Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Goal 4 (1, 5, 6)
Solution
Quiz 2
Goal 4 (2, 3, 4)
Q.1 Assume variable h is associated with register $s2 and the base address of the array A is in
$s3. What is the MIPS assembly code for the C assignment statement below?
A[12] = h + A[8]; 5
Q.2 In the following code segment, f, g, h, i, and j are variables. If the five variables f through j
correspond to the five registers $s0 through $s4, what is the compiled MIPS code for this C
statement?
if (i == j) f = g + h; else f = g – h; 5
Q.1 Assume variable h is associated with register $s2 and the base address of the array A is in
$s3. What is the MIPS assembly code for the C assignment statement below?
A[12] = h + A[8];
Solution
The final instruction stores the sum into A[12], using 48 as the offset and register $s3 as the base register.
Q.2 In the following code segment, f, g, h, i, and j are variables. If the five variables f through j
correspond to the five registers $s0 through $s4, what is the compiled MIPS code for this C
statement?
if (i == j) f = g + h; else f = g – h;
Solution
The end of the loop branches back to the while test at the top of the loop. We just add the Exit label
after it, and we’re done:
j Loop # go to Loop
Exit: