How To Use The Standard I/O Library - Fujitsu F2MC-16L User Manual

Hide thumbs Also See for F2MC-16L:
Table of Contents

Advertisement

3.4

How to Use the Standard I/O Library

In general, the programs contained in the standard I/O library are written using the C
interface. Accordingly, you must use the function execution interface for the C
language when using the library from an assembly language program.
When 0ng a function written in C, the calling program pushes the parameters being
passed onto the stack. After the function completes, the calling program must restore
the stack to its previous level.
I Program interface
In general, the programs contained in the standard I/O library are written using the C interface.
Accordingly, you must use the function execution interface for the C language when using the
library from an assembly language program.
When using the standard I/O library from a C program, use the functions in the same way as
standard C functions.
I Function call interface
When executing a function written in C, the calling program pushes the parameters being
passed onto the stack. After the function completes, the calling program must restore the stack
to its previous level. When there is more than one argument, push the arguments onto the stack
in order from the right. For value arguments, push the 2-byte or 4-byte value onto the stack. The
number of bytes is determined by the type (two bytes for the char and short (int) types and four
bytes for the long type). For address arguments, push the 4-byte address for the large model or
2-byte address for the small model.
The function return value is returned in the AL register.
Figure 4.4a shows an example of calling the "chrcnt = printf("%d %ld \n", 100, 5000L);" function
from assembly language. The example is for the large model library.
format .data.b "%d %|d", 10, 0
.import _printf
.section
CSEG,CODE,ALIGH=2
:
:
movl
a,#5000
pushw
ah
;
pushw
a
mov
a,#100
pushw
a
a,#format ; Push address of format string onto stack
movl
pushw
ah
pushw
a
callp
_printf
addsp
#10
Figure 3.4a Example of Calling the printf Function
3.4 How to Use the Standard I/O Library
*
; \n = 10, string terminator = 0
; Push long data (5000) onto stack
;
; Push int data (100) onto stack
:
:
:
; Execute printf. Add _ in front of the entry label
; Release stack
; AL=chrcnt
25

Advertisement

Table of Contents
loading

This manual is also suitable for:

F2mc-16xlF2mc-16F2mc-16hF2mc-16f

Table of Contents