Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

image text in transcribed

ALL RISCV s\# registers should be saved given that the function is also a CALLEE Any t# registers that need to be saved and restored are part of REG_SET2 REG_SET1 should include ra, s1, s2 Some t\# registers will need to be saved for the program to be guaranteed to work. plot_numbers, being a leaf function should make use of as many s\# registers as possible. t1 and t2 must be both saved because they are being modified by the function. a0 and a1 should be saved because add_memory_values is a CALLER A leaf function is considered a CALLEE t1 needs to be saved REG_SET1 should include ALL s \# register found in RISCV because this function is a CALLEE t2 needs to be saved ALL RISCV s\# registers should be saved given that the function is also a CALLEE Any t# registers that need to be saved and restored are part of REG_SET2 REG_SET1 should include ra, s1, s2 Some t\# registers will need to be saved for the program to be guaranteed to work. plot_numbers, being a leaf function should make use of as many s\# registers as possible. t1 and t2 must be both saved because they are being modified by the function. a0 and a1 should be saved because add_memory_values is a CALLER A leaf function is considered a CALLEE t1 needs to be saved REG_SET1 should include ALL s \# register found in RISCV because this function is a CALLEE t2 needs to be saved

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago