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:
Where:
- Additional arguments spill to stack based on ABI layout rules.
Return register convention (common scalar case):
Where:
- Larger aggregates may use memory or additional ABI-defined paths.
Implementation walkthrough
- Cross-check compiler-generated assembly for expected save/restore and arg moves.
- When writing inline assembly, document clobbers and preserved registers explicitly.
- Validate mixed-language call chains with targeted test functions.
- Keep ABI assumptions explicit in low-level module docs.
Validation and debugging checklist
- Handwritten assembly that clobbers preserved registers creates non-local failures.
- Wrong return register usage can pass tests accidentally and fail under optimization.
- Implicit stack layout assumptions are fragile across toolchain updates.
- Treat ABI warnings as correctness issues, not style comments.
If you can explain register ownership at each call boundary, ABI bugs become preventable rather than mysterious.