Sheet 3
Sheet 3
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)