Register Conventions

Strict conventions associate specific registers with specific operations in the C/C++ environment. If you plan to interface an assembly language routine to a C/C++ program, you must understand and follow these register conventions.

The register conventions dictate how the compiler uses registers and how values are preserved across function calls. Table 6-3 shows the types of registers affected by these conventions. Table 6-4 summarizes how the compiler uses registers and whether their values are preserved across calls. For information about how values are preserved across calls, see Section 6.4.

Table 6-3 How Register Types Are Affected by the Conventions

Register Type Description
Argument register Passes arguments during a function call
Return register Holds the return value from a function call
Expression register Holds a value
Argument pointer Used as a base value from which a function's parameters (incoming arguments) are accessed (AP)
Stack pointer Holds the address of the top of the software stack (SP)
Link register Contains the return address of a function call (LR)
Program counter Contains the current address of code being executed

Table 6-4 Register Usage

Register Usage Save on Call Save on Entry
R0.w0 Expression register Yes
R1 Expression register Yes
R2 Stack pointer (SP)
R3.w0 Expression register
R3.w2 Expression register (usually used as Link register to store the return address) Yes
R4 Argument pointer (AP) Yes
R5 Expression register Yes
R6 Expression register Yes
R7 Expression register Yes
R8 Expression register Yes
R9 Expression register Yes
R10 Expression register Yes
R11 Expression register Yes
R12 Expression register Yes
R13 Expression register Yes
R14 Return register Yes
R15 Expression register Yes
R16 Expression register Yes
R17 Expression register Yes
R18 Expression register Yes
R19 Expression register Yes
R20 Expression register Yes
R21 Expression register Yes
R22 Expression register Yes
R23 Expression register Yes
R24 Expression register Yes
R25 Expression register Yes
R26 Expression register Yes
R27 Expression register Yes
R28 Expression register Yes
R29 Expression register Yes
R30 Control register
R31 Control register