Question: Given the following C program and the mapping of registers to variables, complete the MIPSzy implementation of function Sum. int Dif ( int a ,

Given the following C program and the mapping of registers to variables, complete the MIPSzy implementation of function Sum.
int Dif(int a, int b){
return b-a;
}
int Sum(int m, int n){
int p=Dif(n+1,m-1);
int q=Dif(m+1,n-1);
return p+q;
}
int main()(
int x,y;
z=x+y+sum (x,y);
return 0 ;
}
addi $sp, $zero, 8188 # Assume program stack starts at 8188. Do not modify.
# Procedure Main (Do not modify)
Main:
# Store arguments for Sum
addi $sp, $sp,-4 # Push $t0 to stack
sw $t0,0($sp)
addi $sp, $sp,-4 # Push $t1 to stack
sw $t1,0($sp)
addi $sp, $sp,-4 # Push return value to stack
jal Sum
# Load return value
lw $t2,0($sp)
addi $sp, $sp,4 # Pop return value from stack
lw $t1,0($sp)
addi $sp, $sp,4 # Pop $t1 from stack
lw $t0,0($sp)
addi $sp, $sp,4 # Pop $t0 from stack
# Final additions
add $t2, $t2, $t0
add $t2, $t2, $t1
j End
# Procedure Sum
Sum:
# Type your code here.
# Procedure Dif (Do not modify)
Dif:
# Load arguments
lw $t0,12($sp)
lw $t1,8($sp)
sub $t4, $t1, $t0
sw $t4,4($sp) # Push return value
jr $ra
End:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!