Question: 7 . 1 0 LAB: Nested procedures Given the following C program and the mapping of registers to variables, complete the RISC - V implementation

7.10 LAB: Nested procedures
Given the following C program and the mapping of registers to variables, complete the RISC-V implementation of procedure 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 }\mp@subsup{\textrm{x}}{,}{}\textrm{y}\mathrm{ ;
z = x + y + Sum(x, y);
return 0;
}
Hints: Use stack memory as needed. Use x 10, x11 as arguments and x 12 as return value, according to the convention for procedure calling.
Ex: If the values of x8 and x9 are initialized in the simulator as:
the result is stored in xx18 :
Note: Use the '+' button under the Registers display to initialize register values for x8 and x9.
Given code:
lui x2,1
addi x2, x2,1904// Assume Stack memory starts at 6000. Do not modify.
// Procedure Main (Do not modify)
Main:
add x10, x0, x8
add x11, x0, x9
jal x1, Sum
add x18, x9, x8
add x18, x18, x12
beq x0, x0, End
// Procedure Sum
Sum:
// Type your code here.
// Procedure Dif (Do not modify)
Dif:
sub x12, x11, x10
jalr x0,0(x1)
End:
7 . 1 0 LAB: Nested procedures Given the

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 Programming Questions!