3.3. 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 1 below shows the types of registers affected by these conventions. Table 2 summarizes how the compiler uses registers and whether their values are preserved across calls. Table 3 and 4 provide register usage information for VFP and Neon registers, respectively. For information about how values are preserved across calls, see Function Structure and Calling Conventions.
Table 1: 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
Link register
Contains the return address of a function call
Program counter
Contains the current address of code being executed
Table 2: Register Usage
Register
Alias
Usage
Preserved by Function (Note 1 below)
R0
A1
Argument register, return register, expression register
Parent
R1
A2
Argument register, return register, expression register
Parent
R2
A3
Argument register, expression register
Parent
R3
A4
Argument register, expression register
Parent
R4
V1
Expression register
Child
R5
V2
Expression register
Child
R6
V3
Expression register
Child
R7
V4, AP
Expression register, argument pointer
Child
R8
V5
Expression register
Child
R9
V6
Expression register
Child
R10
V7
Expression register
Child
R11
V8
Expression register
Child
R12
V9, 1P
Expression register, instruction pointer
Parent
R13
SP
Stack pointer
Child (Note 2 below)
R14
LR
Link register, expression register
Child
R15
PC
Program counter
N/A
CPSR
Current program status register
Child
SPSR
Saved program status register
Child
Note 1) The parent function refers to the function making the function call. The child function refers to the function being called.
Note 2) The SP is preserved by the convention that everything pushed on the stack is popped off before returning.
Table 3: VFP Register Usage
32-Bit Register
64-Bit Register
Usage
Preserved by Function (Note 1 below)
FPSCR
Status register
N/A
S0
D0
Floating-point expression, return values, pass arguments
N/A
S1
S2
D1
Floating-point expression, return values, pass arguments
N/A
S3
S4
D2
Floating-point expression, return values, pass arguments
N/A
S5
S6
D3
Floating-point expression, return values, pass arguments
N/A
S7
S8
D4
Floating-point expression, pass arguments
N/A
S9
S10
D5
Floating-point expression, pass arguments
N/A
S11
S12
D6
Floating-point expression, pass arguments
N/A
S13
S14
D7
Floating-point expression, pass arguments
N/A
S15
S16
D8
Floating-point expression
Child
S17
S18
D9
Floating-point expression
Child
S19
S20
D10
Floating-point expression
Child
S21
S22
D11
Floating-point expression
Child
S23
S24
D12
Floating-point expression
Child
S25
S26
D13
Floating-point expression
Child
S27
S28
D14
Floating-point expression
Child
S29
S30
D15
Floating-point expression
Child
S31
D16-D31
Floating-point expression
Note 1) The child function refers to the function being called.
Table 4: Neon Register Usage
64-Bit Register
Quad Register
Usage
Preserved by Function (Note 1 below)
D0
Q0
SIMD register
N/A
D1
D2
Q1
SIMD register
N/A
D3
D4
Q2
SIMD register
N/A
D5
D6
Q3
SIMD register
N/A
D7
D8
Q4
SIMD register
Child
D9
D10
Q5
SIMD register
Child
D11
D12
Q6
SIMD register
Child
D13
D14
Q7
SIMD register
Child
D15
D16
Q8
SIMD register
N/A
D17
D18
Q9
SIMD register
N/A
D19
D20
Q10
SIMD register
N/A
D21
D22
Q11
SIMD register
N/A
D23
D24
Q12
SIMD register
N/A
D25
D26
Q13
SIMD register
N/A
D27
D28
Q14
SIMD register
N/A
D29
D30
Q15
SIMD register
N/A
D31
FPSCR
Status register
N/A
Note 1) The child function refers to the function being called.