Unformatted text preview:

CS 61CSummer 2022Caroline, Justin, PeyrinFinalPrint your name:,(last) (first)Print your student ID:You have 110 minutes. There are 8 questions of varying credit (100 points total).Question: 1 2 3 4 5 6 7 8 TotalPoints: 7 16 20 6 15 7 16 13 100For questions with circular bubbles, you may select only one choice.Unselected option (completely unfilled)Only one selected option (completely filled)For questions with square checkboxes, you may select one or more choices.You can selectmultiple squares(completely filled)Anything you write that you cross out will not be graded. Anything you write outside the answer boxeswill not be graded.If an answer requires hex input, make sure you only use capitalized letters! For example,0xDEADBEEFinstead of0xdeadbeef. Please include hex (0x) or binary (0b) prefixes in your answers unless otherwisespecified. For all other bases, do not add any prefixes or suffixes.Read the following honor code and sign your name.I understand that I may not collaborate with anyone else on this exam, or cheat in any way. I am awareof the Berkeley Campus Code of Student Conduct and acknowledge that academic misconduct will bereported to the Center for Student Conduct and may further result in, at minimum, negative points onthe exam.Sign your name:This content is protected and may not be shared, uploaded, or distributed.Page 1 of 19Questions begin on the next page.FinalThis content is protected and may not be shared, uploaded, or distributed.Page 2 of 19 CS 61C – Summer 2022Q1 Potpourri (7 points)Q1.1 (4 points) Select the 2 Boolean expressions from below that are equivalent to each other:(A+!B)(A+!C)!B!C + AA+!(B + C) + (!B+!C)(!B + C)(A + B)(A + C)(!BC)Convert the following 2-byte hex numbers to decimal using signed 2’s complement.Q1.2 (1 point) 0xFF40Q1.3 (1 point) 0x009CQ1.4 (1 point) Consider a 12-bit biased number representation scheme with a bias of −2047.Which of the following is not a representable number in this scheme?02048−2048−1FinalThis content is protected and may not be shared, uploaded, or distributed.Page 3 of 19 CS 61C – Summer 2022Q2 C: Filed Away (16 points)You are bored over summer break so you decide to write up a file system in C!The structfile_itemrepresents a file or a folder. Thedataunion holds either the contents of the file(a string), or an array of pointers to children file_items.In this question, assume that pointers are 4 bytes long.1 typedef struct file_item {2 char *name;3 bool is_folder;4 file_item_data data;5 } file_item;67 typedef union file_item_data {8 char contents[X];9 struct file_item* children[16];10 } file_item_data;1112 // Copies all characters from src to dest including the NULL terminator13 char *strcpy(char *dest, const char *src);We setXto be the largest possible value that doesn’t increase the union size. What is thestrlenof thelongest string we can store in a single file?Fill in the code on the next page to create files and folders. Your code must still work even if the inputstrings are freed later on. Assume that the input strings will fit inside of a file_item_data union.You may use fewer lines than provided, but you may not add more lines.Final (Question 2 continues. . . )This content is protected and may not be shared, uploaded, or distributed.Page 4 of 19 CS 61C – Summer 2022(Question 2 continued. . . )1 /* Creates a file with the given name and contents,2 and returns a pointer to that file. */3 file_item* create_file(char* contents, const char *name) {4567891011121314 }15 /* Creates a folder with the given name and no children,16 and returns a pointer to that folder. */17 file_item* create_folder(const char *name) {1819202122232425262728 }Final (Question 2 continues. . . )This content is protected and may not be shared, uploaded, or distributed.Page 5 of 19 CS 61C – Summer 2022(Question 2 continued. . . )FinalThis content is protected and may not be shared, uploaded, or distributed.Page 6 of 19 CS 61C – Summer 2022Q3 Error-Introducing Code (20 points)In machine learning, some data scientists add random noise to a training dataset in order to improvetheir models. Here, we will take a dataset and transform it into usable data in RISC-V!The function jitter is defined as follows:• Inputs:– a0 holds a pointer to an integer array.– a1 holds a buffer large enough for n integers (which does not overlap with the array in a0).– a2 holds n, the length of the arrays.• Output:– a0holds a pointer to the buffer originally ina1. The buffer is filled with the result of callingnoisen on each element in the a0 array.The function noisen is defined as follows:• Input: a0 holds an integer.• Output: a0 returns the integer with noise added.Eric has provided the correct implementation of jitter below, following calling convention:1 jitter:2 # BEGIN PROLOGUE3 addi sp sp <BLANK 1>4 # (multiple lines omitted)5 # END PROLOGUE6 mv s0 a07 mv s1 a1 # Hold beginning of output arr8 mv s2 a19 mv s3 a2 # Hold counter10 loop:11 beq s3 x0 end12 lw a0 0(s0)13 jal ra noisen14 sw a0 0(s1)15 addi s0 s0 416 addi s1 s1 417 addi s3 s3 -118 j loop19 end:20 mv a0 s221 # BEGIN EPILOGUE22 # (multiple lines omitted)23 addi sp sp <BLANK 2>24 # END EPILOGUE25 retFinal (Question 3 continues. . . )This content is protected and may not be shared, uploaded, or distributed.Page 7 of 19 CS 61C – Summer 2022(Question 3 continued. . . )Q3.1 (1 point) To follow calling convention, what numbers should go in the blanks?<BLANK 1><BLANK 2>Q3.2 (1 point)List all registers that Eric needs to save on the stack in order to follow calling convention.Q3.3 (6 points)Write a sequence of at most two instructions or pseudoinstructions that are equivalentto the j loop instruction.You must use ajalrinstruction orjalrpseudoinstruction in at least one of the blanks. You maynot use a jal instruction, branch instruction, or jal pseudoinstruction in any of the blanks.12Final (Question 3 continues. . . )This content is protected and may not be shared, uploaded, or distributed.Page 8 of 19 CS 61C – Summer 2022(Question 3 continued. . . )Now, Eric wants to implementnoisento add some random offset to an integera0. Unfortunately, Ericonly has access to therandomBoolfunction, which takes in no inputs and randomly returns either 1or 0 in a0.If Eric implementednoisento returna0+randomBool(), the integer would always get shifted in thepositive direction. Instead, Eric suggests implementingnoisenso thatnoisenalternates betweenreturning a0+randomBool() and returning


View Full Document
Download Final
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 Final 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 Final 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?