1. Consider the following assembly code for parts 1 and 2.
r1 = 99 Loop:
r1 = r1 - 1
if r1 > 0, goto Loop
halt
(a) During the execution of the above code, how many instructions are executed?
(b) Assuming a standard unicycle machine (CPI = 1) running at 100 KHz, how long will the above code take to complete?
3. Add comments to the following MIPS code and describe in one sentence what it computes. Assume that $a0 and $a1 are used for the input and both initially contain the integers a and b, respectively. Assume that $v0 is used for the output.
Can you re-write the code with less number of instructions? If yes, write the new code.
add $t0, $zero, $zero
loop: finish:
|
beq $a1, $zero, finish add $t0, $t0, $a0 addi $a1, $a1, -1 j loop addi $t0, $t0, 100 add $v0, $t0, $zero
|