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

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

ID: 3881110 • Letter: C

Question

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

Explanation / Answer

a)
slt $t2,$0,$t1

$t2 will be set to 1 if $0 < $t1 => 0 < 5 (true)
$t2 = 1
So, accordingly, loop runs for 5 times as loop will be closed after $t2 will be equal to 0 and it will be only when $t1 will be equal to 0.

So,in each loop ;
$t1 = $t1 - 1
$s2 = $s2 + 4

So,as it is given $s2 = 0 intially .It increases it's value by 4 on each loop.And,loop continues for 5 times.So ,accordingly, $s2 = 4*5 = 20

b)
C equivalent program :-

while(1){
temp=0;
if(i>0){
temp=1;
}
if(temp==0){
break;
}
i--;
b=b+4;
}

c)
if $t1 = 15 ; then loop runs for 15 times

for each loop;
5 instructions are executed.
So,for 15 loops; 5 * 15 instructions = 75 instructions

So,for the last condition check;only 2 instructions will be executed i.e slt $t2,$0,$t1 and beq $t2,$0,Done.

Therefor,on total MIPS instructions which are executed are 77 instructions

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