Question: A callable nested function add _ memory _ values as shown below calls another function ( plot _ function with parameter a 0 ) and
A callable nested function addmemoryvalues as shown below calls another function plotfunction with parameter a and being a nested function, it also gets called from somewhere. We assume that the code that follows uses the RISCV calling conventions. We also assume that the function knows essentially nothing about its caller, nor about the function that it calls, ie plotnumbers that is other than knowing what parameters are passed returned. Assume that mv s s is the pseudo instruction equivalent of: addi s s in other words, it copies register s to s
addmemoryvalues: # adds and plots numbers in array of integers
# SAVE REGSET ON STACK CODE GOES HERE
mv s a # param with address of array of integers
mv s a # parameter with number of integers to be added
# s will be used as a down counter
li t # initializes an accumulator
loop:
lwu ts # load from integer array
add s # go to to next word for each time around loop
add t t # add memory value to accumulator
mv a t # parameter for plotnumbers
# SAVE REGSET ON STACK CODE GOES HERE.
jal plotnumbers # Call plotnumbers
# RESTORE REGSET CODE GOES HERE
addi s # decrement counter
bgtz s loop # Loop until all numbers added
mv a t # Return accumulated value in a
# RESTORE REGSET CODE GOES HERE
ret
Given this, mark ALL of the statements that are true.
Group of answer choices
a and a should be saved because addmemoryvalues is a CALLER
REGSET should include ALL s# register found in RISCV because this function is a CALLEE
REGSET should include ra s s
Some t# registers will need to be saved for the program to be guaranteed to work.
ALL RISCV s# registers should be saved given that the function is also a CALLEE
t needs to be saved
plotnumbers, being a leaf function should make use of as many s# registers as possible.
Any t# registers that need to be saved and restored are part of REGSET
t needs to be saved
A leaf function is considered a CALLEE
t and t must be both saved because they are being modified by the function.
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
