CSE112 Computer Architecture
Sheet 3
Exercise 1:
What is the corresponding MIPS assembly code for each of the following C statements?
How many MIPS instructions are needed in each case?
Assume that the variables f, g, h, i and j are available 32-bit integers.
a. 𝑓 = 𝑓 + 𝑔 + ℎ + 𝑖 + 𝑗 + 2;
b. 𝑓 = 𝑔 − (𝑓 + 5);
Exercise 2:
What is the corresponding MIPS assembly code for each of the following C statements?
How many MIPS instructions and how many registers are needed in each case?
Assume that the variables f, g and h are assigned to registers $s0, $s1, and $s2 respectively and the
base address of arrays A and B are in registers $s6 and $s7.
a. 𝑓 = −𝑔 + ℎ + 𝐵[1];
b. 𝑓 = 𝐴[𝐵[𝑔] + 1];
Exercise 3:
The following problems deal with translating from MIPS to C.
Assume that the variables f, g, h and i are assigned to registers $s0, $s1, $s2 and $s3 respectively and
the base address of array A is in register $s6.
a. add $s0,$s0,$s1 b. addi $s6,$s6,-20
add $s0,$s3,$s2 add $s6,$s6,$s1
add $s0,$s0,$s3 lw $s0,8($s6)
Answer the following:
1- For the MIPS assembly instructions above, what is the corresponding C statement?
2- For the MIPS assembly above, assume that the registers $s0, $s1, $s2, $s3, contain the values
10, 20, 30, and 40, respectively. Also, assume that register $s6 contains the value 256, and that
memory contains the values as mentioned in the below table.
Find the value of $s0 at the end of the assembly code.
Address Value
256 100
260 200
264 300