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

Consider the following MIPS procedure. Note that $a0 and $a1 are input arguments

ID: 3747329 • Letter: C

Question

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 $v0 is used for the output.

a. Add comments to describe what each line in assembly is doing, then summarize in one sentence what the whole program accomplishes.

b. This code can be optimized, i.e. written using fewer instructions. Re-write the code using at most 3 instructions.

add $t0, $zero, $zero beq Sal, zero, finish add $t0, $to, $a0 addi $al, $al, -1 j loop #2 loop: finish: addi $t0, $to, 100 add $vO, $to, $zero

Explanation / Answer

add $to,$zero,$zero #initilizing the $to with the 0

loop: beq $a1,$zero finish # go to finish when $a1 is 0

add $t0,$t0,&a0 # adding $a0 to $t0

addi $a1, $a1,-1 # decreamenting $a1 by 1

j loop

finish : addi $t0,$t0,100 # adding 100 to the $t0

add $v0,$t0,$zero # diplaying the output

The program is finding the product of 2 numbers without using the mul and later adding 100 to the res

Optimized code

mul $t0,$a1,$a0

addi $t0,$t0,100

add $v0,$t0,$zero

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote