1. Translate the following loop into C. Assume that the C-level integer i is hel
ID: 3547953 • Letter: 1
Question
1.
Translate the following loop into C. Assume that the C-level integer i is held in register $t1; $t2 holds the C-level integer called result, and $S0 holds the base address of the integer MemArray.
Addi $t1, $0, $0
LOOP: Lw $S1, 0($S0)
Add $S2, $S2, $S1
Addi $S0, $S0, 4
Addi $t1, St1, 1
Slti $t2, $t1, 100
Bne $t2, $S0, LOOP
2.
Write a code that reads from variable N multiplies by 5, adds 25 and stores the result invariable M. Both variables are 32-bit (M = 5*N + 25).
N is stored in $t1. M is stored in $s1.
Explanation / Answer
1.
{ // Code in C
i = 0 ;
while(i<100)
{
temp += i;
i++;
}
2.
#code in mips
# $t1 has N
# $s1 has the result M
muli $s1, $t1, 5
addi $s1 , $s0 , 25
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.