Profile

Elektro Lab

Analog soul, digital mind


ARM Cortex-M: Calling Convention Basics

Technical mental model

Calling convention is the contract that keeps separately compiled code interoperable. Without ABI discipline, mixed C/assembly paths become unstable and difficult to debug.

Argument and return register rules determine how data enters and exits function boundaries.

Caller-saved and callee-saved responsibilities prevent accidental context corruption.

Stack alignment and spill strategy affect both correctness and performance.

Equations and constraints that drive decisions

Argument register mapping for first parameters:

argiRi(0i3)arg_i \to R_i \quad (0 \le i \le 3)

Where:

Return register convention (common scalar case):

retR0ret \to R_0

Where:

Implementation walkthrough

  1. Cross-check compiler-generated assembly for expected save/restore and arg moves.
  2. When writing inline assembly, document clobbers and preserved registers explicitly.
  3. Validate mixed-language call chains with targeted test functions.
  4. Keep ABI assumptions explicit in low-level module docs.

Validation and debugging checklist

If you can explain register ownership at each call boundary, ABI bugs become preventable rather than mysterious.


You Might Also Like