Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
100
Calling convention
AVR® IAR C/C++ Compiler
Reference Guide
For details about the 
--version1_calls
 option and the 
_ _version_1
 attribute, see 
Hints for using the new calling convention
The new calling convention is very complex, and therefore not recommended for use 
when calling assembler routines. However, if you intend to use it for your assembler 
routines, you should create a list file and see how the compiler assigns the different 
parameters to the available registers. For an example, see Creating skeleton code, page 
96
If you intend to use the new calling convention, you should also specify a value to the 
runtime model attribute 
_ _rt_version
 using the 
RTMODEL
 assembler directive:
RTMODEL "_ _rt_version"="value"
The parameter 
value
 should have the same value as used internally by the compiler. For 
information about what value to use, see the generated list file. If the calling convention 
changes in future compiler versions, the runtime model value used internally by the 
compiler will also change. Using this method gives a module consistency check as the 
linker will produce an error if there is a mismatch between the values.
For more information about checking module consistency, see Checking module 
consistency
, page 77.
FUNCTION DECLARATIONS 
In C, a function must be declared in order for the compiler to know how to call it. A 
declaration could look as follows:
int a_function(int first, char * second);
This means that the function takes two parameters: an integer and a pointer to a 
character. The function returns a value, an integer.
In the general case, this is the only knowledge that the compiler has about a function. 
Therefore, it must be able to deduce the calling convention from this information.
C AND C++ LINKAGE
In C++, a function can have either C or C++ linkage. Only functions with C linkage can 
be implemented in assembler. 
The following is an example of a declaration of a function with C linkage:
extern "C"
{
   int f(int);
}