Atmel CAVR-4 Manuale Utente
CAVR-4
102
Calling convention
AVR® IAR C/C++ Compiler
Reference Guide
Special registers
For some registers there are certain prerequisites that you must consider:
●
The stack pointer—register
Y
—must at all times point to the last element on the
stack. In the eventuality of an interrupt, everything below the point that the stack
pointer points to, will be destroyed.
pointer points to, will be destroyed.
●
If using the
-v4
or
-v6
processor option, the
RAMPY
register is part of the data stack
pointer.
●
If using a processor option which utilizes any of the registers
EIND
,
RAMPX
, or
RAMPZ
, these registers are treated as scratch registers.
FUNCTION CALL
During a function call, the calling function:
●
passes the parameters, either in registers or on the stack
●
pushes any other parameters on the data stack (CSTACK)
Control is then passed to the called function with the return address being automatically
pushed on the return address stack (RSTACK).
pushed on the return address stack (RSTACK).
The called function:
●
stores any local registers required by the function on the data stack
●
allocates space for its auto variables and temporary values
●
proceeds to run the function itself.
Register parameters versus stack parameters
Parameters can be passed to a function using one of two basic methods: in registers or
on the stack. It is much more efficient to use registers than to take a detour via memory,
so the calling convention is designed to utilize registers as much as possible. The
remaining parameters not passed in registers are passed on the stack.
on the stack. It is much more efficient to use registers than to take a detour via memory,
so the calling convention is designed to utilize registers as much as possible. The
remaining parameters not passed in registers are passed on the stack.
Register parameters
For both calling conventions, the registers available for passing parameters are:
R16–R23
Parameters are allocated to registers using a first-fit algorithm, using parameter
alignment requirements according to the following table:
alignment requirements according to the following table:
Parameters
Alignment
Passed in registers
8-bit values
1
R16
,
R17
,
R18
,
R19
,
R20
,
R21
,
R22
,
R23
Table 27: Registers used for passing parameters