Atmel CAVR-4 사용자 설명서
CAVR-4
Part1. Using the compiler
Assembler language interface
101
It is often practical to share header files between C and C++. The following is an
example of a declaration that declares a function with C linkage in both C and C++:
example of a declaration that declares a function with C linkage in both C and C++:
#ifdef _ _cplusplus
extern "C"
{
#endif
int f(int);
#ifdef _ _cplusplus
}
#endif
PRESERVED VERSUS SCRATCH REGISTERS
The general AVR CPU registers are divided into three separate sets, which are described
in this section.
in this section.
Scratch registers
Any function may destroy the contents of a scratch register. If a function needs the
register value after a call to another function, it must store it during the call, for example
on the stack.
register value after a call to another function, it must store it during the call, for example
on the stack.
For both calling conventions, the following 14 registers can be used as scratch
registers by a function:
registers by a function:
R0–R3
,
R16–R23
, and
R30–R31
Preserved registers
Preserved registers, on the other hand, are preserved across function calls. Any function
may use a preserved register for other purposes, but must save the value prior to use and
restore it at the exit of the function.
may use a preserved register for other purposes, but must save the value prior to use and
restore it at the exit of the function.
For both calling conventions, the following registers are preserved registers:
R4–R15
and
R24–R27
Note that the registers
R4–R15
can be locked from the command line and used for global
register variables; see --lock_regs, page 186 and __regvar, page 212.