Unformatted text preview:

CS61C F20 Midterm BlankInstructors: Dan Garcia, Borivje NikolicHead TAs: Stephan Kaminsky, Cece McMahonQuestion BreakdownQ1: Float(5 pts) Retake Q1: Float (5 pts) Q2: Quest Clobber (10 pts)Retake Q2: Quest Clobber (10 pts)Q3: RISC-V (10 pts) Retake Q3: RISC-V (10 pts)Q4: SDS (10 pts)Retake Q4: SDS (10 pts)Q5: RISC-V Datapath, Control, and Pipelining (10 pts)Retake Q5: RISC-V Datapath, Control, and Pipelining (10 pts)Appendix: Relevant DiagramsRetake Q2: Quest ClobberBinary Node Structure ReferenceQ4: Truth TableVersion 1 Truth TableVersion 2 Truth TableVersion 3 Truth TableVersion 4 Truth TableVersion 5 Truth TableVersion 6 Truth TableQ4: SDSVersion 1 SDSVersion 2 SDSVersion 3 SDSRetake Q4: SDSVersion 1 + 2 SDS (Same Diagram)Q5: RISC-V Datapath, Pipelining, and ControlsVersion 1 DiagramVersion 2 DiagramVersion 3 DiagramDatapath UpdatedPipelined DatapathCS61C F20 Midterm BlankInstructors: Dan Garcia, Borivje NikolicHead TAs: Stephan Kaminsky, Cece McMahonQuestion BreakdownSection 1: Float (5 pts, 60 minutes)Section 2: Quest Clobber—C (10 pts, 120 minutes)Section 3: RISC-V Assembly (10 pts, 60 minutes)Section 4: SDS (10 pts, 60 minutes)Section 5: RISC-V Datapath, Control, and Pipelining (10 pts, 60 minutes)1Q1: Float(5 pts)Consider aw-bit floating-point number with the following components (1 sign bit,eexponent bits,mmantissa bits);i.e. all other properties of IEEE754 apply (bias, denormalized numbers, infinities, NaNs, etc. . . ). The bias is the usual−(2e−1− 1).Part A — 3 ptsWhat is the bit representation (in hex) of the floating-point numbern?Do NOT include the 0x prefix whenwriting your answer.Your Answer: herePart B — 2 ptsHow many floats are there in the range[ low val, high val)? You can either simplify your answer or leave it inexponent form. If you leave it in exponent form, you must use**for exponentiation. For example, if your answer is8, (i.e. 2**3), you can put either answer down.Your Answer: here2Retake Q1: Float (5 pts)Same as original question, different parameters3Q2: Quest Clobber (10 pts)Skeleton CodeType Conversionsquest.c repeated per versionTREE *incr_tree(TREE *p) {return p; // <-- replace this with your code}void free_tree(TREE *p) {return; // <-- replace this with your code}bias2ones#include "quest.h"uint8_t bias2ones(uint8_t bias) {return bias + 1; // <-- replace this with your converter}bias2sm#include "quest.h"uint8_t bias2sm(uint8_t bias) {return bias + 1; // <-- replace this with your converter}ones2bias#include "quest.h"uint8_t ones2bias(uint8_t ones) {return ones + 1; // <-- replace this with your converter}sm2bias#include "quest.h"uint8_t sm2bias(uint8_t sm) {return sm + 1; // <-- replace this with your converter}Helper Filesquest.h#include <inttypes.h>#include <stdlib.h>#include <stdio.h>typedef struct node {struct node *L;struct node *R;uint8_t N;} TREE;void *CS61C_malloc(size_t size);void CS61C_free(void *ptr);4uint8_t <VERSION FUNCTION>(uint8_t <VERSION INPUT>);TREE *map_tree(TREE *p);void free_tree(TREE *p);void print_tree(TREE *p);print_tree.c#include "quest.h"void print_tree(TREE *p) {if (p) {printf("(");print_tree(p->L);printf(" %02X ", p->N);print_tree(p->R);printf(")");} else {printf(".");}}main.c#include "quest.h"void *CS61C_malloc(size_t size) {void *ptr = malloc(size);printf("malloc: %p\n",ptr);return ptr;}void CS61C_free(void *ptr) {printf("free : %p\n",ptr);free(ptr);}int main(int argc, char *argv[]) {TREE a,b,c,d,e,*p;b.N = 0x0; // <-- PUT VALUES HERE to test your convertera.N = 0x1; // a <-- this is the tester tree we providec.N = 0x2; // b c <-- print_tree prints it like thise.N = 0x3; // d <-- ((. b .) a (. c ((. e .) d .)))d.N = 0x4; // e <-- in which each # is 2-digit Hex// Set up the tester tree for you, don 't worry about thisa.L = &b; a.R = &c; c.R = &d; d.L = &e;b.L = b.R = c.L = d.R = e.L = e.R = NULL;// Print the tree before map_tree, call map_tree and free itprint_tree(&a); printf("\n");print_tree(p = map_tree(&a)); printf("\n");free_tree(p);return 0;}5Part A — 3 ptsHelp! We have two robots, Alexa and Siri, but they’re speaking the wrong languages! Alexasends sensor data with the bits asuint8_ts encodingENCODING TYPE 1which would later be read by Siri. However,Siri can only understandENCODING TYPE 2. Your job is to write a simple functionENCODING TYPE 1 TO 2so thatSiri can correctly convert messages received from Alexa. (E.g. if Alexa saw “-3” and encoded it asENCODING TYPE1, you’d need to return a new set of bits such that Siri would interpret those bits inENCODING TYPE 2as “-3” aswell.) Note that the range of the sensor is such that it would never produce a number that Siri couldn’t handle. Ifyou’re ever given the choice between storing +0 or -0, store +0. If you are not able to complete this part, you canstill receive full credit on Parts B and C.uint8_t <VERSION FUNCTION>(uint8_t <VERSION INPUT>) {//YOUR ANSWER}Part B — 4 ptsAfter much deliberation, the robots have agreed to use unsigned numbers instead. They havestored some data in a binary node structure, but have realized that all their data is one less than the correctvalue. Complete the code forTREE *incr_tree(TREE *p)that returns a duplicate tree in which every number hasbeen incremented by 1. You must useCS61C_malloc()instead ofmalloc(). You can assume that every call toCS61C_malloc() succeeds.typedef struct node {struct node *L;struct node *R;uint8_t N;} TREE;TREE *incr_tree(TREE *p) {//YOUR ANSWER}Part C — 3 ptsClean up behind yourself! Write a functionvoid free_tree(TREE *p)which will free all of thespace used by the input treep. You may assume that all of the nodes inpweremalloc'dproperly. You must useCS61C_free()instead offree(). You may editmain.cto test your code. Your code should be able to run withoutmodifications inquest.h, or the signatures of the three functions. You will only be submittingquest.cand only thecode in that file will be graded.void free_tree(TREE *p) {//YOUR ANSWER}6Retake Q2: Quest Clobber (10 pts)Skeleton CodeType Conversionsquest.c repeated per version#include "quest.h"int count = 1; // a global variable for the node numberTREE *num_tree(int n) {TREE *t;return t; // <-- replace this with your code}void free_tree(TREE *p) {return; // <-- replace this with your code}ones2smuint8_t ones2sm(uint8_t ones) {return ones + 1; // <-- replace this with your converter}sm2onesuint8_t sm2ones(uint8_t sm) {return sm + 1; // <-- replace this with your converter}Helper Filesquest.h#include <inttypes.h>#include


View Full Document
Download Midterm Blank
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Midterm Blank and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Midterm Blank 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?