Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the MARS IDE for the following questions. Submit your MIPS code as separate

ID: 3748789 • Letter: U

Question

Use the MARS IDE for the following questions. Submit your MIPS code as separate files (one per question). Files should be self-contained and runnable. For #2, submit a screenshot of the console output with your completed assignment. [10] Consider the following MIPS procedure. Note that $a0 and $a1 are input arguments and both initially contain the integers a and b, respectively. Assume that SvO is used for the output. 1. add $t0, Szero, zero beq $a1, $zero, finish add $t0, $t0, a0 addi al, $al, -1 j loop loop: # ? finish: addi $to, $t0, 100 add $v0, $t0, Szero [5] Add comments to describe what each line in assembly is doing, then summarize in one sentence what the whole program accomplishes. a. b. [5] This code can be optimized, i.e. written using fewer instructions. Re-write the code using at most 3 instructions

Explanation / Answer

Please find the comments for the code:::

.text

add $t0,$zero,$zero #moving zero to register t0

loop : beq $a1,$zero,finish #if a1 value is zero jump to finish

add $t0,$t0,$a0 #add a0 to t0

addi $a1,$a1,-1 #reduce one from a1

j loop #continue loop

finish: addi $t0,$t0,100 #add 100 in to

add $v0,$t0,$zero #add 0 to to and save to v0

optimized code for the same:

=========================================================

.text

loop : add $t0,$t0,$a0 #add a0 to t0

sub $a1,$a1,1 #reduce one from a1

bnez $a1,loop #if a1 value is not zero jump to loop

addi $v0,$t0,100 #add 0 to t0 and save to v0 for output only