English
Language : 

CC78K0S Datasheet, PDF (476/520 Pages) NEC – C Compiler Ver.1.30 or Later Language
CHAPTER 12 REFERENCING THE ASSEMBLER
12.3 Calling Assembly Language Routines from C Language
This section shows examples when the normal model (default) is used. If the -QV option, -QR option, and -QRV
option are specified, arguments are stored as indicated in Table 12-2. However, the HL register is allocated only
when no base pointer is required (when base pointer is not used).
Calling an assembly language routine from the C language is described as follows.
• C language function calling procedure
• Saving data from the assembly language routine and returning
(1) C language function calling procedure
This is a C language program example that calls an assembly language routine.
extern int FUNC(int, long);
void main()
{
int
long
i, j;
l;
i = 1;
l = 0x54321;
j = FUNC(i, l);
}
/* Function prototype */
/* Function call */
In this program example, the interface and control flow with the program that is being executed are as follows.
(1) Placing the first argument passed from the main function to the FUNC function in the register, and the
second and subsequent arguments on the stack.
(2) Passing control to the FUNC function by using the CALL instruction.
The next figure shows the stack immediately after control moves to the FUNC function in the above program
example.
Figure 12-1. Stack Area After a Call
low address
Stack pointer
Return address to main
l (lower word)
l (higher word)
Arguments passed to
the FUNC function
AX register
i
476
high address
Stack area
User’s Manual U14872EJ1V0UM