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

Consider the following MIPS loop: slt $t2, $0, $t1 beq $t2, $0, Done subi $t1,$t

ID: 3664837 • Letter: C

Question

Consider the following MIPS loop: slt $t2, $0, $t1 beq $t2, $0, Done subi $t1,$t1,1 addi $s2,$s2, 6 j loop Done: Assume that the register is initialized to the value 6. What is the value in register $s2 assuming $s2 is initially zero? For each of the loops above, write the equivalent C code routine. Assume that the register and St2 are integers a, b, i, and temp, respectively. For the loops written in MIPS assembly above, assume that the register is initialized to the value 16. How many MIPS instructions are executed?

Explanation / Answer

a) by considerigng the following MIPS code with the following initial values: $t1 =6 and $s2 = 0.so $s2 will be:

$s2 = $s2 + 6 //$s2 = 6

$t1 = $t1 – 1   //$t1 = 5

$t1 != 0, goto loop

$s2 = $s2 + 6 //$s2 = 12

$t1 = $t1 – 1   //$t1 = 4

$t1 != 0, goto loop

.

.

.

$s2 = $s2 + 6 //$s2 = 36

$t1 = $t1 – 1   //$t1 = 0 loop stops

Hence ,$s2 = 36

b) Given two ways, first one using "while" and second for "For loop":

c) The loop is executed 5*N+2 times,

Loop repeats till $t1 = 0, so it will repeat 16 times. Hence,
                     => 5*16+6=86

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