[10] Consider the following MIPS procedure. Note that $a0 and al are input argum
ID: 3747489 • Letter: #
Question
[10] Consider the following MIPS procedure. Note that $a0 and al are input arguments and both initially contain the integers a and b, respectively. Assume that SvO is used for the output. add $t0, zero, zero beq al, zero, finish add $t0, t0, a0 addi al, al, -1 j loop addi to, t0, 100 add $v0, $t0, zero loop: Tinish: [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
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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.