Knowee
Questions
Features
Study Tools

n what situations must the return address $ra be backed up and restored by a subroutine?Question 9Select one:a.All situations.b.Only if the subroutine DOES NOT call any further subroutines.c.Only if the subroutine DOES call further subroutines.d.Only if the subroutine has a return value.

Question

n what situations must the return address $ra be backed up and restored by a subroutine?Question 9Select one:a.All situations.b.Only if the subroutine DOES NOT call any further subroutines.c.Only if the subroutine DOES call further subroutines.d.Only if the subroutine has a return value.

🧐 Not the exact question you are looking for?Go ask a question

Solution

The return address $ra must be backed up and restored by a subroutine in the situation where the subroutine does call further subroutines. So, the correct answer is c. Only if the subroutine does call further subroutines.

Here's why:

In MIPS assembly language, ra(returnaddress)isaspecialregisterthatisusedtostorethereturnaddressofasubroutine(orfunction).Whenasubroutineiscalled,theaddressofthenextinstruction(theinstructionafterthecall)isstoredinra (return address) is a special register that is used to store the return address of a subroutine (or function). When a subroutine is called, the address of the next instruction (the instruction after the call) is stored in ra, so that when the subroutine finishes, the program knows where to continue execution.

If a subroutine does not call any further subroutines, it can simply return to the address stored in rawithoutworryingaboutlosingthisinformation.However,ifthesubroutinedoescallanothersubroutine,thiswilloverwritethevalueinra without worrying about losing this information. However, if the subroutine does call another subroutine, this will overwrite the value in ra with a new return address. Therefore, before making this second subroutine call, the first subroutine needs to save the current value of $ra somewhere (for example, on the stack), so that it can restore this value before it returns. This ensures that the program will correctly return to the instruction after the original call to the first subroutine.

This problem has been solved

Similar Questions

Which of the following statements is false?Question 2Select one:a.The register $ra does not need to be backed up and restored if the subroutine does not call any other subroutine.b.A subroutine does not need to back up and restore the register $1 in any circumstances.c.The CPU will modify the value stored in $ra when "jal" is executed.d.Each subroutine has its own independent set of registers, much like local variables in C or Java.

In what situations must $1 remain unchanged by a subroutine?Question 13Select one:a.Only if the subroutine does not have a return value.b.Only if the subroutine calls other subroutines.c.Always. Conventions dictate that all registers are not modified by a subroutine.d.Never. Any subroutine is free to modify $1.

Why must registers be backed up at the beginning of a subroutine, and restored before returning?Question 5Select one:a.Conventions dictate that all registers are moved onto the stack.b.Registers might spontaneously change value, therefore backing them up is advisable to prevent against data loss.c.A subroutine expects parameters to be stored on the stack.d.Saving/restoring registers creates the illusion that each subroutine has its own independent set of registers, despite the CPU only having a single set that's shared across the entire program.

Could subroutines use a dedicated section of memory (allocated in .data or .bss) for backing up and restoring register values, instead of using the stack?Question 1Select one:a.Not possible.b.Yes, but it is impossible to use this method and also use the stack to pass parameters to any functions called.c.Yes, this would work fine but it requires more work.d.Yes, but this would only work for a small number of registers because .data and .bss are smaller than the stack segment.

Choose the word or phrase which has a similar meaning to:returnaccountgo backreverse

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.