← Back to the chapter · Previous detail · Next detail →
Technical detail · Microcontroller Programming: Timing and Reliability
Cortex-M registers and function calls
An application binary interface (ABI) is a shared set of rules for calls between compiled functions. Caller-saved registers may be changed by the called function, so the caller saves any values it still needs. Callee-saved registers must be restored by the called function before it returns. The table shows the usual Arm roles:
| Register | Conventional role under the Arm procedure-call standard |
|---|---|
r0 | First argument and primary return value |
r1–r3 | Remaining first four arguments; caller-saved scratch values |
r4–r8, r10 | Callee-saved general registers |
r9 | Platform-specific role; callee-saved as v6 only when the platform ABI assigns it that role |
r11 | Callee-saved; commonly used as a frame pointer when that compiler/ABI choice is enabled |
r12 | Intra-procedure-call scratch register (IP) |
r13 | Stack pointer (SP); Main and Process stack banks may exist |
r14 | Link register (LR), holding return or exception-return context |
r15 | Program counter (PC) |
The frame pointer is a convention, not a new register. A toolchain may use r7, r11, or no frame pointer. Follow the callee-saved rule and inspect debug data rather than assuming an r11 chain exists.
Pair address evidence with live execution state using Figure 4.
In Figure 4, the top strip runs from Code 0x0 through SRAM, peripheral, device, and system regions. Below it, r0-r3 carry early arguments and return values. The stack pointer r13 locates the stack, r14 holds return context, and r15 is the program counter. Together these views help a debugger connect an address to the code path that used it. The chip manual still determines which addresses are implemented.