English
Language : 

CC78K0S Datasheet, PDF (480/520 Pages) NEC – C Compiler Ver.1.30 or Later Language
CHAPTER 12 REFERENCING THE ASSEMBLER
12.4 Calling C Language Routines from Assembly Language
(1) Calling the C language function from an assembly language program
The procedure for calling a function written in the C language from an assembly language routine is:
(1) Place the arguments on the stack.
(2) Save the C work registers (AX, BC, and DE).
(3) Call the C language function.
(4) Increment the value of the stack pointer (SP) by the number of bytes of arguments.
(5) Reference the return value of the C language function (in BC or DE and BC).
This is an example of an assembly language program.
$PROCESSOR (9024)
NAME FUNC2
EXTRN _CSUB
PUBLIC _FUNC2
@@CODE CSEG
_FUNC2:
movw
push
movw
call
pop
ret
END
ax, #20H
ax
ax, #21H
!_CSUB
ax
; Sets 2nd argument (j)
;
; Sets 1st argument (i)
; Calls "CSUB (i, j)"
;
(1) Stacking arguments
Any arguments are placed on the stack. Figure 12-3 shows argument passing.
Figure 12-3. Placing Arguments on Stack
low address
CSUB (i, j)
AX register
1st arg
2nd arg
high address
Stack area
480
User’s Manual U14872EJ1V0UM