Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions