In ARM architecture, why must a function preserve callee-saved registers?
Think about who is responsible for keeping the values intact across function calls.
Callee-saved registers must be preserved by the called function because the caller assumes their values remain unchanged after the call. This allows the caller to rely on these registers without saving them before the call.
Identify the registers that are usually preserved by the callee in ARM calling conventions.
Consider which registers are used for passing arguments and which are preserved.
In ARM, registers r4 to r11 and the stack pointer (sp) are callee-saved. Registers r0 to r3 are caller-saved and used for passing arguments.
What is the likely outcome if a function modifies callee-saved registers but does not restore them before returning?
Think about the caller's expectations about register values after a function call.
If callee-saved registers are modified and not restored, the caller may read incorrect values, leading to bugs or crashes.
Given this ARM assembly snippet, which option correctly preserves callee-saved registers?
push {r4, r5, lr}
// function body
pop {r4, r5, pc}Remember which registers must be saved and how to return from a function.
r4 and r5 are callee-saved registers and must be saved and restored. lr (link register) is saved to return properly using pc in pop.
In ARM, when a function uses callee-saved registers and creates a stack frame, what is the correct order of operations to preserve these registers and set up the frame?
Think about saving registers before using stack space and restoring in reverse order.
The function first saves callee-saved registers, then adjusts the stack pointer for locals, performs operations, and finally restores the stack pointer and registers before returning.