Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
104
Calling convention
AVR® IAR C/C++ Compiler
Reference Guide
This would result in 
a
 being allocated to 
R16
 (first fit), 
b
 to 
R19:R18
 (alignment), 
c
 to 
R23:R22:R21:R20
 (first fit), and 
d
 to 
R17
 (first fit).
A third example:
void baz(char a, char _ _far * b, int c, int d)
This would give, 
a
 being allocated to 
R16
b
 to 
R22:R21:R20
c
 to 
R19:R18
, and 
d
 to 
the stack.
Stack parameters
There is only a limited number of registers that can be used for passing parameters; 
when no more registers are available, the remaining parameters are passed on the stack. 
In addition, the parameters are passed on the stack in the following cases:
Structure types: 
struct
union
, and classes if larger than 4 bytes
The data type 
double
 (64-bit floating-point numbers)
Unnamed parameters to variable length functions; in other words, functions 
declared as 
foo
(
param1
...
), for example 
printf
.
Stack layout 
A function call creates a stack frame as follows:
Figure 2: Storing stack parameters in memory
Note that only the registers that are used will be saved.
Stack parameters
Any parameters that did not go into registers.
Saved registers
R4–R15, R24–R27
Auto variables
Area for local variables.
Temporary storage
Any temporary values.
High 
address
Low 
address
Y
Stack pointer