English
Language : 

CC78K4 Datasheet, PDF (162/523 Pages) NEC – CC78K4 Ver.2.30 or Later, C Compiler Language
CHAPTER 10 LIBRARY FUNCTIONS
(2) When -ZR option is specified
The following example shows the procedure of passing arguments and return values when the -ZR option is
specified.
Called function “long func (int a, long b, char *c);”
<1> Place arguments on the stack (by the caller)
The higher 16 bits of arguments “c” and “b” and the lower 16 bits of argument “b” are placed on the stack in
the order named. a is passed via the AX register.
<2> Call func by call instruction (by the caller).
The return address is placed on the stack next to the lower 16 bits of argument “b” and control is
transferred to the function func.
<3> Save the registers used in the functions (by the caller).
<4> Perform processing of the function func, and store return values in the register (by the callee).
Store the lower 16 bits of the return value (long) in BC and the higher 16 bits in RP2.
<5> Restore the saved registers (by the callee).
<6> Save the return address in the register (by the callee).
Save the return address in the WHL register.
<7> The caller restores the placed arguments (by the callee).
<8> Return control to the function on the caller in the branch instruction (by the callee) at the value saved in the
register in <6>.
Return control to the function on the caller in the BR WHL instruction (by the callee).
Figure 10-2. Stack Area When Function Is Called (–ZR Specified)
Stack pointer after <3>
Stack pointer after <2>
Stack pointer after <1>
Stack pointer before
stacking arguments
High address
RP3
Return address
Lower 16 bits of b
Higher 16 bits of b
c
Return value in <4> is stored
Lower 16 bits
Higher 16 bits
BC
RP2
Stack pointer after <5>
Stack pointer after <6>
Stack pointer after <7>
162
User’s Manual U15556EJ1V0UM