# Pause for Breath --- CS 130 // 2021-10-25 ## Administrivia - Assignment 2 returned on Gradescope - Minor updates to schedule - Assignment 3 due tonight + Last 20-minutes of class today will be dedicated to working on the assignment - The rest we will do exam practice problems # Exam 2 - Wednesday, October 27th ## Exam 2 - **Format of the exam**: + Written, in-class, 75-minute exam + Closed textbook/notes/internet + Can bring a 8.5 x 11, single-sided "cheat sheet" - **Topics**: + Basic MIPS, C to MIPS translation, binary, two's complement representation, hexadecimal, R-type and I-type machine code # Questions ## ...about anything? # Exam 2 Practice ## Exercise 1 - Is the following MIPS machine-code instruction an R-type or an I-type instruction? Why? + $00000010101100001000000000100101$ ## Exercise 2 - Convert the following two (unsigned) binary integers into decimal (base 10) + 10101 + 10000 ## Exercise 3 - Convert the following (unsigned) binary integer into hexadecimal (base 16) + 100101 ## Exercise 4 - Using your MIPS sheet + What instruction has opcode 0 and funct $25_\text{hex}$? + What registers correspond to 21 and 16? - Using this, write down the equivalent MIPS instruction the following machine code represents + $000000\\;10101\\;10000\\;10000\\;00000\\;100101$ ## Exercise 5 - Consider the following 16-bit number: + $1111111111001010$ - Convert it to hexadecimal - Convert it to decimal, assuming it is a 16-bit **signed** two's complement representation ## Exercise 6 - Convert the following C code to MIPS ```c int log(int n) { int count = 0; int value = 1; while (value < n) { count++; value = 2 * value; } return count; } ``` ## Exercise 7 - Convert the following C code to MIPS ```c int foo(int x) { return x + 5; } int bar(int y) { return 4 * foo(2 * y); } ``` ## Exercise 8 - Convert the following C code to MIPS where `arr` is an array of 4-byte integers with a memory address stored in `$s0` ```c arr[0] = arr[1] + arr[2]; ``` # Questions ## ...about anything? # Assignment 3 Time