Question: 1. Translate function foo() in the following C code to RISC-V assembly code. Assume function bar() has already been implemented. The constraints/tips are: 1)
1. Translate function foo() in the following C code to RISC-V assembly code. Assume function bar() has already been implemented. The constraints/tips are: 1) Allocate register s1 to sum, and register s2 to i. 2) 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. 3) Identify the registers that are changed in function foo() but should be preserved. Note that the callee, bar(), may change any temporary and argument registers. 4) Save registers at the beginning of the function and restore them before the exit. Your code should follow the flow of the C code. Write concise comments. Clearly mark instructions for saving registers, loop, function calls, restoring register, etc. // prototype of bar // the first argument is an address of an integer int bar(int a[], int i); int foo(int d[], int n) { } int sum = 0; for (int i = } return sum; 0; i
Step by Step Solution
There are 3 Steps involved in it
The C function foo provided in the image should be translated into RISCV assembly language considering the constraints and tips mentioned The provided ... View full answer
Get step-by-step solutions from verified subject matter experts
