
Derek B. answered 06/02/23
BS in Computer Information Technology, Specializing in Cloud/Web Dev.
The RISC-V calling convention specifies that the caller-saved registers (a0-a7, t0-t6, and ra) are expected to be preserved across function calls. If a function uses these registers, it must save the old values and restore them before returning. The callee-saved registers (s0-s11) are expected to be preserved by the called function. If these registers are modified by the called function, it must save the old values before modifying them and restore them before returning.
Given this, let's analyze the options:
1. "t1 needs to be saved." - True. The function uses t1, a caller-saved register, so it needs to be saved before the function call and restored afterward.
2. "ra does not need saving" - False. The function uses the jal instruction, which modifies the ra register. Therefore, ra needs to be saved before the function call and restored afterward.
3. "only ra needs to be saved" - False. The function uses both t1 and ra, so both need to be saved.
4. "all s# registers should be saved" - False. The s# registers are callee-saved, so they are expected to be preserved by the called function. The calling function does not need to save them.
5. "reg_set2 is: should include t1" - True. As mentioned above, t1 needs to be saved before the function call and restored afterward.
6. "reg_set1 is empty" - True. The function does not modify any callee-saved registers before the function call, so there is no need to save any registers in reg_set1.
7. "a0 doesn't need to be saved on the stack" - True. The a0 register is caller-saved, so it is expected to be preserved by the calling function, not the called function.
8. "only t1 and ra need to be saved" - True. These are the only caller-saved registers that are modified by the function.
9. "all t# should be saved" - False. The function only uses t1, so only t1 needs to be saved.
10. "reg_set1 should include ra, s1, s2, s3" - False. As mentioned above, the s# registers are callee-saved, so they are expected to be preserved by the called function. The calling function does not need to save them. Also, ra is not modified before the function call, so it does not need to be saved in reg_set1.
11. "reg_set2 is empty" - False. As mentioned above, t1 and ra need to be saved before the function call and restored afterward, so they should be included in reg_set2.