• Keine Ergebnisse gefunden

Chapter 8 ANSI Library

8.4 Lower-level Functions

The following three functions (read, write, and _exit) are the lower-level functions called by a library function.

Since these functions depend on hardware, they are not provided in the library. If these functions are desired, define them in the user program.

For an example of a C source file that defines these functions, refer to sys.c in the sample\ansilib\ directory.

8.4.1 "read" Function

Contents of read function

Format: int read(int fd, char *buf, int nbytes);

Argument: int fd; File descriptor denoting input

When called from a library function, 0 (stdin) is passed.

char *buf; Pointer to the buffer that stores input data int nbytes; Number of bytes transferred

Functionality: This function reads up to nbytes of data from the user-defined input buffer, and stores it in the buffer indicated by buf.

Returned value: Number of bytes actually read from the input buffer

If the input buffer is empty (EOF) or nbytes = 0, 0 is returned.

If an error occurs, -1 is returned.

Library functions that call the read function:

Direct call: fread, getc, _doscan (_doscan is a scanf-series internal function) Indirect call: fgetc, fgets, getchar, gets (calls getc)

scanf, fscanf, sscanf (calls _doscan) Definition of input buffer

Format: unsigned char READ_BUF[65]; (Variable name is arbitrary; size is fixed to 65 bytes) unsigned char READ_EOF;

Buffer contents: The size of the input data (1 to max. 64) is stored at the beginning of the buffer (READ_BUF[0]). 0 denotes EOF.

The input data is stored in READ_BUF[1], and the following locations.

READ_EOF stores the status that indicates whether EOF is reached.

Precautions on using a simulated I/O

When using the debugger's simulated I/O, define in the read function the global label "READ_FLASH" that is required for the debugger to update the input buffer, then create the function so that new data will be read into the input buffer at that position. (For details about the simulated I/O function, refer to the chapter where the debugger is discussed.)

8.4.2 "write" Function

Contents of write function

Format: int write(int fd, char *buf, int nbytes);

Argument: int fd; File descriptor denoting output

When called from a library function, 1 (stdout) or 2 (stderr) is passed.

char *buf; Pointer to the buffer that stores output data int nbytes; Number of transferred bytes

Functionality: The data stored in the buffer indicated by buf is written as much as indicated by nbytes to the user-defined output buffer.

Returned value: Number of bytes actually written to the output buffer If data is written normally, nbytes is returned.

If a write error occurs, a value other than nbytes is returned.

Library function that calls the write function:

Direct call: fwrite, putc, _doprint (_doprint is printf-series internal function) Indirect call: fputc, fputs, putchar, puts (calls putcc)

printf, fprintf, sprintf, vprintf, vfprintf (calls _doprint) perror (calls fprintf)

Definition of output buffer

Format: unsigned char WRITE_BUF[65]; (Variable name is arbitrary; size is fixed to 65 bytes) Buffer content: The size of the output data (1 to max. 64) is stored at the beginning of the buffer

(WRITE_BUF[0]). 0 denotes EOF.

The output data is stored in WRITE_BUF[1], and the following locations.

Precautions on using simulated I/O

When using the debugger's simulated I/O, define in the write function the global label "WRITE_FLASH"

that is required for the debugger to update the output buffer, and create a function so that data will be output from the output buffer at that position. (For details about the simulated I/O function, refer to the chapter where the debugger is discussed.)

8.4.3 "_exit" Function

Contents of _exit function Format: void _exit(void);

Functionality: Performs program terminating processing.

Argument/ Returned value: None

CHAPTER 9: PREPROCESSOR

EPSON

Chapter 9 Preprocessor

This chapter describes the functions of the Preprocessor pp33.

9.1 Functions

The preprocessor pp33 (hereafter called "pp33") is the C compiler package's first tool to process the assembly source file; therefore, it provides the assembler as33 with additional functions. It expands the additional function part described in the assembly source file to mnemonics that can be assembled. The functions provided by the pp33 are as follows:

· Macro definition and macro invocation

· Definition of Define name

· Operators

· Insertion of other file

· Conditional assembly

· Addition of debugging information for assembly source display

9.2 Input/Output Files

Preprocessor pp33

file.s

file.ps pp33.err

Assembly source file

Assembly source file

Error file Instruction Extender ext33

Fig. 9.2.1 Flowchart

9.2.1 Input File

Source file

File format: Text file

File name: <file name>.s (Other extensions than ".s" can be used.)

Description: File in which the assembly source program is described. Instructions for the pp33 and the extended instructions can be described there.

9.2.2 Output Files

Assembly source file

File format: Text file

File name: <file name>.ps (The <file name> is the same as that of the input file.) Output destination: Current directory

Description: File in which instructions for the pp33 are expanded into an assembling format.

Error file

File format: Text file

File name: pp33.err

Output destination: Current directory

Description: File that is output when the startup option (-e) is specified, and describes the contents which the pp33 delivers through the Standard Output (stdout), such as an error message.

9.3 Starting Method

9.3.1 Startup Format

General form of command line

pp33 ^ [<startup option>] ^ [<file name>]

^ denotes a space.

[ ] indicates the possibility to omit.

<file name>: Specify an assembly source file name including the extension (.s).

Operations on work bench

Select options and a source file, then click the [PP33] button.

In the command line, only one source file can be specified at a time.

The wb33 allows multiple files to be selected, in which case the pp33 is executed as many times as the number of files selected.

9.3.2 Startup Options

The pp33 comes provided with the following three types of startup options:

-d <Define name>

Function: Definition of Define name Specification on wb33: Enter in the [define] text box.

Explanation: · Works in the same manner as you describe "#define <Define name>" at top of the source. It is an option to control the conditional assembly at the startup. However, unlike the #define definition, it does not perform replacement in the source.

· One or more spaces are necessary between -d and the <Define name>.

· Refer to Section 9.5.2 for formats and restrictions of definable names.

· To define two or more Define names, repeat the specification of "-d <Define name>".

For the wb33, separate each <Define name> with a comma (,) as you input them.

-g

Function: Addition of debugging information Specification on wb33: Check [debug info].

Explanation: · Creates an output file containing debugging information.

· Always specify this function when you perform the assembly source level debugging.

· Refer to Section 9.7 for debugging information.

-e

Function: Output of error files

CHAPTER 9: PREPROCESSOR

EPSON

9.4 Messages

The pp33 delivers its messages through the Standard Output (stdout).

If the pp33 is started up by using the wb33's [PP33] button, the message is output to "wb33.err". When execution is completed, a message is displayed in the output window (default).

End message

The pp33 outputs only the following end message when it ends normally.

Pre Processor Completed Usage output

If no file name was specified or an option was not specified correctly, the pp33 ends after delivering the following message concerning the usage:

Pre Processor 33 Ver x.xx

Copyright (C) SEIKO EPSON CORP. 199x Usage:

pp33 [options] filename Options:

-e : produce log file (pp33.err)

-g : generate debug information in output file -d string : define string

Output:

Assembler source file for ext33 (.ps) Example:

pp33 -e -g -d TYPE1 test.s When error/warning occurs

If an error is produced, an error message will appear before the end message shows up.

Example: test.s(431): Error: Invalid Syntax.

Pre Processor Completed

In the case of an error, the pp33 ends without creating an output file.

If a warning is issued, a warning message will appear before the end message shows up.

Example: test.s(211): Warning: Multi define symbol.

Pre Processor Completed

In the case of a warning, the pp33 ends after creating an output file.

For details on errors and warnings, refer to Section 9.12 "Error/Warning Messages".