4. Translate the following MIPS into C. (1) Assume that the variables a, b, i, a
ID: 3585301 • Letter: 4
Question
4. Translate the following MIPS into C.
(1) Assume that the variables a, b, i, and j are stored in registers $s0, $s1, $t0, and $t1 respectively. Assume that registers $s2 and $s3 hold the base registers for arrays A and B.
addi $t1, $zer0, 1000
loop: slt $t0, $s1, $t1
bne $t0, $zer0, EXIT
sll $t2, $t1, 2
add $t2, $t2, $s2
lw $t2, 0($t2)
add $s1, $s1, $t2
addi $t1, $t1, -1
j loop
EXIT:
(2)
A: addi $sp, $sp, -4
sw $s0, 0($sp)
add $s0, $a0, $a1
mul $s0, $s0, $s0
addi $s0, $s0, 1234
add $v0, $s0, $zer0
lw $s0, 0($sp)
addi $sp, $sp, 4
jr $ra
Explanation / Answer
1)
int x=0; //$t2=x
int * addr_A = array_A; //pointer addr_A have the base address of array A
j=1000;
while(1){
if(b < j){
i=1;
}
if(i != 0){
break
}
x= j << 2;
addr_A = addr_A + x;
b=b + *(addr_A);
j--;
}
2)
NOTE:- As variable notation not given;I am writing in here
$a0,$a1 = a,b (which are function arguement)
int A(int a,int b){
int x=a+b;
x= x * x;
x= x + 1234
return x;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.