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
Stack pointer Holds the address of the top of the software stack
Program counter Contains the current address of code being executed

Table 6-4 Register Usage and Preservation Conventions

Register Alias Usage Preserved by Function(1)
R0 PC Program counter N/A
R1 SP Stack pointer N/A(2)
R2 SR Status register N/A
R3 Constant generator N/A
R4-R10 Expression register Child
R11 Expression register Parent
R12 Expression register, argument pointer, return register Parent
R13 Expression register, argument pointer, return register Parent
R14 Expression register, argument pointer, return register Parent
R15 Expression register, argument pointer, return register Parent
The parent function refers to the function making the function call. The child function refers to the function being called.
The SP is preserved by the convention that everything pushed on the stack is popped off before returning.