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 |
char, |
int, |
long, |
untyped |
1 |
R7 |
R6 &
R7 |
R4 - R7 |
R1 - R3 |
2 |
R5 |
R4 &
R5 |
R4 - R7 |
R1 - R3 |
3 |
R3 |
R2 &
R3 |
R1 - R3 |
|
The following examples clarify how registers are selected for parameter passing.
Declaration |
Description |
func1 ( |
The first and only argument, a, is passed in registers R6 and R7. |
Func2 ( |
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 ( |
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 ( |
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. |