Calling Convention 2
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
RISC-V Calling Convention 2
Consider the following C function, f:int f(int x, int y) {
int w = y;
int z = mul(x, 2) + y + w;
return z;
}
Suppose that you wanted to implement the function, f, in RISC-V assembly.
f? Select all correct answers.
Consider the following incorrect RISC-V implementation of the function f.
Assume that its calling function believes that f is properly
implemented and follows the RISC-V calling conventions. Also assume
that the function mul, being called by f, is implemented correctly
and follows the RISC-V calling convention. The function mul takes two
unsigned integer arguments and returns the result of multiplying those
inputs.
f:
// (1)
mv a2, a1
mv s0, a1
li a1, 2
// (2)
call mul
// (3)
add a0, a0, a2
add a0, a0, s0
// (4)
ret
// (5)
f is called with arguments (4 and 6), what will be the value in a0, a1, and a2 when execution reaches label (2) in the code?
mul follows the calling convention, which of the following register(s) are guaranteed to hold the same value at both points (2) and (3) in the code execution? Select all correct answers.
mul follows the calling convention, but f does not, which register(s) are not handled properly by the code above? Select all correct answers
f are 6 and 7 respectively, which of the following statement(s) are true? Select all correct answers.
Using the Stack
We now want to modify the implementation of function f so that it follows the calling convention and works correctly. To do this we will make use of the stack and additional instructions that save and restore values from the stack.The first instruction we need to add is an instruction that will allocate enough space on the stack to hold all the registers that we need to save.
f?
(1) or (2) in the code of function f? Select all missing instructions that would work correctly regardless of being placed at point (1) or point (2).
(1) in the code of function f? Select all correct answers.
(2) in the code of function f? Select all correct answers.
(3) or (4) in the code of function f? Select all missing instructions that would work correctly regardless of being placed at point (3) or point (4).
(3) in the code of function f? Select all correct answers.
(4) in the code of function f? Select all correct answers.
sp, to its original value be placed assuming that all registers that must be restored are restored prior to this instruction? Select all correct answers.