Specifications
CAVR-4
106
Calling convention
AVR® IAR C/C++ Compiler
Reference Guide
Registers used for returning values
For both calling conventions, the registers available for returning values are R16–R19.
Note that the size of a returned pointer depends on the memory model in use;
appropriate registers are used accordingly.
Stack handling
Normally, it is the responsibility of the called function to clean the stack. The only
exception is for ellipse functions—functions with a variable argument list such as
printf—for which it is the responsibility of the caller to clean the stack.
RETURN ADDRESS HANDLING
A function written in assembler language should, when finished, return to the caller. At
a function call, the return address is automatically stored on the RSTACK (not the
CSTACK).
Typically, a function returns by using the
RET instruction.
RESTRICTIONS FOR SPECIAL FUNCTION TYPES
Interrupt functions
Interrupt functions differ from ordinary C functions in that:
● If used, flags and scratch registers are saved
● Calls to interrupt functions are made via interrupt vectors; direct calls are not
allowed
● No arguments can be passed to an interrupt function
● Interrupt functions returns by using the RETI function.
For more information about interrupt functions, see Interrupt functions, page 29.
Return values Passed in registers
8-bit values
R16
16-bit values
R17:R16
24-bit values
R18:R17:R16
32-bit values
R19:R18:R17:R16
Table 29: Registers used for returning values