Question: . Translate function f ( ) in the following C code to RISC - V assembly code. Assume function g has already been implemented. The

. Translate function f() in the following C code to RISC-V assembly code. Assume function g
has already been implemented. The constraints are:
1) Allocate register s1 to sum, and register s2 to i.
2) Save registers at the beginning of the function and restore them before the exit.
3) There are no load or store instructions in the loop. If we want to preserve values
across function calls, place the value in a saved register before the loop. For example,
we keep variable i in register s2.
Your code should follow the flow of the C code. Write concise comments. Clearly mark
instructions for saving registers, loop control, function, restoring register, and so on.
Reminder: the callee can change any temporary and argument registers.
// prototype of g
// the first argument of g is an address of an integer
int g(int * a, int i);
int f(int d[1024])
{
int sum =0;
for (int i =0; i <1024; i +=1){
sum += g(&d[i], i); // pass d[i]s address to g
}
return sum;
}

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!