LOOP: slt $t2, $0, $t1 beq $t2, $0, DONE subi $t1, $t1, 1 addi $s2, $s2, 2 j LOO
ID: 3821175 • Letter: L
Question
LOOP: slt $t2, $0, $t1 beq $t2, $0, DONE subi $t1, $t1, 1 addi $s2, $s2, 2 j LOOP DONE: Assume that the register $t1 is initialized to the value 10. What is the value in register $s2 assuming $s2 is initially to zero? For each of the loops above, write the equivalent C code routine. Assume that the registers $s2, $t1, and $t2 are integers A, i, and tempo respectively. For the loops in written MIPS assembly above, assume that the register $t1 is initialized to the value N. How many MIPs instructions are executed? (MIPS instructions used here the value of $0 is 0; slt, $t2, $0, $t1: if the content of the register $t1 then the register $t2 will be assigned to land else it will be assigned to 0, beq $t2, $0, DONE: if the value of register $t2 is go the of $0, then the program will go to DONE else will to the following statement.)Explanation / Answer
The instructions are given below:
1 LOOP: slt $t2, $0, $t1
2 beq $t2, $0, DONE
3 subi $t1, $t1, 1
4 addi $s2, $s2, 2
5 j LOOP
6 DONE:
Let us have a look at the instructions and their meaning
slt - set on less than unsigned
sltu $s1, $s2, $s3 would be interpreted as below:
if ($s2 < $s3) $s1 = 1; else $s1 = 0
beq - branch on equal
beq $s1, $s2, 25 would be interpreted as:
if ($s1 == $s2) go to PC + 4 + 100
subi - Substract immediate
subi $t2, $t3, 5
$t2 = $t3 – 5
addi - Add immediate
addi $2, $3, 5
$2 = $3 + 5
Answers:
1) 0x14 = 20
2) $s2 would be A
$t1 would be i
$t2 would be temp
while(i > 0)
{
i = i - 1;
A = A + 2;
}
3) Suppose the value of $t1 is N
As long as the $t1 is greater than zero the whole instructions would be executed. The total instructions are 5.
For the last iteration, only two instructions would be executed. They are instruction number 1 and 2.
So total number of instructions that executed would be:
N x 5 + 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.