Atmel CAVR-4 ユーザーズマニュアル

ページ / 323
CAVR-4
Part1. Using the compiler
Assembler language interface
107
Monitor functions
A monitor function causes interrupts to be disabled during execution of the function. At 
function entry, the status register 
SREG
 is saved and global interrupts are disabled. At 
function exit, the global interrupt enable bit (I) is restored in the 
SREG
 register, and 
thereby the interrupt status existing before the function call is also restored.
For more information about monitor functions, see Monitor functions, page 30.
EXAMPLES
The following section shows a series of declaration examples and the corresponding 
calling conventions. The complexity of the examples increases towards the end.
Example 1
Assume that we have the following function declaration:
int add1(int);
This function takes one parameter in the register 
R17:R16
, and the return value is passed 
back to its caller in the register 
R17:R16
.
The following assembler routine is compatible with the declaration; it will return a value 
that is one number higher than the value of its parameter:
SUBI
R16,FF
SBCI
R17,FF
Example 2
This example shows how structures are passed on the stack. Assume that we have the 
following declarations:
struct a_struct { int a; int b; int c;};
int a_function(struct a_struct x, int y);
The calling function must reserve six bytes bytes on the top of the stack and copy the 
contents of the 
struct
 to that location. The integer parameter 
y
 is passed in the register 
R17:R16
. The return value is passed back to its caller in the register 
R17:R16
.
Example 3
The function below will return a 
struct
.
struct a_struct { int a; };
struct a_struct  a_function(int x);