Keil Logo

Passing in Registers

C functions may pass parameters in registers and fixed memory locations. A maximum of 3 parameters may be passed in registers. All other parameters are passed using fixed memory locations. The following tables define which registers are used for passing parameters.

Arg Number char,
1-byte ptr
int,
2-byte ptr
long, float generic ptr
1 R7 R6 & R7
(MSB in R6,LSB in R7)
R4—R7 R1—R3
(Mem type in R3, MSB in R2, LSB in R1)
2 R5 R4 & R5
(MSB in R4,LSB in R5)
R4—R7 R1—R3
(Mem type in R3, MSB in R2, LSB in R1)
3 R3 R2 & R3
(MSB in R2,LSB in R3)
  R1—R3
(Mem type in R3, MSB in R2, LSB in R1)

The following examples clarify how registers are selected for parameter passing.

Declaration Description
func1 (
int a)
The first and only argument, a, is passed in registers R6 and R7.
func2 (
int b,
int c,
int *d)
The first argument, b, is passed in registers R6 and R7. The second argument, c, is passed in registers R4 and R5. The third argument, d, is passed in registers R1, R2, and R3.
func3 (
long e,
long f)
The first argument, e, is passed in registers R4, R5, R6, and R7. The second argument, f, cannot be located in registers since those available for a second parameter with a type of long are already used by the first argument. This parameter is passed using fixed memory locations.
func4 (
float g,
char h)
The first argument, g, passed in registers R4, R5, R6, and R7. The second parameter, h, cannot be passed in registers and is passed in fixed memory locations.

Related Knowledgebase Articles

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.