A nested function calls another function (plot_function with parameter a0) and is also called by another function. Given the code that follows RISCV calling convention, which sets of registers should be saved to make this program run more optimally. All the function knows is that the plot_function uses a0 as a parameter, and its own caller passes a value in a0. mv s1, s2 is the pseudo instruction equivalent of: addi s1, s2, 0
add_memory_values:
# save reg_set1 on stack here
mv s1, a0 # parameter used by this function, holds an address
li s2, 1000 # down counter
li s3, 0 # accumulator
loop1:
lwu t1, 0(s1) # load from memory
addw s1, 4 # go to to next word
add s3, t1 # add memory value to accumulator
mv a0, s3 # pass a parameter to plot_numbers
# save reg_set2 here
jal plot_numbers
# restore reg_set2 here
addi s2, -1 # decrement counter
bgtz s2, loop1
mv a0, s3
# restore reg_set1 here
ret
What combinations should apply (mark as all that are true):
t1 needs to be saved.
ra does not need saving
only ra needs to be saved
all s# registers should be saved
reg_set2 is: should include t1
reg_set1 is empty
a0 doesn't need to be saved on the stack
only t1 and ra need to be saved
all t# should be saved
reg_set1 should include ra, s1, s2, s3
reg_set2 is empty
Hanas J.
I believe this is wrong05/31/23