Specifications
CAVR-4
Part1. Using the compiler
Assembler language interface
99
Calling convention
A calling convention is the way a function in a program calls another function. The
compiler handles this automatically, but, if a function is written in assembler language,
you must know where and how its parameters can be found, how to return to the program
location from where it was called, and how to return the resulting value.
It is also important to know which registers an assembler-level routine must preserve. If
the program preserves too many registers, the program might be ineffective. If it
preserves too few registers, the result would be an incorrect program.
The AVR IAR C/C++ Compiler provides two calling conventions—one old, which is
used in version 1.x of the compiler, and one new, which is default. This section describes
the calling conventions used by the AVR IAR C/C++ Compiler. The following items are
looked upon:
● Choosing a calling convention
● Function declarations
● C and C++ linkage
● Preserved versus scratch registers
● Function entrance
● Function exit
● Return address handling.
At the end of the section, some examples are shown to describe the calling convention
in practice.
CHOOSING A CALLING CONVENTION
There are two calling conventions to choose between:
● The old calling convention offers a simple assembler interface. It is compatible with
the calling convention used in version 1.x of the compiler. Even though this
convention is not used by default, it is recommended for use when mixing C and
assembler code
● The new calling convention is default. It is more efficient than the old calling
convention, but also more complex to understand and subject to change in later
versions of the compiler.
The new calling convention is used by default. However, you can choose a calling
convention by using the --version1_calls command line option. You can also
declare individual functions to use the old calling convention by using the
__version_1 function attribute, for example:
extern
__version_1 void doit(int arg);