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

4. Add comments to the following MIPS code anddescribe in a sentence or two what

ID: 3609806 • Letter: 4

Question

4. Add comments to the following MIPS code anddescribe in a sentence or two whatit

computes. Assume that$a0 is used for the input and initiallycontains n, a positiveinteger.

Assume that $v0 isused for returning the output value.

begin: addi $t0, $zero, 0 #

addi $t1, $zero, 1 #

loop: slt $t2, $a0, $t1 #

bne $t2, $zero, finish #

add $t0, $t0, $t1 #

addi $t1, $t1, 2 #

j loop #

finish add $v0, $t0, $zero #

begin: addi $t0, $zero, 0#                  t0=0

addi $t1, $zero, 1#                  t1=1

loop:      slt $t2, $a0, $t1#                 if(a0<t1)t2=1   elset2=0

bne $t2, $zero, finish#           if(t2=1) go to finish

add $t0, $t0, $t1#              t0++           t0 counts how many times through the loop andthis is what is output

addi $t1, $t1, 2#                t1+=2        

j loop#                               go to loop

finish add $v0, $t0, $zero#     v0=t0

Explanation / Answer

please rate - thanks the answer is right there- last sentence    if n is input this finds    (int)(n+1)/2    which isoutput the input is n that's whats in a0 if n is even v0 will have    n/2 at theend if n is odd v0 will have (n+1)/2 so that is   (int)(n+1)/2      is output example    in a0    in v0 at completion 1            1 2            1 3            2 4            2 5            3 6            3

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