Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

A callable nested function add _ memory _ values as shown below calls another function ( plot _ function with parameter a 0 ) and

A callable nested function add_memory_values as shown below calls another function (plot_function with parameter a0) and being a nested function, it also gets called from somewhere. We assume that the code that follows uses the RISC-V calling conventions. We also assume that the function knows essentially nothing about its caller, nor about the function that it calls, i.e. plot_numbers (that is other than knowing what parameters are passed returned. Assume that mv s1, s2 is the pseudo instruction equivalent of: addi s1, s2,0, in other words, it copies register s2 to s1.
add_memory_values: # adds and plots numbers in array of integers
# SAVE REG_SET1 ON STACK CODE GOES HERE
mv s1, a0 # param with address of array of integers
mv s2, a1 # parameter with number of integers to be added
# s2 will be used as a down counter
li t2,0 # initializes an accumulator
loop1:
lwu t1,0(s1) # load from integer array
add s1,4 # go to to next word for each time around loop
add t2, t1 # add memory value to accumulator
mv a0, t2 # parameter for plot_numbers
# SAVE REG_SET2 ON STACK CODE GOES HERE.
jal plot_numbers # Call plot_numbers
# RESTORE REG_SET2 CODE GOES HERE
addi s2,-1 # decrement counter
bgtz s2, loop1 # Loop until all numbers added
mv a0, t2 # Return accumulated value in a0
# RESTORE REG_SET1 CODE GOES HERE
ret
Given this, mark ALL of the statements that are true.
Group of answer choices
a0 and a1 should be saved because add_memory_values is a CALLER
REG_SET1 should include ALL s# register found in RISCV because this function is a CALLEE
REG_SET1 should include ra, s1, s2
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
t1 needs to be saved
plot_numbers, 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 REG_SET2
t2 needs to be saved
A leaf function is considered a CALLEE
t1 and t2 must be both saved because they are being modified by the function.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions