6.4.1 How a Function Makes a Call
A function (parent function) performs the following tasks when it calls another function (child function).
- The calling function (parent) is responsible for preserving any save-on-call registers across the call that are live across the call. (The save-on-call registers are R11-R15.)
- If the called function (child) returns a structure, the caller allocates space for the structure and passes the address of that space to the called function as the first argument.
- The caller places the first arguments in registers R12-R15, in that order. The caller moves the remaining arguments to the argument block in reverse order, placing the leftmost remaining argument at the lowest address. Thus, the leftmost remaining argument is placed at the top of the stack. An argument with a type larger than 16 bits that would start in a save-on-call register may be split between R15 and the stack.
- The caller calls the function.
Functions defined in C++ that must be called in asm must be defined extern "C", and functions defined in asm that must be called in C++ must be prototyped extern "C" in the C++ file.