#Answer the five questions below 1 foo: addi $sp, $sp, -8 2 sw $ra, 0($sp) 3 sw $s0, 4($sp) 4 addu $s0, $a0 $zero 5 beq $a1, $zero, skip 6 jal bar 7 skip: addu $v0, $zero, $zero 8 loop: lbu $t0, 0($s0) #Note the bug fix, was "loop: lbu $t0, 0$($s0)" 9 beq $t0, $zero, done 10 addi $v0, $v0, 1 11 addi $s0, $s0, 1 12 j loop 13 done: nop #Added these two nop's. nop instructions have no effect. 14 nop 15 lw $s0, 4($sp) 16 lw $ra, 0($sp) 17 addi $sp, $sp, 8 18 jr $ra 19 bar: lw $t0, 8($ra) 20 lw $t1, 16($ra) 21 sw $t0, 16($ra) 22 sw $t1, 8($ra) 23 jr $ra NOTE: The instructions on lines 13 and 14 (nop) are no-operation instructions. from wikipedia: "NOP is an instruction that does nothing at all besides wasting clock cycles" =) Part A: Observe how $a0 is used. Based on this, what is the C-equivalent type of $a0 that is passed into the function foo(TYPE $a0, int $a1)? Explain. (For example: int, int*, char, char*, etc) ANSWER: //FILL IN HERE Part B: Let $a1 be a zero value passed into the function foo. How do lines 8-12 (inclusively) translate into C (Based on the program's behavior)? What does the return value represent? C-Code: //FILL IN HERE return-Value: //FILL IN HERE Part C: Let $a1 be non-zero at the beginning of function foo. What does the function bar do? How do lines 8-12 (inclusively) translate into C (Based on the program's behavior)? What does the return value represent? Bar?: //FILL IN HERE C-Code: //FILL IN HERE return-Value: //FILL IN HERE Part D: On lines 20 and 21 you accidentally used an Offset of 20 instead of 16. What is the behavior of the resulting code? ANSWER: //FILL IN HERE Part E: This question is for you to have practice with SPIM. This should also better your understanding of what the code is doing. Open SPIM with smc.s file. Start stepping through the code until you enter the main function (Pay attention to what instruction you are on as you step through the code). Once you enter main, set register $a1 to have value 1. Use the print function to find out what address the label "skip" is at. Set the register $a0 to the value of that address. Note that you can use hex when setting registers to some value. using SPIM, answer the following questions: 1) How many iterations did the code run inside the loop? ANSWER: //FILL IN HERE 2) Once you break out of the loop, what is the next instruction you execute? Explain the behavior (hint: what does "done" translate to when loaded into spim in the "beq" instruction. You can also run the code with $a1 reset to value 0 and see where beq jumps to help answer this question) ANSWER: //FILL IN HERE 3) Let us now investigate the subtle bug I had with my ORIGINAL code. Remove the two NOP instructions. You should now have "done: lw $s0, 4($sp)" on one line after after "j loop". a) What is the behavior of the code? (Hint: use SPIM to investigate the problem) ANSWER: //FILL IN HERE b) What if we used more than one $s* registers in the code, i.e $s1, $s2, etc (saving the registers in the prologue, recovering the original values in the epilogue). Would this program ever terminate? If so, how and why? ANSWER: //FILL IN HERE