Question: ( 1 5 points ) Translate the following C code into RISC - V assembly language. If you need to use temporary registers x 5

(15 points) Translate the following C code into RISC-V assembly language. If you need
to use temporary registers x5 through x7 and x28 through x31, or saved registers x8, x9,
x18 through x27, use the lower-numbered registers first.
Completed the assembly language program, submit your program as a
separated .asm file.
Procedure func is a leaf procedure, and procedure f is a non-leaf procedure.
Assume that the arguments a, b, c, and d for function f are in x10-x13, respectively,
and the return value is in x10.
Assume that the arguments a and b for function func are in x10 and x11,
respectively, and the return value is in x10.
The code for functions main, f and func is as follows:
void main (){
int g =-5;
int h =10;
int i =15;
int j =20;
f (g, h, i, j);
}
int f (int a, int b, int c, int d){
int x = func(a, b); // x should be 15
int y = c+d; // y should be 35
x = func(x, y); // return value should be 20
x = a + x; // x should be 15
return x; // return x10=15
}
int func (int a, int b){
if (a > b)
return a - b;
else
return b - a;

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!