Question: 7 . 1 0 LAB: Nested procedures Given the following C program and the mapping of registers to variables, complete the RISC - V implementation
LAB: Nested procedures
Given the following C program and the mapping of registers to variables, complete the RISCV implementation of procedure Sum.
int Difint a int b
return b a;
int Sumint m int n
int p Difn m;
int q Difm n;
return p q;
int main
int mp@subsuptextrmxtextrmymathrm ;
z x y Sumx y;
return ;
Hints: Use stack memory as needed. Use x x as arguments and x as return value, according to the convention for procedure calling.
Ex: If the values of x and x are initialized in the simulator as:
the result is stored in xx :
Note: Use the button under the Registers display to initialize register values for x and x
Given code:
lui x
addi x x Assume Stack memory starts at Do not modify.
Procedure Main Do not modify
Main:
add x x x
add x x x
jal x Sum
add x x x
add x x x
beq x x End
Procedure Sum
Sum:
Type your code here.
Procedure Dif Do not modify
Dif:
sub x x x
jalr xx
End:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
