← 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:

RegisterConventional role under the Arm procedure-call standard
r0First argument and primary return value
r1–r3Remaining first four arguments; caller-saved scratch values
r4–r8, r10Callee-saved general registers
r9Platform-specific role; callee-saved as v6 only when the platform ABI assigns it that role
r11Callee-saved; commonly used as a frame pointer when that compiler/ABI choice is enabled
r12Intra-procedure-call scratch register (IP)
r13Stack pointer (SP); Main and Process stack banks may exist
r14Link register (LR), holding return or exception-return context
r15Program 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.

Cortex-M address regions paired with core-register groups, calling-convention roles, frame pointer, stack pointer, link register, and program counter.
Cortex-M address regions identify memory roles. Core registers connect a function call to its arguments, stack, and return context.

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.

← Back to the chapter · Previous detail · Next detail →