Consider the following MIPS loop: *(show work) LOOP: slt $t2, $0, $t1 beq $t2, $
ID: 3562524 • Letter: C
Question
Consider the following MIPS loop: *(show work)
LOOP: slt $t2, $0, $t1
beq $t2, $0, DONE
subi $t1, $t1, 1
addi $s2, $s2, 2
j LOOP
DONE:
a) Assume that the register $t1 is initialized to the value 10. 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 registers $s1, $s2, $t1, and $t2 are integers A,B, I, and temp, respectively.
c) For the loops written in MIP assembly above, assume that the register $t1 is initialized to the value N. How many MIPS instructions are executed?
Explanation / Answer
The loop will run for condition ($0 < $t1)
It is similar to c code:
$t1 = 10; $s2 = 0;
while($0 < $t1) {
$t1 = $t1 - 1;
$s2 = $s2 + 2;
}
Therefore
(a) $s2 = 20
// loop will run 10 times
(b)
I = 10; B = 0;
while((temp = (0 < I)) != 0) {
I = I - 1;
B = B + 2;
}
// loop will run 10 times
(c)
As seen above from c code
For $t1 = N
No of executions of loop = N
For each loop execution --> 5 MIPS instruction
Therefore total MIPS instruction = 5N
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.