Parameter Passing in Registers

C functions may pass parameters in registers and/or 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 what registers are used for passing parameters.

Argument
Number

char,
1
-byte ptr

int,
2
-byte ptr

long,
float

untyped
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 will be 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.