CX6812
CX6812
CX6812
OSMIC
Soft ware
Version 4.6
Table of Contents
Preface
Organization of this Manual ....................................................... 1
Chapter 1
Introduction
Introduction................................................................................. 4
Document Conventions............................................................... 4
Typewriter font..................................................................... 4
Italics .................................................................................... 5
[ Brackets ] ........................................................................... 5
Conventions.......................................................................... 6
Command Line ..................................................................... 6
Flags ..................................................................................... 6
Compiler Architecture ................................................................ 8
Predefined Symbol...................................................................... 9
Linking........................................................................................ 9
Programming Support Utilities................................................... 9
Listings...................................................................................... 10
Optimizations............................................................................ 11
Support for Bank Switching ..................................................... 12
Support for ROMable Code...................................................... 12
Support for eeprom ................................................................... 13
Chapter 2
Tutorial Introduction
Acia.c, Example file.................................................................. 16
Default Compiler Operation ............................................... 17
Compiling and Linking............................................................. 18
Step 1: Compiling............................................................... 18
Step 2: Assembler............................................................... 19
Step 3: Linking ................................................................... 20
Step 4: Generating S-Records file ...................................... 23
Linking Your Application......................................................... 24
Generating Automatic Data Initialization................................. 25
Specifying Command Line Options ......................................... 27
Chapter 3
Programming Environments
Introduction............................................................................... 30
Modifying the Runtime Startup ................................................ 32
(i)
Chapter 4
Using The Compiler
Invoking the Compiler.............................................................. 72
Compiler Command Line Options ..................................... 73
File Naming Conventions......................................................... 79
Generating Listings................................................................... 80
Generating an Error File ........................................................... 80
Return Status............................................................................. 80
Examples .................................................................................. 80
C Library Support ..................................................................... 81
How C Library Functions are Packaged............................. 81
Inserting Assembler Code Directly .................................... 81
(ii)
(iii)
(iv)
Chapter 5
Using The Assembler
Invoking ca6812 ..................................................................... 204
Object File............................................................................... 207
Listings.................................................................................... 207
Assembly Language Syntax.................................................... 208
Instructions ....................................................................... 208
Labels ............................................................................... 210
Temporary Labels............................................................. 211
Constants .......................................................................... 211
Expressions....................................................................... 212
Macro Instructions............................................................ 214
(v)
(vi)
Chapter 6
Using The Linker
Introduction............................................................................. 285
Overview................................................................................. 286
Linker Command File Processing........................................... 288
Inserting comments in Linker commands ........................ 289
Linker Options ........................................................................ 290
Global Command Line Options........................................ 291
Segment Control Options ................................................. 292
Segment Grouping............................................................ 295
Linking Files on the Command line ................................. 296
Example............................................................................ 296
Include Option .................................................................. 297
Example............................................................................ 297
(vii)
Chapter 7
Debugging Support
Generating Debugging Information........................................ 324
Generating Line Number Information.............................. 324
Generating Data Object Information................................ 324
The cprd Utility ...................................................................... 326
Command Line Options ................................................... 326
Examples .......................................................................... 327
The clst utility ......................................................................... 328
Command Line Options ................................................... 328
Chapter 8
Programming Support
The cbank Utility .................................................................... 332
Command Line Options ................................................... 332
(viii)
Chapter A
Compiler Error Messages
Parser (cp6812) Error Messages ............................................. 352
Code Generator (cg6812) Error Messages.............................. 366
Assembler (ca6812) Error Messages ...................................... 367
Linker (clnk) Error Messages ................................................. 370
Chapter B
Modifying Compiler Operation
The Configuration File............................................................ 374
Changing the Default Options ................................................ 375
Creating Your Own Options............................................. 375
Example .................................................................................. 376
(ix)
Chapter C
HC12/HCS12 Machine Library
Get a long bitfield............................................................. 378
Store a long bitfield .......................................................... 379
Check stack growth .......................................................... 380
Add double to double ....................................................... 381
Compare double with double ........................................... 382
Divide double by double .................................................. 383
Multiply double by double ............................................... 384
Negate a double ................................................................ 385
Move a structure in DPAGE space................................... 386
Subtract double from double ............................................ 387
Copy a double into a double............................................. 388
Convert double to float..................................................... 389
Convert double to integer ................................................. 390
Convert double into long integer...................................... 391
Copy a double onto the stack ........................................... 392
Eeprom char bit field update ............................................ 393
Eeprom short bit field update ........................................... 394
Eeprom long bit field update ............................................ 395
Write a short int aligned in eeprom .................................. 396
Write a char int in eeprom................................................ 397
Write a double in eeprom ................................................. 398
Write a long int in eeprom................................................ 399
Write a short int in eeprom............................................... 400
Move a structure in eeprom.............................................. 401
Move a structure in eeprom.............................................. 402
Multiply signed int by unsigned int.................................. 403
Multiply unsigned int by signed int.................................. 404
Move a structure in EPAGE space ................................... 405
Add float to float .............................................................. 406
Compare floats ................................................................. 407
Divide float by float ......................................................... 408
Float addition.................................................................... 409
Float division.................................................................... 410
Float multiplication .......................................................... 411
Float subtraction ............................................................... 412
Multiply float by float ...................................................... 413
Subtract float from float ................................................... 414
Convert float into double.................................................. 415
Convert float to integer..................................................... 416
Convert float into long integer ......................................... 417
(x)
(xi)
Chapter D
Compiler Passes
The cp6812 Parser .................................................................. 462
Command Line Options ................................................... 462
Return Status .................................................................... 466
Example............................................................................ 466
The cg6812 Code Generator................................................... 467
Command Line Options ................................................... 467
Return Status .................................................................... 470
Example............................................................................ 470
The co6812 Assembly Language Optimizer .......................... 471
Command Line Options ................................................... 471
Disabling Optimization .................................................... 472
Return Status .................................................................... 472
Example............................................................................ 472
(xii)
Preface
he Cross Compiler User's Guide for HC12/HCS12 is a reference
guide for programmers writing C programs for HC12/HCS12
microcontroller environments. It provides an overview of how the cross
compiler works, and explains how to compile, assemble, link and debug
programs. It also describes the programming support utilities included
with the cross compiler and provides tutorial and reference information
to help you configure executable images to meet specific requirements.
This manual assumes that you are familiar with your host operating system and with your specific target environment.
Preface
Preface
CHAPTER
1
Introduction
This chapter explains how the compiler operates. It also provides a
basic understanding of the compiler architecture. This chapter includes
the following sections:
Introduction
Document Conventions
Compiler Architecture
Predefined Symbol
Linking
Listings
Optimizations
Introduction
Introduction
Introduction
The C cross compiler targeting the HC12/HCS12 microcontroller reads
C source files, assembly language source files, and object code files,
and produces an executable file. You can request listings that show your
C source interspersed with the assembly language code and object code
that the compiler generates. You can also request that the compiler generate an object module that contains debugging information that can be
used by COSMICs C source level cross debugger or by other debuggers or in-circuit emulators.
You begin compilation by invoking the cx6812 compiler driver with the
specific options you need and the files to be compiled.
Document Conventions
In this documentation set, we use a number of styles and typefaces to
demonstrate the syntax of various commands and to show sample text
you might type at a terminal or observe in a file. The following is a list
of these conventions.
Typewriter font
Used for user input/screen output. Typewriter (or courier) font is
used in the text and in examples to represent what you might type at a
terminal: command names, directives, switches, literal filenames, or
any other text which must be typed exactly as shown. It is also used in
other examples to represent what you might see on a screen or in a
printed listing and to denote executables.
To distinguish it from other examples or listings, input from the user
will appear in a shaded box throughout the text. Output to the terminal
or to a file will appear in a line box.
For example, if you were instructed to type the compiler command that
generates debugging information, it would appears as:
cx6812 +debug acia.c
Introduction
Document Conventions
If, however, the text included a partial listing of the file acia.c an
example of text from a file or from output to the terminal then typewriter font would still be used, but would be enclosed in a line box:
/* defines the ACIA as a structure */
struct acia {
char status;
char data;
} acia @0x6000;
NOTE
Due to the page width limitations of this manual, a single invocation line
may be represented as two or more lines. You should, however, type the
invocation as one line unless otherwise directed.
Italics
Used for value substitution. Italic type indicates categories of items for
which you must substitute appropriate values, such as arguments or
hypothetical filenames. For example, if the text was demonstrating a
hypothetical command line to compile and generate debugging information for any file, it might appear as:
cx6812 +debug file.c
[ Brackets ]
Items enclosed in brackets are optional. For example, the line:
[ options ]
means that zero or more options may be specified because options
appears in brackets. Conversely, the line:
options
means that one or more options must be specified because options is not
enclosed by brackets.
2004 COSMIC Software
Introduction
Document Conventions
means that one file with the extension .o or .h12 may be specified, and
the line:
file1 [ file2 . . . ]
Conventions
All the compiler utilities share the same optional arguments syntax.
They are invoked by typing a command line.
Command Line
A command line is generally composed of three major parts:
program_name [<flags>] <files>
Flags
Flags are used to select options or specify parameters. Options are recognized by their first character, which is always a - or a +, followed
by the name of the flag (usually a single letter). Some flags are simply
yes or no indicators, but some must be followed by a value or some
additional information. The value, if required, may be a character
string, a single character, or an integer. The flags may be given in any
order, and two or more may be combined in the same argument, so long
as the second flag cant be mistaken for a value that goes with the previous one.
It is possible for each utility to display a list of accepted options by
specifying the -help option. Each option will be displayed alphabetically on a separate line with its name and a brief description. If an
option requires additional information, then the type of information is
Introduction
Document Conventions
Type of information
character string
short integer
##
long integer
single character
If the code is immediately followed by the character >, the option may
be specified more than once with different values. In that case, the
option name must be repeated for every specification.
For example, the options of the chex utility are:
chex [options] file
-a##
absolute file start address
-b##
address bias
-e##
entry point address
-f?
output format
-h
suppress header
+h*
specify header string
-m#
maximum data bytes per line
-n*>
output only named segments
-o*
output file name
-p
use paged address format
-pp
use paged address with mapping
-pn
use paged address in bank only
-s
output increasing addresses
-x*
exclude named segment
Introduction
Compiler Architecture
Flags
Function
-a
-b
-e
-f
-h
+h
-m
-n
-o
-p
-pn
-pp
-s
-x
Compiler Architecture
The C compiler consists of several programs that work together to
translate your C source files to executable files and listings. cx6812
controls the operation of these programs automatically, using the
options you specify, and runs the programs described below in the order
listed:
Introduction
Predefined Symbol
ca6812 - the assembler. ca6812 converts the assembly language output of co6812 to a relocatable object module.
Predefined Symbol
The COSMIC compiler defines the __CSMC__ preprocessor symbol. It
expands to a numerical value whose each bit indicates if a specific
option has been activated:
bit 0:
bit 1:
bit 2:
bit 3:
bit 4:
bit 5:
Linking
clnk combines all the object modules that make up your program with
the appropriate modules from the C library. You can also build your
own libraries and have the linker select files from them as well. The
linker generates an executable file which, after further processing with
the chex utility, can be downloaded and run on your target system. If
you specify debugging options when you invoke cx6812, the compiler
will generate a file that contains debugging information. You can then
use the COSMICs debugger to debug your code.
Introduction
Listings
clabs - absolute listing utility. clabs translates relocatable listings produced by the assembler by replacing all relocatable information by
absolute information. This utility must to be used only after the linker.
clib - build and maintain object module libraries. clib allows you to
collect related files into a single named library file for convenient storage. You use it to build and maintain object module libraries in standard
library format.
cobj - object module inspector. cobj allows you to examine standard
format executable and relocatable object files for symbol table information and to determine their size and configuration.
Listings
Several options for listings are available. If you request no listings, then
error messages from the compiler are directed to your terminal, but no
additional information is provided. Each error is labelled with the C
source file name and line number where the error was detected.
If you request an assembly language and object code listing with interspersed C source, the compiler merges the C source as comments
among the assembly language statements and lines of object code that it
generates. Unless you specify otherwise, the error messages are still
written to your terminal. Your listing is the listing output from the
assembler.
10
Introduction
Optimizations
Optimizations
The C cross compiler performs a number of compile time and optimizations that help make your application smaller and faster:
Introduction
11
12
Introduction
@eeprom type qualifier to describe a variable as an eeprom location. The compiler generates special sequences when the variable
is modified.
NOTE
The basic routine to program an eeprom byte is located in the library file
eeprom.s and has been written using the default input/output address
0x. This file must be modified if using a different base address.
For information on using the compiler, see Chapter 4.
For information on using the assembler, see Chapter 5.
For information on using the linker, see Chapter 6.
For information on debugging support, see Chapter 7.
For information on using the programming utilities, see Chapter 8.
For information on the compiler passes, see Appendix D.
Introduction
13
CHAPTER
2
Tutorial Introduction
This chapter will demonstrate, step by step, how to compile, assemble
and link the example program acia.c, which is included on your distribution media. Although this tutorial cannot show all the topics relevant
to the COSMIC tools, it will demonstrate the basics of using the compiler for the most common applications.
In this tutorial you will find information on the following topics:
Tutorial Introduction
15
/* buffer size */
/* transmit ready bit */
/*
Authorize interrupts.
*/
#define cli()_asm("andcc #$EF\n")
/*
Some variables.
*/
char buffer[SIZE];
char *ptlec;
char *ptecr;
/* reception buffer */
/* read pointer */
/* write pointer */
/*
Character reception.
*
Loops until a character is received.
*/
char getch(void)
{
char c;
/* character to be returned */
while (ptlec == ptecr)/* equal pointers => loop */
;
c = *ptlec++;
/* get the received char */
if (ptlec >= &buffer[SIZE])/* put in in buffer */
ptlec = buffer;
return (c);
}
/*
Send a char to the SCI 0.
*/
void outch(char c)
{
while (!(SC0SR1 & TDRE))/* wait for READY */
;
SC0DRL = c;/* send it */
}
16
Tutorial Introduction
/*
Character reception routine.
*
This routine is called on interrupt.
*
It puts the received char in the buffer.
*/
@interrupt void recept(void)
{
SC0SR1;
/* clear interrupt */
*ptecr++ = SC0DRL;
/* get the char */
if (ptecr >= &buffer[SIZE])/* put it in buffer */
ptecr = buffer;
}
/*
Main program.
*
Sets up the SCI and starts
*
loop of receive transmit.
*/
void main(void)
{
ptecr = ptlec = buffer; /*
SC0BDL = 52;
/*
SC0CR2 = 0x2c;
/*
cli();
/*
for (;;)
/*
outch(getch());
/*
}
an infinite
initialize pointers */
initialize SCI */
parameters for interrupt */
authorize interrupts */
loop */
get and put a char */
Tutorial Introduction
17
Step 1: Compiling
The first step consists in compiling the C source file and producing an
assembly language file named acia.s.
cx6812 -s acia.c
The -s option directs cx6812 to stop after having produced the assembly
file acia.s. You can then edit this file with your favorite editor. You can
also visualize it with the appropriate system command (type, cat,
more,...). For example under MS/DOS you would type:
type acia.s
18
Tutorial Introduction
The -v option, known as verbose mode, instructs the C compiler to display all of its actions. For example if you type:
cx6812 -v -s acia.c
the C parser
cg6812
co6812
the optimizer
Step 2: Assembler
The second step of the compilation is to assemble the code previously
produced. The relocatable object file produced is acia.o.
cx6812 acia.s
or
ca6812 -i\cosmic\h6812\acia.s
Tutorial Introduction
19
Step 3: Linking
This step consists in linking relocatable files, also referred to as object
modules, produced by the compiler or by the assembler (<files>.o) into
an absolute executable file: acia.h12 in our example. Code and data
sections will be located at absolute memory addresses. The linker is
used with a command file (acia.lkf in this example).
An application that uses one or more object module(s) may require several sections (code, data, interrupt vectors, etc.,...) located at different
addresses. Each object module contains several sections. The compiler
creates the following sections:
Type
Description
.ftext
.text
.const
.fdata
.data
.bss
.bsct
.ubsct
.eeprom
.const.w
In our example, and in the test file provided with the compiler, the
acia.lkf file contains the following information:
20
Tutorial Introduction
You can create your own link command file by modifying the one provided with the compiler.
Here is the explanation of the lines in acia.lkf:
lines 1 to 3: These are comment lines. Each line can include comments.
They must be prefixed by the # character.
line 4: +seg .const -b0x1c000 -o0xc000 -n.const creates a
const segment located at physical address 1c000 (hexa) and logical
address c000 which is named .const (page 7 unbanked).
line 5: +seg .text -a.const creates a text (code) segment located
after the previous const segment (page 7 unbanked).
line 6: +seg .data -b0x2000 creates a data segment located at 2000
(hex address)
line 7: +def __sbss=@.bss defines a symbol __sbss equal to the
value of the current address in the .bss segment. This is used to get the
address of the start of the bss. The symbol __sbss is used by the startup
routine to reset the bss.
line 8: crts.o runtime startup code. It will be located at 0xc000
(code segment)
Tutorial Introduction
21
line 9: acia.o, the file that constitutes your application. It follows the
startup routine for code and data
line 10: libi.h12 the integer library to resolve references
line 11: libm.h12 the machine library to resolve references
line 12: +seg .vector -b0x1ffb8 -o0xffb8 creates a new constant segment located at ffb8
line 13: vectors.o interrupt vectors file
line 14: +def __memory=@.bss defines a symbol __memory equal to
the value of the current address in the .bss segment. This is used to get
the address of the end of the bss. The symbol __memory is used by the
startup routine to reset the bss.
line 15: +def __stack=0x4000 defines a symbol __stack equal to the
absolute value 4000 (hex value). The symbol __stack is used by the
startup routine to initialize the stack pointer.
By default and in our example, the .bss segment follows the .data segment.
The crts.o file contains the runtime startup that performs the following
operations:
22
Tutorial Introduction
or
chex -o acia.hex acia.h12
Tutorial Introduction
23
In this example the linker will locate and merge crts.o, acia.o and
module1.o in a text segment at 0xc000 (page 7, unbanked), a data segment at 0x2000 and a bss segment, if needed at 0x2500. zero page
variables will be located at 0x0. The rest of the application, module2.o
and module3.o will be located in a bank at 0x8000. The libraries will
be located and merged in the page 7 (unbanked) segment named .common at 0xc000 then the interrupt vectors file, vector.o in a .vector segment at 0xffb8.For more information about the linker, see Chapter 6,
Using The Linker.
24
Tutorial Introduction
Tutorial Introduction
25
The following link file demonstrates how to achieve automatic data initialization.
+seg .text -b 0xfe000 -o 0xe000 -n.text# program start
+seg .const -a .text
# constant follow code
+seg .bsct -b 0 -m 0x100
# zpage start address
+seg .data -b0x2000
# data start address
+def __sbss=@.bss
# symbol used by startup
\cx\lib\crtsi.h12
# startup with auto-init
acia.o
# main program
module1.o
# module program
\cx\lib\libi.h12
# C library (if needed)
\cx\lib\libm.h12
# machine library
+def __memory=@.bss
# symbol used by library
+def __stack=0x4000
# stack pointer initial value
or
26
Tutorial Introduction
In the first case, the initialized data will be located after the first code
segment. In the second case, the -it option instructs the linker to locate
the initialized data after the segment marked with this flag. The initialized data will be located after the second code segment located at
address 0xf000.
For more information, see Initializing data in RAM in Chapter 3 and
Automatic Data Initialization in Chapter 6.
The -v option instructs the compiler driver to echo the name and options
of each program it calls. The -l option instructs the compiler driver to
create a mixed listing of C code and assembly language code in the file
acia.ls.
To perform the operations described above, enter the command:
Tutorial Introduction
27
cx6812 -v -l acia.c
When the compiler exits, the following files are left in your current
directory:
This command will compile the acia.c file, create a listing named
acia.ls in the \mylist directory and an object file named acia.o in the
\myobj directory.
cx6812 allows you to compile more than one file. The input files can be
C source files or assembly source files. You can also mix all of these
files.
If your application is composed with the following files: two C source
files and one assembly source file, you would type:
cx6812 -v start.s acia.c getchar.c
This command will assemble the start.s file, and compile the two C
source files.
See Compiler Command Line Options in Chapter 4 for information
on these and other command line options.
28
Tutorial Introduction
CHAPTER
3
Programming
Environments
This chapter explains how to use the COSMIC program development
system to perform special tasks required by various HC12/HCS12
applications.
Programming Environments
29
Introduction
Introduction
The HC12/HCS12 COSMIC compiler is an ANSI C compiler that
offers several extensions which support special requirements of embedded systems programmers. This chapter provides details about:
30
Performing Input/Output in C
Redefining Sections
Inlining Functions
Programming Environments
Introduction
Register Usage
Data Representation
Programming Environments
31
32
Programming Environments
17
18
19
20
21
22
23
24
25
26
lds
#__stack
ifdef PIC
lbsr _main
else
jsr
_main
endif
_exit:
bra
_exit
;
end
; execute main
; stay here
Programming Environments
33
;
;
;
;
;
__stext:
lds
ifdef PIC
leax
ifdef MCX
subx
pshx
else
tfr
subd
pshd
endif
else
ldx
endif
ldy
ibcl:
ldaa
beq
bpl
leax
nopg:
bita
bne
ldy
bra
dseg:
pshx
tfr
subd
ldx
ifdef PIC
ifdef MCX
addy
else
exg
addd
exg
endif
34
_exit, __stext
_main, __sbss, __memory, __idesc__, __stack
#__stack
; code offset
; on the stack
x,d
#__idesc__
; compute
; code offset
; on the stack
#__idesc__
; descriptor address
2,x+
5,x+
zbss
nopg
2,x
;
;
;
;
#$60
dseg
-2,x
ibcl
;
;
;
;
y,d
-2,x
-4,x
;
;
;
;
save pointer
start address
minus end address
destination address
2,s
d,y
2,s
d,y
; adjust
; code address
Programming Environments
endif
dbcl:
movb
ibne
ifdef PIC
ifdef MCX
suby
else
exg
subd
exg
endif
endif
pulx
bra
zbss:
ldx
clrb
bra
zbcl:
std
loop:
cpx
blo
ifdef PIC
puld
lbsr
else
jsr
endif
_exit:
bra
;
end
1,y+,1,x+
d,dbcl
2,s
d,y
2,s
d,y
; restore
; code address
ibcl
#__sbss
loop
; start of bss
; complete zero
; start loop
2,x+
; clear byte
#__memory
zbcl
; end of bss
; no, continue
_main
; clean stack
; execute main
_main
; execute main
_exit
; stay here
crtsi.s performs the same function as described with the crts.s, but with
one additional step. Lines (marked in bold) in crtsi.s include code to
copy the contents of initialized static data, which has been placed in the
text section by the linker, to the desired location in RAM.
For more information, see Generating Automatic Data Initialization
in Chapter 2 and Automatic Data Initialization in Chapter 6.
Programming Environments
35
NOTE
The volatile keyword must be used for any data object (variables) that
can be modified outside of the normal flow of the function. Without the
volatile keyword, all data objects are subject to normal redundant code
removal optimizations. Volatile MUST be used for the following conditions:
1) all data objects or variables associated with a memory mapped hardware register e.g. volatile char PORTD @0x05;
2) all global variable that can be modified (written to) by an interrupt
service routine either directly or indirectly. e.g. a global variable used as
a counter in an interrupt service routine.
You use const to declare data objects whose stored values you do not
intend to alter during execution of your program. You can therefore
place data objects of const type in ROM or in write protected program
segments. The cross compiler generates an error message if it encounters an expression that alters the value stored in a const data object.
36
Programming Environments
Performing Input/Output in C
If you declare a static data object of const type at either file level or at
block level, you may specify its stored value by writing a data initializer. The compiler determines its stored value from its data initializer
before program startup, and the stored value continues to exist
unchanged until program termination. If you specify no data initializer,
the stored value is zero. If you declare a data object of const type at
argument level, you tell the compiler that your program will not alter
the value stored in that argument data object by the function call. If you
declare a data object of const type and dynamic lifetime at block level,
you must specify its stored value by writing a data initializer. If you
specify no data initializer, the stored value is indeterminate.
You may specify const and volatile together, in either order. A const
volatile data object could be a Read-only status register, or a variable
whose value may be set by another program.
Examples of data objects declared with type qualifiers are:
char * const x;
/* const pointer to char */
int * volatile y;
/* volatile pointer to int */
const float pi = 355.0 / 113.0; /* pi is never changed */
Performing Input/Output in C
You perform input and output in C by using the C library functions
getchar, gets, printf, putchar, puts and sprintf. They are described in
chapter 4.
The C source code for these and all other C library functions is included
with the distribution, so that you can modify them to meet your specific
needs. Note that all input/output performed by C library functions is
supported by underlying calls to getchar and putchar. These two functions provide access to all input/output library functions. The library is
built in such a way so that you need only modify getchar and putchar;
the rest of the library is independent of the runtime environment.
Function definitions for getchar and putchar are:
char getchar(void);
char putchar(char c);
Programming Environments
37
A data object declared this way will be located into the section .bsct, if
it is initialized, or in the section .ubsct otherwise. An external object
name is published via a xref.b declaration at the assembly language
level.
To place data objects into the zero page on a file basis, you use the
#pragma directive of the compiler. The compiler directive:
#pragma space [] @dir
instructs the compiler to place all data objects of storage class extern or
static into the zero page for the current unit of compilation (usually a
file). The section must end with a #pragma space [].
38
Programming Environments
NOTE
The code generator does not check for zero page overflow.
Programming Environments
39
To place all data objects from a file into eeprom, you can use the
#pragma directive of the compiler. The directive
#pragma space [] @eeprom
instructs the compiler to treat all extern and static data in the current file
as eeprom locations. The section must end with a #pragma space [].
NOTE
The library modules handling the specific eeprom control registers, the
application must include in at least one C source file one of the provided
header files specific to the actual target (for instance, iosdp256.h). Otherwise, the missing symbols will have to be manually defined with +def
directives in the linker command file.
The compiler allocates @eeprom variables in a separate section named
.eeprom, which will be located at link time. The linker directive:
+seg .eeprom -b0x1000 -m4096
var_eeprom.o
NOTE
The code generator cannot check if the final address of an @eeprom
object will be valid after linkage.
Due to the specific features of the HC12DP256 eeprom, you must use a
specific library to handle correctly the eeprom access. This library is
named libe.h12 and must be linked before the other libraries of the
application.
40
Programming Environments
Redefining Sections
Redefining Sections
The compiler uses by default predefined sections to output the various
components of a C program. The default sections are:
Section
Description
.ftext
.text
.const
.fdata
.data
initialized variables
.bss
uninitialized variables
.bsct
.ubsct
.eeprom
Programming Environments
41
Redefining Sections
A section name is a plain C identifier which does not begin with a dot
character and which is no longer than 13 characters. The compiler will
prefix automatically the section name with a dot character when passing
this information to the assembler. It is possible to switch back to the
default sections by omitting the section name in the <qualified_name>
sequence.
Each pragma directive starts redirecting the selected component from
the next declarations. Redefining the bss section forces the compiler to
produce the memory definitions for all the previous bss declarations
before to switch to the new section.
When the +ceven option is selected in order to have two different sections for aligned and non aligned constants, renaming the const section
renames both sections by applying the suffix .w to the word aligned
part.
The following directives:
#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
section
section
section
section
section
section
section
(code)
const {string}
[udata]
{idata}
@dir {zpage}
@eeprom {e2prom}
@far {dpage}
42
Programming Environments
Inlining Functions
Inlining Functions
The compiler is able to inline a function body instead of producing a
function call. This feature allows the program to run faster but produces
a larger code. A function to be inlined has to be defined with the
@inline modifier. Such a function is kept by the compiler and does not
produced any code yet. Each time this function is called in the same
source file, the call is replaced by the full body of the inlined function.
Because inlined functions are in fact local to a source file, they should
be defined in a header file if they have to be used by several source
files. To allow the arguments to be passed properly, inlined functions
must be defined with prototypes.
NOTE
The current implementation does not allow an inlined function to return
anything and such a function has to be defined with the void return type.
The compiler allows access to specific instructions or features of the
HC12/HCS12 processor, using @inline functions. Such functions shall
be declared as external functions with the @inline modifier. The compiler recognizes two predefined functions when declared as follows:
@inline char carry(void);
@inline char overflow(void);
carry
the carry function is used to test or get the carry bit from
the condition register. If the carry function is used in a test,
the compiler produces a bcc or bcs instruction. If the carry
function is used in any other expression, the compiler produces a code sequence setting the b register to 0 or 1
depending on the carry bit value.
overflow the overflow function is used to test or get the overflow bit
from the condition register. If the overflow function is used
Programming Environments
43
44
Programming Environments
Using this declaration, references to acia.status will refer to memory location 0x6000 and acia.data will refer to memory location
0x6001. This is very useful if you are building your own custom I/O
hardware that must reside at some location in the HC12/HCS12 memory map.
Programming Environments
45
/* for MCS912DP256 */
in each file using the input-output registers. All the register names are
defined by assembly equates which are made public. This allows any
assembler source to use directly the input-output register names by
defining them with an xref directive. All those definitions are already
provided in the io.s files which may be included in an assembly source
by a:
include "iosdp256.s"
; for MCS912DP256
All these header files assume a default location for the input-output registers depending on the actual target. This default value may be changed
by defining the C symbol _BASE by a #define directive before the
header file # include:
#define _BASE 0x1000
#include <iosdp256.h>
The default value of 0 for the register starting address as defined by the
file <iosdp256.h> is changed to 0x1000.
Header files specific to HCS12 (Star12) family members start with
ios while files specific to the standard HC12 family members start
with io.
If these compiler provided header files are not used, the compiler may
still need to access some registers (PPAGE, DPAGE, EPAGE), and
will use the code generator options -t and -r to locate them properly.
46
Programming Environments
Description
#pragma asm
#pragma endasm
The compiler also accepts shorter sequences with the same meaning:
Directive
Description
#asm
#endasm
Programming Environments
47
#pragma asm
xref asmvar
#pragma endasm
extern char test;
void func(void)
{
if (test)
#asm
/* no need for { */
sec
; set carry bit
rol asmvar ; access assembler variable
#endasm
else
test = 1;
}
NOTE
Preprocessing directives are still handled inside assembly code, but
#define symbols or macros are not replaced within assembly instruction
and operands by default. In order to enable such a replacement in the
assembly code, the compiler must be run with the -pad option.This
expansion is limited to the simple macros (without arguments).
The string constant argument is the assembly code you want embedded in your C program. arguments follow the standard C rules for
passing arguments.
NOTE
The argument string must be shorter than 255 characters. If you wish to
insert longer assembly code strings you will have to split your input
among consecutive calls to _asm().
48
Programming Environments
The string you specify follows standard C rules. For example, carriage
returns can be denoted by the \n character.
To produce the following assembly sequence:
leas $1000,x
jsr _main
The \n character is used to separate the instructions when writing multiple instructions in the same line.
To copy a value in the condition register, you write:
_asm(tfr b,ccr, varcc);
allows to test the overflow bit. That way, you can use _asm() to write
equivalents of C functions directly in assembly language.
NOTE
With both methods, the assembler source is added as is to the code during the compilation. The optimizer does not modify the specified instructions, unless the compiler is run with the -ga option.
Programming Environments
49
Inlining Labels
When labels are necessary in the inlined assemby code, the compiler
provides a special syntax allowing local labels to be created and handled without interaction with other labels and the optimizer. The
sequence $N in the assembly source is replaced by a new label name
while the sequence $L is replaced by the label name created by the last
$N. Using this syntax, a simple wait loop may be entered as follow:
#asm
ldab #7
$N:
dbne b,$L ; loop on the previous label
#endasm
50
Programming Environments
NOTE
The @interrupt modifier is an extension to the ANSI standard.
Due to the HC12/HCS12 interrupt mechanism, an interrupt function
cannot be directly placed in a bank. It should be normally located in the
common part and then explicitly defined with the @near modifier if the
source file is compiled with the +modf option.
Programming Environments
51
where handler1 and so forth are interrupt handlers. Then, at link time,
include the following options on the link line:
+seg .vector -b0xfffce -o0xffce vector.o
where vector.o is the file which contains the vector table. This file is
provided in the compiler package. You should modify this vector table
as necessary for your application.
52
Programming Environments
NOTE
The libraries are not built as @far functions and should not be located in
a banked area, if they need to be accessed from any bank.
It is possible to force the compiler to build all the functions as @far
functions by using the +modf option. An example of such a definition
is:
@far int func(void)
{
...
}
-b
-bs
-m
should be specified with the maximum size of each segment, or the maximum size of all the banks if the -w option
is used.
-o
-w
Programming Environments
53
given two banks, the first one obtained from func1, func2 and func3
linked at physical address 0x10000, the second obtained from func4,
func5 and func6 linked at physical address 0x14000. The window
mechanism has to be initialized with the first window at 0x8000. The
code to perform this initialization has to be located in the root segment,
for instance at the beginning of the main function. The linker should
thus be called with the following options:
clnk -o appli.h12 -bs14 appli.lkf
NOTE
Applications not using bank switching should specified the -bs0 option to
disabled the internal banking verification.
It is possible to let the linker automatically fill consecutive banks by
using the -w option specifying the window size. In that case, the +seg
directive describes the first bank and if a new object file turns the bank
size large than the window size, a new bank is automatically starting
from a physical address obtained by adding the window size to the
physical starting address of the previous bank. The -m option specifies
54
Programming Environments
the maximum size of all the possible banks. With the following link
command file:
+seg .text -b 0x10000 -o 0x8000 -m 0x8000 -w 0x4000
func1.o func2.o func3.o
func4.o func5.o func6.o
+seg .text -b 0xc000 -o 0xc000
main.o libm.h12
Programming Environments
55
area. To access the EPAGE area, the @epage modifier has to be used
along with @far. For examples:
@far int i;
A constant can also be defined in a code bank by using the @far modifier along with the const keyword. Such a constant is accessed using the
PPAGE register. This register beeing used implicitly by any banked
code, such a constant can be accessed only by a function located in a
common (non banked) area, but declared as an @far function to ensure
that the PPAGE register is saved on function entry, and restored on
function exit. These constraints are properly checked by the compiler
and the linker.
@far const int k;
The Star12 family processors are also able to decode external data
using the code banking mechanism, and then using the PPAGE register
to access such variables. This feature is implemented with the same
constraints than @far const objects.
By default, any @far data is produced in a separate section called
.fdata, regardless of any initialization, and any @far constant is produced in the default .text section. When using the +nofds option from
the command line, @far data are produced in the .data or .bss sections
as plain data, thus requesting @far data to be declared in a separate
source file in order to allow a correct linking.
If data banking is used, interrupt functions will have to save and restore
these registers if they are used by the interrupt code. The compiler will
detect automatically any explicit usage done by the interrupt function
itself. If the interrupt function does not use directly those registers but
calls any other function, the compiler will not save the page registers, to
keep efficiency on applications not using data bank switching. If data
bank switching is used by the called functions, the @svpage modifier
has to be used on the interrupt function declaration, such as:
56
Programming Environments
NOTE
No data can be allocated across a page boundary and then far pointers
calculations do not update the page number. This means that this feature
cannot be used to allocate large arrays whose size is larger than the page
size.
Linking banked data sections uses the same directives as code bank
switching. Because code and data pages sizes are not identical, an extra
option is needed to specify the page size when defining a segment.
DPAGE segments will use a -ds12 option while EPAGE segments will
use a -ds10 option. To link a DPAGE banked segment, you can use the
automatic filling option such as:
+seg .data -ds12 -b 0x0 -o 0x7000 -m 0x4000 -w 0x1000
data1.o data2.o data3.o
The physical address will match the RAM chip address decoded by the
CSD chip select. The maximum size specified here allows up to 4
pages.
NOTE
Bank switching cannot be used with PIC code.
By default, the data sections are still using the standard addressing
modes and then are linked to a fixed address. Options +picd and +picds
allow data to be also accessed with pc relative addressing mode. With
the +picd option, any data is mapped to the code section, thus letting
Programming Environments
57
revhc12
revwhc12
wavhc12
Note that for keeping efficiency, most of these functions are directly
inlined in the code output instead of calling actual functions.
Those functions are more completely documented in the Chapter 4,
Using The Compiler.
58
Programming Environments
Declaration
Reference
.bsct
xdef
.ubsct
@dir char i;
xdef
.fdata
xdef
.data
int init = 1
xdef
Programming Environments
59
Register Usage
Section
Declaration
Reference
.bss
int uninit
xdef
.ftext
xdef
.text
char putchar(c);
xdef
.const
xdef
Any of above
xref
NOTE
By default, character data is sign extended to short, and floats are
extended to doubles. This widening can be disabled at the user's option.
In that case, character and float will be left unmodified. If widening is
disabled, and the first argument to a function is of type char, and it is
stored in a register, then it will be stored in register b. Data of type short,
integer and long integer are left unmodified.
2) A data space address is moved onto the stack if a structure or double return area is required.
3) The function is called via a jsr _func instruction, or a call f_func if
the function is an @far function.
4) The arguments to the function are popped off the stack.
Register Usage
Except for the return value, the registers d, x, y and the condition codes
are undefined on return from a function call. The return value is in d if
it is of type char widened to short, short, integer or pointer to.... The
return value is in the register d and x if it is of type long or float. The d
register holds the low order word.
60
Programming Environments
Register Usage
Stack Model
Because the stack pointer can be used to address directly the stack, no
register is dedicated as frame pointer. If automatics are needed, the
sequence:
leas -<#>,s
will restore the previous context. Functions that do not have any arguments or autos, and do not use any temporary storage (required to perform operations on structure data or cast float data, for example) do not
reference the frame pointer x and do not stack it.
Stack Representation
The diagrams below show the stack layout at function entry func. In this
example, func has three arguments: arg1, arg2 and arg3. The first diagram describes cases where arg1 is in the d register. The second diagram describes cases where arg1 is not in the d register. In both cases,
arguments are assumed to be widened, so char is widened to short and
float to double.
Programming Environments
61
Register Usage
arg1 is in d
locals
arg1
@return
OFST+0
arg2
arg3
OFST+4
arg1 not in d
locals
@return
arg1
arg2
arg3
OFST+2
62
Programming Environments
uninitialized variables
(bss segment)
The heap start is the bss end, and is equal to the __memory symbol
defined by the linker with an appropriate +def directive. The stack
pointer is initialized by the application startup (crts.s) to an absolute
value, generally the end of available memory, or a value relative to the
end of the bss segment (for multi-tasking purposes for instance). The
heap grows upwards and the stack downwards until collision may
occur.
The heap management functions maintain a global pointer named heap
pointer, or simply HP, pointing to the heap top, and a linked list of
memory blocks, free or allocated, in the area between the heap start and
the heap top. In order to be able to easily modify the heap implementation, the heap management functions use a dedicated function to move
the heap pointer whenever necessary. The heap pointer is initialized to
the heap start: the heap is initially empty. When malloc needs some
memory and no space is available in the free list, it calls this dedicated
function named _sbreak to move the heap pointer upwards if possible.
_sbreak will return a NULL pointer if this move is not possible (usually
Programming Environments
63
this is because the heap would overlap the stack). Therefore it is possible to change the heap default location by rewriting the _sbreak function.
The default _sbreak function provided by the library is as follows:
/*
SET SYSTEM BREAK
*/
void *sbreak(int size)
{
extern char _memory;
static char *_brk = NULL;/* memory break */
char *obrk, yellow[40];
if (!_brk)
/*
_brk = &_memory;
obrk = _brk;
/*
_brk += size;
/*
if (yellow <= _brk || _brk
{
/*
_brk = obrk;
/*
return (NULL);
/*
}
return (obrk);
/*
}
The yellow array is used to calculate the stack pointer value to check the
heap limits. This array is declared as the last local variable, so its
address is almost equal to the stack pointer once the function has been
entered. It is declared to be 40 bytes wide to allow for some security
margin. If the new top is outside the authorized limits, the function
returns a NULL pointer, otherwise, it returns the start of the new allocated area. Note that the top variable _brk is a static variable initialized
to zero (NULL pointer). It is set to the heap start on the first call. It is
also possible to initialize it directly within the declaration, but in this
case, we create an initialized variable in the data segment which needs
to be initialized by the startup. The current code avoids such a requirement by initializing the variable to zero (in the bss segment), which is
simply done by the standard startup sequence.
64
Programming Environments
If you need to place the heap array at a specific location, you need to
locate this module at a specific address using the linker options. In the
above example, the heap array will be located in the .bss segment, thus,
complicating the startup code which would need to zero two bss sections instead of one. Compiling this function, with the +nobss option,
Programming Environments
65
will force allocation of the heap, in the data segment and you can locate
it easily with linker directives as:
+seg .data -b 0x8000
sbreak.o
# heap start
# sbreak function
It is also possible to handle the heap area outside of any C object, just
by defining the heap start and end values using the linker +def directives. Assuming these symbols are named _heap_start and _heap_end
in C, it is possible to define them at link time with such directives:
+def __heap_start=0x8000# heap start
+def __heap_end=0xA000 # heap end
NOTE
Since the initial content of the area may be undefined, the -ib option
should be specified to exclude the segment in the automatic RAM initialization.
You need to add an extra _ character when defining a C symbol at link
time to match the C compiler naming conventions.
The modified _sbreak function is as follows:
/*
SET SYSTEM BREAK IN MEMORY
*/
void *sbreak(int size)
{
extern char _heap_start, _heap_end;/* heap limits */
static char *_brk = NULL;/* memory break */
char *obrk;
if (!_brk)
/* initialize on first call */
_brk = &_heap_start;
obrk = _brk;
/* old top */
_brk += size;
/* new top */
if (&_heap_end <= _brk || _brk < &_heap_start)
{
/* check boundaries */
_brk = obrk;
/* restore old top */
return (NULL);
/* return NULL pointer */
}
return (obrk);
/* return new area start */
}
66
Programming Environments
Note that it is possible to use this _sbreak function as a malloc equivalent function with some restrictions. The malloc function should be
used when the allocated memory has to be released, or if the application
has no idea about the total amount of space needed. If memory can be
allocated and never released, the free mechanism is not necessary, nor
the linked list of memory blocks built by malloc. In that case, simply
rename the _sbreak function as malloc, regardless of its implementation, and you will get a very efficient and compact malloc mechanism.
You may do the renaming in the function itself, which needs to be recompiled, or by using a #define at C level, or by renaming the function at
link time with a +def directive such as:
+pri
+def _malloc=__sbreak
+new
libi.h12
#
#
#
#
Programming Environments
67
Data Representation
Data Representation
Data objects of type char are stored as one byte:
7
Char representation
Data objects of type short int, int and 16 bit pointers (@near) are stored
as two bytes, more significant byte first:
15
8 7
24 23
16 15
8 7
Long representation
Data objects of type @far pointer are stored as four bytes. The first
word is the logical address represented as 16 bit pointer, the next byte is
the paged value and the next byte is a 0.
15
8 7
0 7
LSB
0 7
Page
Zero
68
Programming Environments
Data Representation
resentation is: most significant bit is one for negative numbers, and zero
otherwise; the next eight bits (for float) or eleven bits (for double) are
the characteristic, biased such that the binary exponent of the number is
the characteristic minus 126 (for float) or 1022 (for double); the remaining bits are the fraction, starting with the weighted bit. If the characteristic is zero, the entire number is taken as zero, and should be all zeros
to avoid confusing some routines that do not process the entire number.
Otherwise there is an assumed 0.5 (assertion of the weighted bit) added
to all fractions to put them in the interval [0.5, 1.0). The value of the
number is the fraction, multiplied by -1 if the sign bit is set, multiplied
by 2 raised to the exponent.
31 30
23 22
Sign
Characteristic
Mantissa
Float representation
63 62
52 51
Sign
Characteristic
Mantissa
Double representation
Programming Environments
69
CHAPTER
4
Using The Compiler
This chapter explains how to use the C cross compiler to compile programs on your host system. It explains how to invoke the compiler, and
describes its options. It also describes the functions which constitute the
C library. This chapter includes the following sections:
Generating Listings
C Library Support
71
cx6812 is the name of the compiler. The option list is optional. You
must include the name of at least one input file <file>. <file> can be a
C source file with the suffix .c, or an assembly language source file
with the suffix .s. You may specify multiple input files with any combination of these suffixes in any order.
If you do not specify any command line options, cx6812 will compile
your <files> with the default options. It will also write the name of each
file as it is processed. It writes any error messages to STDERR.
The following command line:
cx6812 acia.c
72
assemble your program. You can change the operation of the compiler
by specifying the options you want when you run the compiler.
To specify options to the compiler, type the appropriate option or
options on the command line as shown in the first example above.
Options should be separated with spaces. You must include the - or
+ that is part of the option name.
-a*>
specify assembler options. Up to 60 options can be specified on the same command line. See Chapter 5, Using
The Assembler, for the list of all accepted options.
73
74
-ce*
specify a path for the error files. By default, errors are created in the same directoy than the source files.
-cl*
-co*
-d*^
specify * as the name of a user-defined preprocessor symbol (#define). The form of the definition is
-dsymbol[=value]; the symbol is set to 1 if value is omitted. You can specify up to 60 such definitions.
-e
-ec
-es
-ex
-f*
specify * as the name of a configuration file. This file contains a list of options which will be automatically used by
the compiler. If no file name is specified, then the compiler
looks for a default configuration file named cx6812.cxf in
the compiler directory as specified in the installation process. For more information, see Appendix B, Modifying
Compiler Operation.
-g*>
-i*>
-l
merge C source listing with assembly language code; listing output defaults to <file>.ls.
-no
-o*>
specify optimizer options. Up to 60 options can be specified. See Appendix D, Compiler Passes, for the list of
all accepted options.
-p*>
-s
-sp
-t*
-v
be verbose. Before executing a command, print the command, along with its arguments, to STDOUT. The default
is to output only the names of each file processed. Each
name is followed by a colon and newline.
-x
+*>
select a predefined compiler option. These options are predefined in the configuration file. You can specify up to 20
compiler options on the command line. The following documents the available options as provided by the default
configuration file.
75
76
+ceven
split the constants into two sections, one for single byte
constant (.const) and one for the other ones which are supposed to be accessed more efficiently when properly
aligned (.const.w).
+debug
produce debug information to be used by the debug utilities provided with the compiler and by any external debugger.
+even
+fast
+modf
+nobss
do not use the .bss section for variables allocated in external memory. By default, such uninitialized variables are
defined into the .bss section. This option is useful to force
all variables to be grouped into a single section.
+nocst
+nofds
+nofts
+pgff
+pic
+picd
+picds
+proto
enforce prototype declaration for functions. An error message is issued if a function is used and no prototype declaration is found for it. By default, the compiler accepts both
syntaxes without any error.
+rev
77
78
+split
produce each C function in a separate section, thus allowing the linker to suppress unused functions if the -k option
has been specified on at least one segment in the linker
command file. For more information, see Segment Control Options in Chapter 6.
+sprec
+std
+strict
+zpage
cp6812
<file>.c
<file>.1
cg6812
<file>.1
<file>.2
co6812
<file>.2
<file>.s
error listing
<file>.c
<file>.err
assembler listing
<file>.[c|s]
<file>.ls
C header files
<file>.h
ca6812
<file>.s
<file>.o
source listing
<file>.s
<file>.ls
clnk
<file>.o
name required
cbank
<file>
STDOUT
chex
<file>
STDOUT
clabs
<file.h12>
<files>.la
clib
<file>
name required
cobj
<file>
STDOUT
cv695
<file>
<file>.695
cvdwarf
<file.h12>
<file.elf>
79
Generating Listings
Generating Listings
You can generate listings of the output of any (or all) the compiler
passes by specifying the -l option to cx6812. You can locate the listing
file in a different directory by using the -cl option.
The example program provided in the package shows the listing produced by compiling the C source file acia.c with the -l option:
cx6812 -l acia.c
The error file name is obtained from the source filename by replacing
the .c suffix by the .err suffix.
Return Status
cx6812 returns success if it can process all files successfully. It prints a
message to STDERR and returns failure if there are errors in at least
one processed file.
Examples
To echo the names of each program that the compiler runs:
cx6812 -v file.c
To save the intermediate files created by the code generator and halt
before the assembler:
cx6812 -s file.c
80
C Library Support
C Library Support
This section describes the facilities provided by the C library. The C
cross compiler for HC12/HCS12 includes all useful functions for programmers writing applications for ROM-based systems.
atol
calloc
div
eepcpy
eepera
eepset
exit
free
getchar
realloc
gets
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
strcmp
isqrt
isspace
isupper
isxdigit
labs
ldiv
longjmp
lsqrt
malloc
strspn
81
C Library Support
memcmp
memcpy
memmov
memset
printf
putchar
puts
rand
sbreak
scanf
setjmp
sprintf
srand
sscanf
strcat
strchr
strcmp
strcpy
strcspn
strlen
strncat
strncpy
strpbrk
strrchr
strstr
strtol
strtoul
tolower
toupper
vprintf
vsprintf
cosh
exp
fabs
floor
fmod
frexp
ldexp
log
log10
modf
pow
printf
scanf
sin
sinh
sprintf
sqrt
sscanf
strtod
tan
tanh
revhc12
revwhc12
wavhc12
C Library Support
83
C Library Support
84
85
C Library - _asm
_asm
Description
Generate inline assembly code
Syntax
/* no header file need be included */
_asm(<string constant>, ...)
Function
_asm generates inline assembly code by copying <string constant>
and quoting it into the output assembly code stream. If extra arguments
are specified, they are processed as for a standard function. If arguments are stacked, they are popped off just after the inline code produced. For more information, see Inserting Inline Assembly
Instructions in Chapter 3.
Return Value
Nothing, unless _asm() is used in an expression. In that case, normal
return conventions must be followed. For more information, see Register Usage in Chapter 3.
Example
The sequence tsx; pshx, may be generated by the following call:
_asm(\ttsx\n\tpshx\n);
Notes
_asm() is not packaged in any library. It is recognized (and its argument
passed unchanged) by the compiler itself.
86
C Library - abort
abort
Description
Abort program execution
Syntax
#include <stdlib.h>
void abort(void)
Function
abort stops the program execution by calling the exit function which is
placed by the startup module just after the call to the main function.
Return Value
abort never returns.
Example
To abort in case of error:
if (fatal_error)
abort();
See Also
exit
Notes
abort is a macro equivalent to the function name exit.
87
C Library - abs
abs
Description
Find absolute value
Syntax
#include <stdlib.h>
int abs(int i)
Function
abs obtains the absolute value of i. No check is made to see that the
result can be properly represented.
Return Value
abs returns the absolute value of i, expressed as an int.
Example
To print out a debit or credit balance:
printf(balance %d%s\n, abs(bal), (bal < 0)? CR : );
See Also
labs, fabs
Notes
abs is packaged in the integer library.
88
C Library - acos
acos
Description
Arccosine
Syntax
#include <math.h>
double acos(double x)
Function
acos computes the angle in radians the cosine of which is x, to full double precision.
Return Value
acos returns the closest internal representation to acos(x), expressed as
a double floating value in the range [0, pi]. If x is outside the range
[-1, 1], acos returns zero.
Example
To find the arccosine of x:
theta = acos(x);
See Also
asin, atan, atan2
Notes
acos is packaged in the floating point library.
89
C Library - asin
asin
Description
Arcsine
Syntax
#include <math.h>
double asin(double x)
Function
asin computes the angle in radians the sine of which is x, to full double
precision.
Return Value
asin returns the nearest internal representation to asin(x), expressed as a
double floating value in the range [-pi/2, pi/2]. If x is outside the range
[-1, 1], asin returns zero.
Example
To compute the arcsine of y:
theta = asin(y);
See Also
acos, atan, atan2
Notes
asin is packaged in the floating point library.
90
C Library - atan
atan
Description
Arctangent
Syntax
#include <math.h>
double atan(double x)
Function
atan computes the angle in radians; the tangent of which is x, atan computes the angle in radians; the tangent of which is x, to full double precision.
Return Value
atan returns the nearest internal representation to atan(x), expressed as
a double floating value in the range [-pi/2, pi/2].
Example
To find the phase angle of a vector in degrees:
theta = atan(y/x) * 180.0 / pi;
See Also
acos, asin, atan2
Notes
atan is packaged in the floating point library.
91
C Library - atan2
atan2
Description
Arctangent of y/x
Syntax
#include <math.h>
double atan2(double y, double x)
Function
atan2 computes the angle in radians the tangent of which is y/x to full
double precision. If y is negative, the result is negative. If x is negative,
the magnitude of the result is greater than pi/2.
Return Value
atan2 returns the closest internal representation to atan(y/x), expressed
as a double floating value in the range [-pi, pi]. If both input arguments
are zero, atan2 returns zero.
Example
To find the phase angle of a vector in degrees:
theta = atan2(y/x) * 180.0/pi;
See Also
acos, asin, atan
Notes
atan2 is packaged in the floating point library.
92
C Library - atof
atof
Description
Convert buffer to double
Syntax
#include <stdlib.h>
double atof(char *nptr)
Function
atof converts the string at nptr into a double. The string is taken as the
text representation of a decimal number, with an optional fraction and
exponent. Leading whitespace is skipped and an optional sign is permitted; conversion stops on the first unrecognizable character. Acceptable
inputs match the pattern:
[+|-]d*[.d*][e[+|-]dd*]
where d is any decimal digit and e is the character e or E. No checks
are made against overflow, underflow, or invalid character strings.
Return Value
atof returns the converted double value. If the string has no recognizable characters, it returns zero.
Example
To read a string from STDIN and convert it to a double at d:
gets(buf);
d = atof(buf);
See Also
atoi, atol, strtol, strtod
Notes
atof is packaged in the floating point library.
93
C Library - atoi
atoi
Description
Convert buffer to integer
Syntax
#include <stdlib.h>
int atoi(char *nptr)
Function
atoi converts the string at nptr into an integer. The string is taken as the
text representation of a decimal number. Leading whitespace is skipped
and an optional sign is permitted; conversion stops on the first unrecognizable character. Acceptable characters are the decimal digits. If the
stop character is l or L, it is skipped over.
No checks are made against overflow or invalid character strings.
Return Value
atoi returns the converted integer value. If the string has no recognizable characters, zero is returned.
Example
To read a string from STDIN and convert it to an int at i:
gets(buf);
i = atoi(buf);
See Also
atof, atol, strtol, strtod
Notes
atoi is packaged in the integer library.
94
C Library - atol
atol
Description
Convert buffer to long
Syntax
#include <stdlib.h>
long atol(char *nptr)
Function
atol converts the string at nptr into a long integer. The string is taken as
the text representation of a decimal number. Leading whitespace is
skipped and an optional sign is permitted; conversion stops on the first
unrecognizable character. Acceptable characters are the decimal digits.
If the stop character is l or L it is skipped over.
No checks are made against overflow or invalid character strings.
Return Value
atol returns the converted long integer. If the string has no recognizable
characters, zero is returned.
Example
To read a string from STDIN and convert it to a long l:
gets(buf);
l = atol(buf);
See Also
atof, atoi, strtol, strtod
Notes
atol is packaged in the integer library.
95
C Library - calloc
calloc
Description
Allocate and clear space on the heap
Syntax
#include <stdlib.h>
void *calloc(int nelem, int elsize)
Function
calloc allocates space on the heap for an item of size nbytes, where
nbytes = nelem * elsize. The space allocated is guaranteed to be at least
nbytes long, starting from the pointer returned, which is guaranteed to
be on a proper storage boundary for an object of any type. The heap is
grown as necessary. If space is exhausted, calloc returns a null pointer.
The pointer returned may be assigned to an object of any type without
casting. The allocated space is initialized to zero.
Return Value
calloc returns a pointer to the start of the allocated cell if successful;
otherwise it returns NULL.
Example
To allocate an array of ten doubles:
double *pd;
pd = calloc(10, sizeof (double));
See Also
free, malloc, realloc
Notes
calloc is packaged in the integer library.
96
C Library - carry
carry
Description
Test or get the carry bit
Syntax
#include <processor.h>
@inline char carry(void)
Function
carry is an inline function allowing to test or get the value of the carry
bit. When used in an if construct, this function expands directly to a bcc
or bcs instruction. When used in an expression, it expands in order to
build in the b register the value 0 or 1 depending on the carry bit value.
Return Value
carry returns 0 or 1 in the b register if such a value is needed.
Example
low <<= 1;
if (carry())
++high;
produces
lsl
bcc
inc
_low
L1
_high
lsl
tfr
andb
stab
_low
ccr,b
#1
_high
L1:
low <<= 1;
high = carry()
produces
Notes
carry is an inline function and then is not defined in any library. It is
therefore not possible to take its address. For more information, see
Inlining Functions in Chapter 3.
97
C Library - ceil
ceil
Description
Round to next higher integer
Syntax
#include <math.h>
double ceil(double x)
Function
ceil computes the smallest integer greater than or equal to x.
Return Value
ceil returns the smallest integer greater than or equal to x, expressed as a
double floating value.
Example
x
5.1
5.0
0.0
-5.0
-5.1
ceil(x)
6.0
5.0
0.0
-5.0
-5.0
See Also
floor
Notes
ceil is packaged in the floating point library.
98
C Library - _checksum
_checksum
Description
Verify the recorded checksum
Syntax
int _checksum()
Function
_checksum scans the descriptor built by the linker and controls at the
end that the computed 8 bit checksum is equal to the one expected. For
more information, see Checksum Computation in Chapter 6.
Return Value
_checksum returns 0 if the checksum is correct, or a value different of 0
otherwise.
Example
if (_checksum())
abort();
Notes
The descriptor is built by the linker only if the _checksum function is
called by the application, even if there are segments marked with the
-ck option.
_checksum is packaged in the integer library.
See Also
_checksumx, _checksum16, _checksum16x
NOTE
The routine provided by default does not support bank switching. Provision is made in the library source file to support bank switching if
needed. Uncomment the proper PPAGE definition and re-assemble the
file to link it with the application.
99
C Library - _checksumx
_checksumx
Description
Verify the recorded checksum
Syntax
int _checksumx()
Function
_checksumx scans the descriptor built by the linker and controls at the
end that the computed 8 bit checksum is equal to the one expected. For
more information, see Checksum Computation in Chapter 6.
Return Value
_checksumx returns 0 if the checksum is correct, or a value different of
0 otherwise.
Example
if (_checksumx())
abort();
Notes
The descriptor is built by the linker only if the _checksumx function is
called by the application, even if there are segments marked with the
-ck option.
_checksumx is packaged in the integer library.
See Also
_checksum, _checksum16, _checksum16x
NOTE
The routine provided by default does not support bank switching. Provision is made in the library source file to support bank switching if
needed. Uncomment the proper PPAGE definition and re-assemble the
file to link it with the application.
C Library - _checksum16
_checksum16
Description
Verify the recorded checksum
Syntax
int _checksum16()
Function
_checksum16 scans the descriptor built by the linker and controls at the
end that the computed 16 bit checksum is equal to the one expected. For
more information, see Checksum Computation in Chapter 6.
Return Value
_checksum16 returns 0 if the checksum is correct, or a value different of
0 otherwise.
Example
if (_checksum16())
abort();
Notes
The descriptor is built by the linker only if the _checksum16 function is
called by the application, even if there are segments marked with the
-ck option.
_checksum16 is packaged in the integer library.
See Also
_checksum, _checksumx, _checksum16x
NOTE
The routine provided by default does not support bank switching. Provision is made in the library source file to support bank switching if
needed. Uncomment the proper PPAGE definition and re-assemble the
file to link it with the application.
C Library - _checksum16x
_checksum16x
Description
Verify the recorded checksum
Syntax
int _checksum16x()
Function
_checksum16x scans the descriptor built by the linker and controls at
the end that the computed 16 bit checksum is equal to the one expected.
For more information, see Checksum Computation in Chapter 6.
Return Value
_checksum16x returns 0 if the checksum is correct, or a value different
of 0 otherwise.
Example
if (_checksum16x())
abort();
Notes
The descriptor is built by the linker only if the _checksum16x function
is called by the application, even if there are segments marked with the
-ck option.
_checksum16x is packaged in the integer library.
See Also
_checksum, _checksumx, _checksum16
NOTE
The routine provided by default does not support bank switching. Provision is made in the library source file to support bank switching if
needed. Uncomment the proper PPAGE definition and re-assemble the
file to link it with the application.
C Library - cos
cos
Description
Cosine
Syntax
#include <math.h>
double cos(double x)
Function
cos computes the cosine of x, expressed in radians, to full double precision. If the magnitude of x is too large to contain a fractional quadrant
part, the value of cos is 1.
Return Value
cos returns the nearest internal representation to cos(x) in the range
[0, pi], expressed as a double floating value. A large argument may
return a meaningless value.
Example
To rotate a vector through the angle theta:
xnew = xold * cos(theta) - yold * sin(theta);
ynew = xold * sin(theta) + yold * cos(theta);
See Also
sin, tan
Notes
cos is packaged in the floating point library.
C Library - cosh
cosh
Description
Hyperbolic cosine
Syntax
#include <math.h>
double cosh(double x)
Function
cosh computes the hyperbolic cosine of x to full double precision.
Return Value
cosh returns the nearest internal representation to cosh(x) expressed as a
double floating value. If the result is too large to be properly represented, cosh returns zero.
Example
To use the Moivre's theorem to compute (cosh x + sinh x) to the nth
power:
demoivre = cosh(n * x) + sinh(n * x);
See Also
exp, sinh, tanh
Notes
cosh is packaged in the floating point library.
C Library - div
div
Description
Divide with quotient and remainder
Syntax
#include <stdlib.h>
div_t div(int numer, int denom)
Function
div divides the integer numer by the integer denom and returns the quotient and the remainder in a structure of type div_t. The field quot contains the quotient and the field rem contains the remainder.
Return Value
div returns a structure of type div_t containing both quotient and
remainder.
Example
To get minutes and seconds from a delay in seconds:
div_t result;
result = div(time, 60);
min = result.quot;
sec = result.rem;
See Also
ldiv
Notes
div is packaged in the integer library.
C Library - eepcpy
eepcpy
Description
Copy a buffer to an eeprom buffer
Syntax
#include <string.h>
void *eepcpy(void *s1, void *s2, unsigned int n)
Function
eepcpy copies the first n characters starting at location s2 into the eeprom buffer beginning at s1.
Return Value
eepcpy returns s1.
Example
To place first string, second string in eepbuf[]:
eepcpy(eepbuf, first string, 12);
eepcpy(eepbuf + 13, , second string, 15);
See Also
eepset, eepera
Notes
eepcpy is packaged in the integer library.
C Library - eepera
eepera
Description
Erase the full eeprom space
Syntax
void eepera(void)
Function
eepera erases the full eeprom space with the global erase sequence. It
does not erase the config register.
Return Value
Nothing.
Example
To erase the full eeprom space:
eepera();
See Also
eepset, eepcpy
Notes
eepera is packaged in the machine library.
C Library - eepset
eepset
Description
Propagate fill character throughout eeprom buffer
Syntax
#include <string.h>
void *eepset(void *s, int c, unsigned int n)
Function
eepset floods the n character buffer starting at eeprom location s with
fill character c. The function waits for all bytes to be programmed.
Return Value
eepset returns s.
Example
To flood a 512 byte eeprom buffer with NULs:
eepset(eepbuf, \0, BUFSIZ);
See Also
eepcpy, eepera
Notes
eepset is packaged in the integer library.
C Library - exit
exit
Description
Exit program execution
Syntax
#include <stdlib.h>
void exit(int status)
Function
exit stops the execution of a program by switching to the startup module just after the call to the main function. The status argument is not
used by the current implementation.
Return Value
exit never returns.
Example
To exit in case of error:
if (fatal_error)
exit();
See Also
abort
Notes
exit is in the startup module.
C Library - exp
exp
Description
Exponential
Syntax
#include <math.h>
double exp(double x)
Function
exp computes the exponential of x to full double precision.
Return Value
exp returns the nearest internal representation to exp x, expressed as a
double floating value. If the result is too large to be properly represented, exp returns zero.
Example
To compute the hyperbolic sine of x:
sinh = (exp(x) - exp(-x)) / 2.0;
See Also
log
Notes
exp is packaged in the floating point library.
C Library - fabs
fabs
Description
Find double absolute value
Syntax
#include <math.h>
double fabs(double x)
Function
fabs obtains the absolute value of x.
Return Value
fabs returns the absolute value of x, expressed as a double floating
value.
Example
x
5.0
0.0
-3.7
fabs(x)
5.0
0.0
3.7
See Also
abs, labs
Notes
fabs is packaged in the floating point library.
C Library - _fctcpy
_fctcpy
Description
Copy a moveable code segment in RAM
Syntax
int _fctcpy(char name);
Function
_fctcpy copies a moveable code segment in RAM from its storage location in ROM. _fctcpy scans the descriptor built by the linker and looks
for a moveable segment whose flag byte matches the given argument. If
such a segment is found, it is entirely copied in RAM. Any function
defined in that segment may then be called directly. For more information, see Moveable Code in Chapter 6.
Return Value
_fctcpy returns a non zero value if a segment has been found and copied. It returns 0 otherwise.
Example
if (_fctcpy(b))
flash();
Notes
_fctcpy is packaged in the integer library.
C Library - floor
floor
Description
Round to next lower integer
Syntax
#include <math.h>
double floor(double x)
Function
floor computes the largest integer less than or equal to x.
Return Value
floor returns the largest integer less than or equal to x, expressed as a
double floating value.
Example
x
5.1
5.0
0.0
-5.0
-5.1
floor(x)
5.0
5.0
0.0
-5.0
-6.0
See Also
ceil
Notes
floor is packaged in the floating point library.
C Library - fmod
fmod
Description
Find double modulus
Syntax
#include <math.h>
double fmod(double x, double y)
Function
fmod computes the floating point remainder of x / y, to full double precision. The return value of f is determined using the formula:
f=x-i*y
where i is some integer, f is the same sign as x, and the absolute value of
f is less than the absolute value of y.
Return Value
fmod returns the value of f expressed as a double floating value. If y is
zero, fmod returns zero.
Example
x
5.5
5.0
0.0
-5.5
y
5.0
5.0
0.0
5.0
fmod(x, y)
0.5
0.0
0.0
-0.5
Notes
fmod is packaged in the floating point library.
C Library - free
free
Description
Free space on the heap
Syntax
#include <stdlib.h>
void free(void *ptr)
Function
free returns an allocated cell to the heap for subsequence reuse. The cell
pointer ptr must have been obtained by an earlier calloc, malloc, or
realloc call; otherwise the heap will become corrupted. free does its
best to check for invalid values of ptr. A NULL value for ptr is explicitly allowed, however, and is ignored.
Return Value
Nothing.
Example
To give back an allocated area:
free(pd);
See Also
calloc, malloc, realloc
Notes
No effort is made to lower the system break when storage is freed, so it
is quite possible that earlier activity on the heap may cause problems
later on the stack.
free is packaged in the integer library.
C Library - frexp
frexp
Description
Extract fraction from exponent part
Syntax
#include <math.h>
double frexp(double val, int *exp)
Function
frexp partitions the double at val, which should be non-zero, into a fraction in the interval [1/2, 1) times two raised to an integer power. It then
delivers the integer power to *exp, and returns the fractional portion as
the value of the function. The exponent is generally meaningless if val
is zero.
Return Value
frexp returns the power of two fraction of the double at val as the return
value of the function, and writes the exponent at *exp.
Example
To implement the sqrt(x) function:
double sqrt(double x)
{
extern double newton(double);
int n;
x = frexp(x, &n);
x = newton(x);
if (n & 1)
x *= SQRT2;
return (ldexp(x, n / 2));
}
See Also
ldexp
Notes
frexp is packaged in the floating point library.
C Library - getchar
getchar
Description
Get character from input stream
Syntax
#include <stdio.h>
int getchar(void)
Function
getchar obtains the next input character, if any, from the user supplied
input stream. This user must rewrite this function in C or in assembly
language to provide an interface to the input mechanism of the C
library.
Return Value
getchar returns the next character from the input stream. If end of file
(break) is encountered, or a read error occurs, getchar returns EOF.
Example
To copy characters from the input stream to the output stream:
while ((c = getchar()) != EOF)
putchar(c);
See Also
putchar
Notes
getchar is packaged in the integer library.
C Library - gets
gets
Description
Get a text line from input stream
Syntax
#include <stdio.h>
char *gets(char *s)
Function
gets copies characters from the input stream to the buffer starting at s.
Characters are copied until a newline is reached or end of file is
reached. If a newline is reached, it is discarded and a NUL is written
immediately following the last character read into s.
gets uses getchar to read each character.
Return Value
gets returns s if successful. If end of file is reached, gets returns NULL.
If a read error occurs, the array contents are indeterminate and gets
returns NULL.
Example
To copy input to output, line by line:
while (puts(gets(buf)))
;
See Also
puts
Notes
There is no assured limit on the size of the line read by gets.
gets is packaged in the integer library.
C Library - isalnum
isalnum
Description
Test for alphabetic or numeric character
Syntax
#include <ctype.h>
int isalnum(int c)
Function
isalnum tests whether c is an alphabetic character (either upper or
lower case), or a decimal digit.
Return Value
isalnum returns nonzero if the argument is an alphabetic or numeric
character; otherwise the value returned is zero.
Example
To test for a valid C identifier:
if (isalpha(*s) || *s == '_')
for (++s; isalnum(*s) || *s == '_'; ++s)
;
See Also
isalpha, isdigit, islower, isupper, isxdigit, tolower, toupper
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isalnum is packaged in the integer library.
C Library - isalpha
isalpha
Description
Test for alphabetic character
Syntax
#include <ctype.h>
int isalpha(int c)
Function
isalpha tests whether c is an alphabetic character, either upper or lower
case.
Return Value
isalpha returns nonzero if the argument is an alphabetic character. Otherwise the value returned is zero.
Example
To find the end points of an alphabetic string:
while (*first && !isalpha(*first))
++first;
for (last = first; isalpha(*last); ++last)
;
See Also
isalnum, isdigit, islower, isupper, isxdigit, tolower, toupper
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isalpha is packaged in the integer library.
C Library - iscntrl
iscntrl
Description
Test for control character
Syntax
#include <ctype.h>
int iscntrl(int c)
Function
iscntrl tests whether c is a delete character (0177 in ASCII), or an ordinary control character (less than 040 in ASCII).
Return Value
iscntrl returns nonzero if c is a control character; otherwise the value is
zero.
Example
To map control characters to percent signs:
for (; *s; ++s)
if (iscntrl(*s))
*s = '%';
See Also
isgraph, isprint, ispunct, isspace
Notes
If the argument is outside the range [-1, 255], the result is undefined.
iscntrl is packaged in the integer library.
C Library - isdigit
isdigit
Description
Test for digit
Syntax
#include <ctype.h>
int isdigit(int c)
Function
isdigit tests whether c is a decimal digit.
Return Value
isdigit returns nonzero if c is a decimal digit; otherwise the value
returned is zero.
Example
To convert a decimal digit string to a number:
for (sum = 0; isdigit(*s); ++s)
sum = sum * 10 + *s - '0';
See Also
isalnum, isalpha, islower, isupper, isxdigit, tolower, toupper
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isdigit is packaged in the integer library.
C Library - isgraph
isgraph
Description
Test for graphic character
Syntax
#include <ctype.h>
int isgraph(int c)
Function
isgraph tests whether c is a graphic character; i.e. any printing character except a space (040 in ASCII).
Return Value
isgraph returns nonzero if c is a graphic character. Otherwise the value
returned is zero.
Example
To output only graphic characters:
for (; *s; ++s)
if (isgraph(*s))
putchar(*s);
See Also
iscntrl, isprint, ispunct, isspace
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isgraph is packaged in the integer library.
C Library - islower
islower
Description
Test for lower-case character
Syntax
#include <ctype.h>
int islower(int c)
Function
islower tests whether c is a lower-case alphabetic character.
Return Value
islower returns nonzero if c is a lower-case character; otherwise the
value returned is zero.
Example
To convert to upper-case:
if (islower(c))
c += 'A' - 'a';
See Also
isalnum, isalpha, isdigit, isupper, isxdigit, tolower, toupper
Notes
If the argument is outside the range [-1, 255], the result is undefined.
islower is packaged in the integer library.
C Library - isprint
isprint
Description
Test for printing character
Syntax
#include <ctype.h>
int isprint(int c)
Function
isprint tests whether c is any printing character. Printing characters are
all characters between a space (040 in ASCII) and a tilde ~ character
(0176 in ASCII).
Return Value
isprint returns nonzero if c is a printing character; otherwise the value
returned is zero.
Example
To output only printable characters:
for (; *s; ++s)
if (isprint(*s))
putchar(*s);
See Also
iscntrl, isgraph, ispunct, isspace
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isprint is packaged in the integer library.
C Library - ispunct
ispunct
Description
Test for punctuation character
Syntax
#include <ctype.h>
int ispunct(int c)
Function
ispunct tests whether c is a punctuation character. Punctuation characters include any printing character except space, a digit, or a letter.
Return Value
ispunct returns nonzero if c is a punctuation character; otherwise the
value returned is zero.
Example
To collect all punctuation characters in a string into a buffer:
for (i = 0; *s; ++s)
if (ispunct(*s))
buf[i++] = *s;
See Also
iscntrl, isgraph, isprint, isspace
Notes
If the argument is outside the range [-1, 255], the result is undefined.
ispunct is packaged in the integer library.
C Library - isqrt
isqrt
Description
Integer square root
Syntax
#include <stdlib.h>
unsigned int isqrt(unsigned int i)
Function
isqrt obtains the integral square root of the unsigned int i.
Return Value
isqrt returns the closest integer smaller or equal to the square root of i,
expressed as an unsigned int.
Example
To use isqrt to check whether n > 2 is a prime number:
if (!(n & 01))
return (NOTPRIME);
sq = isqrt(n);
for (div = 3; div <= sq; div += 2)
if (!(n % div))
return (NOTPRIME);
return (PRIME);
See Also
lsqrt, sqrt
Notes
isqrt is packaged in the integer library.
C Library - isspace
isspace
Description
Test for whitespace character
Syntax
#include <ctype.h>
int isspace(int c)
Function
isspace tests whether c is a whitespace character. Whitespace characters
are horizontal tab (\t), newline (\n), vertical tab (\v), form feed
(\f), carriage return (\r), and space ( ).
Return Value
isspace returns nonzero if c is a whitespace character; otherwise the
value returned is zero.
Example
To skip leading whitespace:
while (isspace(*s))
++s;
See Also
iscntrl, isgraph, isprint, ispunct
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isspace is packaged in the integer library.
C Library - isupper
isupper
Description
Test for upper-case character
Syntax
/* no header file need be included */
int isupper(int c)
Function
isupper tests whether c is an upper-case alphabetic character.
Return Value
isupper returns nonzero if c is an upper-case character; otherwise the
value returned is zero.
Example
To convert to lower-case:
if (isupper(c))
c += 'a' - 'A'; /* also see tolower() */
See Also
isalnum, isalpha, isdigit, islower, isxdigit, tolower, toupper
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isupper is packaged in the integer library.
C Library - isxdigit
isxdigit
Description
Test for hexadecimal digit
Syntax
#include <ctype.h>
int isxdigit(int c)
Function
isxdigit tests whether c is a hexadecimal digit, i.e. in the set
[0123456789abcdefABCDEF].
Return Value
isxdigit returns nonzero if c is a hexadecimal digit; otherwise the value
returned is zero.
Example
To accumulate a hexadecimal digit:
for (sum = 0; isxdigit(*s); ++s)
if (isdigit(*s)
sum = sum * 10 + *s - '0';
else
sum = sum * 10 + tolower(*s) + (10 - 'a');
See Also
isalnum, isalpha, isdigit, islower, isupper, tolower, toupper
Notes
If the argument is outside the range [-1, 255], the result is undefined.
isxdigit is packaged in the integer library.
C Library - labs
labs
Description
Find long absolute value
Syntax
#include <stdlib.h>
long labs(long l)
Function
labs obtains the absolute value of l. No check is made to see that the
result can be properly represented.
Return Value
labs returns the absolute value of l, expressed as an long int.
Example
To print out a debit or credit balance:
printf(balance %ld%s\n,labs(bal),(bal < 0) ? CR : );
See Also
abs, fabs
Notes
labs is packaged in the integer library.
C Library - ldexp
ldexp
Description
Scale double exponent
Syntax
#include <math.h>
double ldexp(double x, int exp)
Function
ldexp multiplies the double x by two raised to the integer power exp.
Return Value
ldexp returns the double result x * (1 << exp) expressed as a double
floating value. If a range error occurs, ldexp returns HUGE_VAL.
Example
x
1.0
1.0
1.0
0.0
exp
1
0
-1
0
ldexp(x, exp)
2.0
1.0
0.5
0.0
See Also
frexp, modf
Notes
ldexp is packaged in the floating point library.
C Library - ldiv
ldiv
Description
Long divide with quotient and remainder
Syntax
#include <stdlib.h>
ldiv_t ldiv(long numer, long denom)
Function
ldiv divides the long integer numer by the long integer denom and
returns the quotient and the remainder in a structure of type ldiv_t. The
field quot contains the quotient and the field rem contains the remainder.
Return Value
ldiv returns a structure of type ldiv_t containing both quotient and
remainder.
Example
To get minutes and seconds from a delay in seconds:
ldiv_t result;
result = ldiv(time, 60L);
min = result.quot;
sec = result.rem;
See Also
div
Notes
ldiv is packaged in the integer library.
C Library - log
log
Description
Natural logarithm
Syntax
#include <math.h>
double log(double x)
Function
log computes the natural logarithm of x to full double precision.
Return Value
log returns the closest internal representation to log(x), expressed as a
double floating value. If the input argument is less than zero, or is too
large to be represented, log returns zero.
Example
To compute the hyperbolic arccosine of x:
arccosh = log(x + sqrt(x * x - 1));
See Also
exp
Notes
log is packaged in the floating point library.
C Library - log10
log10
Description
Common logarithm
Syntax
#include <math.h>
double log10(double x)
Function
log10 computes the common log of x to full double precision by computing the natural log of x divided by the natural log of 10. If the input
argument is less than zero, a domain error will occur. If the input argument is zero, a range error will occur.
Return Value
log10 returns the nearest internal representation to log10 x, expressed as
a double floating value. If the input argument is less than or equal to
zero, log10 returns zero.
Example
To determine the number of digits in x, where x is a positive integer
expressed as a double:
ndig = log10(x) + 1;
See Also
log
Notes
log10 is packaged in the floating point library.
C Library - longjmp
longjmp
Description
Restore calling environment
Syntax
#include <setjmp.h>
void longjmp(jmp_buf env, int val)
Function
longjmp restores the environment saved in env by setjmp. If env has not
been set by a call to setjmp, or if the caller has returned in the meantime, the resulting behavior is unpredictable.
All accessible objects have their values restored when longjmp is
called, except for objects of storage class register, the values of which
have been changed between the setjmp and longjmp calls.
Return Value
When longjmp returns, program execution continues as if the corresponding call to setjmp had returned the value val. longjmp cannot force
setjmp to return the value zero. If val is zero, setjmp returns the value
one.
Example
You can write a generic error handler as:
void handle(int err)
{
extern jmp_buf env;
longjmp(env, err); /* return from setjmp */
}
See Also
setjmp
Notes
longjmp is packaged in the integer library.
C Library - lsqrt
lsqrt
Description
Long integer square root
Syntax
#include <stdlib.h>
unsigned int lsqrt(unsigned long l)
Function
lsqrt obtains the integral square root of the unsigned long l.
Return Value
lsqrt returns the closest integer smaller or equal to the square root of l,
expressed as an unsigned int.
Example
To use lsqrt to check whether n > 2 is a prime number:
if (!(n & 01))
return (NOTPRIME);
sq = lsqrt(n);
for (div = 3; div <= sq; div += 2)
if (!(n % div))
return (NOTPRIME);
return (PRIME);
See Also
isqrt, sqrt
Notes
lsqrt is packaged in the integer library.
C Library - malloc
malloc
Description
Allocate space on the heap
Syntax
#include <stdlib.h>
void *malloc(unsigned int nbytes)
Function
malloc allocates space on the heap for an item of size nbytes. The space
allocated is guaranteed to be at least nbytes long, starting from the
pointer returned, which is guaranteed to be on a proper storage boundary for an object of any type. The heap is grown as necessary. If space is
exhausted, malloc returns a null pointer.
Return Value
malloc returns a pointer to the start of the allocated cell if successful;
otherwise it returns NULL. The pointer returned may be assigned to an
object of any type without casting.
Example
To allocate an array of ten doubles:
double *pd;
pd = malloc(10 * sizeof *pd);
See Also
calloc, free, realloc
Notes
malloc is packaged in the integer library.
C Library - max
max
Description
Test for maximum
Syntax
#include <stdlib.h>
max(a,b)
Function
max obtains the maximum of its two arguments, a and b. Since max is
implemented as a builtin function, its arguments can be any numerical
type, and type coercion occurs automatically.
Return Value
max is a numerical rvalue of the form ((a < b) ? b : a), suitably parenthesized.
Example
To set a new maximum level:
hiwater = max(hiwater, level);
See Also
min
Notes
max is an extension to the proposed ANSI C standard.
max is a builtin declared in the <stdlib.h> header file. You can use it by
including <stdlib.h> with your program. Because it is a builtin, max
cannot be called from non-C programs, nor can its address be taken.
C Library - memchr
memchr
Description
Scan buffer for character
Syntax
#include <string.h>
void *memchr(void *s, int c, unsigned int n)
Function
memchr looks for the first occurrence of a specific character c in an n
character buffer starting at s.
Return Value
memchr returns a pointer to the first character that matches c, or NULL
if no character matches.
Example
To map keybuf[]characters into subst[] characters:
if ((t = memchr(keybuf, *s, KEYSIZ)) != NULL)
*s = subst[t - keybuf];
See Also
strchr, strcspn, strpbrk, strrchr, strspn
Notes
memchr is packaged in the integer library.
C Library - memcmp
memcmp
Description
Compare two buffers for lexical order
Syntax
#include <string.h>
int memcmp(void *s1, void *s2, unsigned int n)
Function
memcmp compares two text buffers, character by character, for lexical
order in the character collating sequence. The first buffer starts at s1,
the second at s2; both buffers are n characters long.
Return Value
memcmp returns a short integer greater than, equal to, or less than zero,
according to whether s1 is lexicographically greater than, equal to, or
less than s2.
Example
To look for the string include in name:
if (memcmp(name, "include", 7) == 0)
doinclude();
See Also
strcmp, strncmp
Notes
memcmp is packaged in the integer library.
C Library - memcpy
memcpy
Description
Copy one buffer to another
Syntax
#include <string.h>
void *memcpy(void *s1, void *s2, unsigned int n)
Function
memcpy copies the first n characters starting at location s2 into the
buffer beginning at s1.
Return Value
memcpy returns s1.
Example
To place first string, second string in buf[]:
memcpy(buf, first string, 12);
memcpy(buf + 13, ", second string, 15);
See Also
strcpy, strncpy
Notes
memcpy is implemented as a builtin function.
C Library - memhc12
memhc12
Description
Fuzzify an input
Syntax
#include <fuzzy.h>
void memhc12(char crisp, char *t_shape,
char *t_result, int nba)
Function
memchc12 evaluates the grade of membership of all the adjectives
associated to an input. Each adjective is described by a shape and an
output byte. The input value is specified by the crisp argument, and is
followed by a pointer t_shape to an array of shapes (four bytes each),
and a pointer t_result to an array of output addresses. The last argument nba specifies the number of output to evaluate.
Return Value
memhc12 sets the content of the array of nba bytes specified by t_shape
to the grade of membership of the input crisp according to an array of
shapes specified by t_result.
Example
memhc12(val, tabsh, tabptr, 4);
See Also
revhc12, revwhc12, wavhc12
C Library - memmove
memmove
Description
Copy one buffer to another
Syntax
#include <string.h>
void *memmove(void *s1, void *s2, unsigned int n)
Function
memmove copies the first n characters starting at location s2 into the
buffer beginning at s1. If the two buffers overlap, the function performs
the copy in the appropriate sequence, so the copy is not corrupted.
Return Value
memmove returns s1.
Example
To shift an array of characters:
memmove(buf, &buf[5], 10);
See Also
memcpy
Notes
memmove is packaged in the integer library.
C Library - memset
memset
Description
Propagate fill character throughout buffer
Syntax
#include <string.h>
void *memset(void *s, int c, unsigned int n)
Function
memset floods the n character buffer starting at s with fill character c.
Return Value
memset returns s.
Example
To flood a 512-byte buffer with NULs:
memset(buf,'\0', BUFSIZ);
Notes
memset is packaged in the integer library.
C Library - min
min
Description
Test for minimum
Syntax
#include <stdlib.h>
min(a,b)
Function
min obtains the minimum of its two arguments, a and b. Since min is
implemented as a builtin function, its arguments can be any numerical
type, and type coercion occurs automatically.
Return Value
min is a numerical rvalue of the form ((a < b) ? a : b), suitably parenthesized.
Example
To set a new minimum level:
nmove = min(space, size);
See Also
max
Notes
min is an extension to the ANSI C standard.
min is a builtin declared in the <stdlib.h> header file. You can use it by
including <stdlib.h> with your program. Because it is a builtin, min
cannot be called from non-C programs, nor can its address be taken.
C Library - modf
modf
Description
Extract fraction and integer from double
Syntax
#include <math.h>
double modf(double val, double *pd)
Function
modf partitions the double val into an integer portion, which is delivered to *pd, and a fractional portion, which is returned as the value of
the function. If the integer portion cannot be represented properly in an
int, the result is truncated on the left without complaint.
Return Value
modf returns the signed fractional portion of val as a double floating
value, and writes the integer portion at *pd.
Example
val
*pd
5.1
5.0
4.9
0.0
-1.4
5
5
4
0
-1
modf(val, *pd)
0.1
0.0
0.9
0.0
-0.4
See Also
frexp, ldexp
Notes
modf is packaged in the floating point library.
C Library - overflow
overflow
Description
Test or get the carry bit
Syntax
#include <processor.h>
@inline char carry(void)
Function
overflow is an inline function allowing to test or get the value of the
overflow bit. When used in an if construct, this function expands
directly to a bvc or bvs instruction. When used in an expression, it
expands in order to build in the b register the value 0 or 1 depending on
the overflow bit value.
Return Value
overflow returns 0 or 1 in the b register if such a value is needed.
Example
low <<= 1;
if (overflow())
++high;
produces
lsl
bvc
inc
_low
L1
_high
lsl
tfr
andb
lsrb
stab
_low
ccr,b
#2
L1:
low <<= 1;
high = overflow()
produces
_high
Notes
overflow is an inline function and then is not defined in any library. It is
therefore not possible to take its address. For more information, see
Inlining Functions in Chapter 3.
C Library - pow
pow
Description
Raise x to the y power
Syntax
#include <math.h>
double pow(double x, double y)
Function
pow computes the value of x raised to the power of y.
Return Value
pow returns the value of x raised to the power of y, expressed as a double floating value. If x is zero and y is less than or equal to zero, or if x is
negative and y is not an integer, pow returns zero.
Example
x
2.0
2.0
2.0
1.0
0.0
-1.0
-1.0
y
2.0
1.0
0.0
any
-2.0
2.0
2.1
pow(x, y)
4.0
2.0
1.0
1.0
0
1.0
0
See Also
exp
Notes
pow is packaged in the floating point library.
C Library - printf
printf
Description
Output formatted arguments to stdout
Syntax
#include <stdio.h>
int printf(char *fmt,...)
Function
printf writes formatted output to the output stream using the format
string at fmt and the arguments specified by ..., as described below.
printf uses putchar to output each character.
Format Specifiers
The format string at fmt consists of literal text to be output, interspersed
with conversion specifications that determine how the arguments are to
be interpreted and how they are to be converted for output. If there are
insufficient arguments for the format, the results are undefined. If the
format is exhausted while arguments remain, the excess arguments are
evaluated but otherwise ignored. printf returns when the end of the format string is encountered.
Each <conversion specification> is started by the character %. After
the %, the following appear in sequence:
<field width> - a decimal number which optionally specifies a minimum field width. If the converted value has fewer characters than the
field width, it is padded on the left (or right, if the left adjustment flag
has been given) to the field width. The padding is with spaces unless the
field width digit string starts with zero, in which case the padding is
with zeros.
C Library - printf
space - a space will be prepended if the first character of a signed conversion is not a sign. This flag will be ignored if space and + flags are
both specified.
2004 COSMIC Software
C Library - printf
C Library - printf
C Library - printf
Return Value
printf returns the number of characters transmitted, or a negative
number if a write error occurs.
Notes
A call with more conversion specifiers than argument variables will
cause unpredictable results.
Example
To print arg, which is a double with the value 5100.53:
printf(%8.2f\n, arg);
printf(%*.*f\n, 8, 2, arg);
See Also
sprintf
Notes
printf is packaged in both the integer library and the floating point
library. The functionality of the integer only version of printf is a subset
of the functionality of the floating point version. The integer only version cannot print or manipulate floating point numbers. If your programs call the integer only version of printf, the following conversion
specifiers are invalid: e, E, f, g and G. The L modifier is also invalid.
If printf encounters an invalid conversion specifier, the invalid specifier
is ignored and no special message is generated.
C Library - putchar
putchar
Description
Put a character to output stream
Syntax
#include <stdio.h>
int putchar(c)
Function
putchar copies c to the user specified output stream.
You must rewrite putchar in either C or assembly language to provide
an interface to the output mechanism to the C library.
Return Value
putchar returns c. If a write error occurs, putchar returns EOF.
Example
To copy input to output:
while ((c = getchar()) != EOF)
putchar(c);
See Also
getchar
Notes
putchar is packaged in the integer library.
C Library - puts
puts
Description
Put a text line to output stream
Syntax
#include <stdio.h>
int puts(char *s)
Function
puts copies characters from the buffer starting at s to the output stream
and appends a newline character to the output stream.
puts uses putchar to output each character. The terminating NUL is not
copied.
Return Value
puts returns zero if successful, or else nonzero if a write error occurs.
Example
To copy input to output, line by line:
while (puts(gets(buf)))
;
See Also
gets
Notes
puts is packaged in the integer library.
C Library - rand
rand
Description
Generate pseudo-random number
Syntax
#include <stdlib.h>
int rand(void)
Function
rand computes successive pseudo-random integers in the range
[0, 32767], using a linear multiplicative algorithm which has a period of
2 raised to the power of 32.
Example
int dice()
{
return (rand() % 6 + 1);
}
Return Value
rand returns a pseudo-random integer.
See Also
srand
Notes
rand is packaged in the integer library.
C Library - realloc
realloc
Description
Reallocate space on the heap
Syntax
#include <stdlib.h>
void *realloc(void *ptr, unsigned int nbytes)
Function
realloc grows or shrinks the size of the cell pointed to by ptr to the size
specified by nbytes. The contents of the cell will be unchanged up to the
lesser of the new and old sizes. The cell pointer ptr must have been
obtained by an earlier calloc, malloc, or realloc call; otherwise the heap
will become corrupted.
Return Value
realloc returns a pointer to the start of the possibly moved cell if successful. Otherwise realloc returns NULL and the cell and ptr are
unchanged. The pointer returned may be assigned to an object of any
type without casting.
Example
To adjust p to be n doubles in size:
p = realloc(p, n * sizeof(double));
See Also
calloc, free, malloc
Notes
realloc is packaged in the integer library.
C Library - revhc12
revhc12
Description
Evaluate fuzzy outputs
Syntax
#include <fuzzy.h>
void revhc12(char *rules, char *in_out)
Function
revhc12 evaluates fuzzy outputs based on evaluation rules which are
specified by the pointer rules. The base address of input and output
bytes is specified by the pointer in_out. Refer to the HC12/HCS12
Reference Manual, for a complete description of the rules encoding.
Return Value
revhc12 sets the output bytes to the result values according to the evaluation rules.
Example
revhc12(rules, base);
See Also
memhc12, revwhc12, wavhc12
Notes
revhc12 is a builtin function declared in the <fuzzy.h> header file.
C Library - revwhc12
revwhc12
Description
Evaluate fuzzy outputs
Syntax
#include <fuzzy.h>
void revwhc12(unsigned int *rules, char *weight)
Function
revwhc12 evaluates fuzzy outputs based on evaluation rules which are
specified by the pointer rules. If the weight pointer is provided, it
should point to an array of byte weights used to ponderate the evaluation. Otherwise weight has to be specified has the NULL pointer. Refer
to the HC12/HCS12 Reference Manual, for a complete description of
the rules encoding.
Return Value
revwhc12 sets the output bytes to the result values according to the
evaluation rules.
Example
revwhc12(rules, NULL);
See Also
memhc12, revhc12, wavhc12
Notes
revwhc12 is a builtin function declared in the <fuzzy.h> header file.
C Library - sbreak
sbreak
Description
Allocate new memory
Syntax
/* no header file need be included */
void *sbreak(unsigned int size)
Function
sbreak modifies the program memory allocation as necessary, to make
available at least size contiguous bytes of new memory, on a storage
boundary adequate for representing any type of data. There is no guarantee that successive calls to sbreak will deliver contiguous areas of
memory.
Return Value
sbreak returns a pointer to the start of the new memory if successful;
otherwise the value returned is NULL.
Example
To buy space for an array of symbols:
if (!(p = sbreak(nsyms * sizeof (symbol))))
remark(not enough memory!, NULL);
Notes
sbreak is packaged in the integer library.
sbreak is an extension to the ANSI C standard.
C Library - scanf
scanf
Description
Read formatted input
Syntax
#include <stdio.h>
int scanf(char *fmt,...)
Function
scanf reads formatted input from the output stream using the format
string at fmt and the arguments specified by ..., as described below.
scanf uses getchar to read each character.
The behavior is unpredictable if there are insufficient argument pointers
for the format. If the format string is exhausted while arguments
remain, the excess arguments are evaluated but otherwise ignored.
Format Specifiers
The format string may contain:
Each <conversion specification>, the definition of which follows, consists of the character %, an optional assignment-suppressing character
*, an optional maximum field width, an optional h, l or L indicating
the size of the receiving object, and a <conversion character>,
described below.
A conversion specification directs the conversion of the next input
field. The result is placed in the object pointed to by the subsequent
argument, unless assignment suppression was indicated by a *. An
C Library - scanf
input field is a string of non-space characters; it extends to the next conflicting character or until the field width, if specified, is exhausted.
The conversion specification indicates the interpretation of the input
field; the corresponding pointer argument must be a restricted type. The
<conversion character> is one of the following:
C Library - scanf
C Library - scanf
Return Value
scanf returns the number of assigned input items, which can be zero if
there is an early conflict between an input character and the format, or
EOF if end of file is encountered before the first conflict or conversion.
Example
To be certain of a dubious request:
printf(are you sure?);
if (scanf(%c, &ans) && (ans == 'Y' || ans == 'y'))
scrog();
See Also
sscanf
Notes
scanf is packaged in both the integer library and the floating point
library. The functionality of the integer only version of scanf is a subset
of the functionality of the floating point version. The integer only version cannot read or manipulate floating point numbers. If your programs call the integer only version of scanf, the following conversion
specifiers are invalid: e, f, g and p. The L flag is also invalid.
If an invalid conversion specifier is encountered, it is ignored.
C Library - setjmp
setjmp
Description
Save calling environment
Syntax
#include <setjmp.h>
int setjmp(jmp_buf env)
Function
setjmp saves the calling environment in env for later use by the
longjmp function.
Since setjmp manipulates the stack, it should never be used except as
the single operand in a switch statement.
Return Value
setjmp returns zero on its initial call, or the argument to a longjmp call
that uses the same env.
Example
To call any event until it returns 0 or 1 and calls longjmp, which will
then start execution at the function event0 or event1:
static jmp_buf ev[2];
switch (setjmp(ev[0]))
{
case 0:
/* registered */
break;
default:
/* event 0 occurred */
event0();
next();
}
switch (setjmp(ev[1])
{
case 0:
/* registered */
break;
default:
/* event 1 occurred */
event1();
next();
C Library - setjmp
}
next();
...
next()
{
int i;
for (; ;)
{
i = anyevent();
if (i == 0 || i == 1)
longjmp(ev[i]);
}
}
See Also
longjmp
Notes
setjmp is packaged in the integer library.
C Library - sin
sin
Description
Sin
Syntax
#include <math.h>
double sin(double x)
Function
sin computes the sine of x, expressed in radians, to full double precision. If the magnitude of x is too large to contain a fractional quadrant
part, the value of sin is 0.
Return Value
sin returns the closest internal representation to sin(x) in the range
[-pi/2, pi/2], expressed as a double floating value. A large argument
may return a meaningless result.
Example
To rotate a vector through the angle theta:
xnew = xold * cos(theta) - yold * sin(theta);
ynew = xold * sin(theta) + yold * cos(theta);
See Also
cos, tan
Notes
sin is packaged in the floating point library.
C Library - sinh
sinh
Description
Hyperbolic sine
Syntax
#include <math.h>
double sinh(double x)
Function
sinh computes the hyperbolic sine of x to full double precision.
Return Value
sinh returns the closest internal representation to sinh(x), expressed as a
double floating value. If the result is too large to be properly represented, sinh returns zero.
Example
To obtain the hyperbolic sine of complex z:
typedef struct
{
double x, iy;
}complex;
complex z;
z.x = sinh(z.x) * cos(z.iy);
z.iy = cosh(z.x) * sin(z.iy);
See Also
cosh, exp, tanh
Notes
sinh is packaged in the floating point library.
C Library - sprintf
sprintf
Description
Output arguments formatted to buffer
Syntax
#include <stdio.h>
int sprintf(char *s, char fmt,...)
Function
sprintf writes formatted to the buffer pointed at by s using the format
string at fmt and the arguments specified by ..., in exactly the same way
as printf. See the description of the printf function for information on
the format conversion specifiers. A NUL character is written after the
last character in the buffer.
Return Value
sprintf returns the numbers of characters written, not including the terminating NUL character.
Example
To format a double at d into buf:
sprintf(buf, %10f\n, d);
See Also
printf
Notes
sprintf is packaged in both the integer library and the floating point
library. The functionality of the integer only version of sprintf is a subset of the functionality of the floating point version. The integer only
version cannot print or manipulate floating point numbers. If your programs call the integer only version of sprintf, the following conversion
specifiers are invalid: e, E, f, g and G. The L flag is also invalid.
C Library - sqrt
sqrt
Description
Real square root
Syntax
#include <math.h>
double sqrt(double x)
Function
sqrt computes the square root of x to full double precision.
Return Value
sqrt returns the nearest internal representation to sqrt(x), expressed as a
double floating value. If x is negative, sqrt returns zero.
Example
To use sqrt to check whether n > 2 is a prime number:
if (!(n & 01))
return (NOTPRIME);
sq = sqrt((double)n);
for (div = 3; div <= sq; div += 2)
if (!(n % div))
return (NOTPRIME);
return (PRIME);
See Also
isqrt, lsqrt
Notes
sqrt is packaged in the floating point library.
C Library - srand
srand
Description
Seed pseudo-random number generator
Syntax
#include <stdlib.h>
void srand(unsigned char nseed)
Function
srand uses nseed as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand. If srand is called with
the same seed value, the sequence of pseudo-random numbers will be
repeated. The initial seed value used by rand and srand is 0.
Return Value
Nothing.
Example
To set up a new sequence of random numbers:
srand(103);
See Also
rand
Notes
srand is packaged in the integer library.
C Library - sscanf
sscanf
Description
Read formatted input from a string
Syntax
#include <stdio.h>
int sscanf(schar *, char *fmt,...)
Function
sscanf reads formatted input from the NUL-terminated string pointed at
by s using the format string at fmt and the arguments specified by ..., in
exactly the same way as scanf. See the description of the scanf function
for information on the format conversion specifiers.
Return Value
sscanf returns the number of assigned input items, which can be zero if
there is an early conflict between an input character and the format, or
EOF if the end of the string is encountered before the first conflict or
conversion.
See Also
scanf
Notes
sscanf is packaged in both the integer library and the floating point
library. The functionality of the integer only version of sscanf is a subset of the functionality of the floating point version. The integer only
version cannot print or manipulate floating point numbers. If your programs call the integer only version of sscanf, the following conversion
specifiers are invalid: e, f, g and p. The L flag is also invalid.
C Library - strcat
strcat
Description
Concatenate strings
Syntax
#include <string.h>
char *strcat(char *s1, char *s2)
Function
strcat appends a copy of the NUL terminated string at s2 to the end of
the NUL terminated string at s1. The first character of s2 overlaps the
NUL at the end of s1. A terminating NUL is always appended to s1.
Return Value
strcat returns s1.
Example
To place the strings first string, second string in buf[]:
buf[0] = '\0';
strcpy(buf, first string);
strcat(buf, , second string);
See Also
strncat
Notes
There is no way to specify the size of the destination area to prevent
storage overwrites.
strcat is packaged in the integer library.
C Library - strchr
strchr
Description
Scan string for first occurrence of character
Syntax
#include <string.h>
char *strchr(char *s, int c)
Function
strchr looks for the first occurrence of a specific character c in a NUL
terminated target string s.
Return Value
strchr returns a pointer to the first character that matches c, or NULL if
none does.
Example
To map keystr[] characters into subst[] characters:
if (t = strchr(keystr, *s))
*s = subst[t - keystr];
See Also
memchr, strcspn, strpbrk, strrchr, strspn
Notes
strchr is packaged in the integer library.
C Library - strcmp
strcmp
Description
Compare two strings for lexical order
Syntax
#include <string.h>
int strcmp(char *s1, char *s2)
Function
strcmp compares two text strings, character by character, for lexical
order in the character collating sequence. The first string starts at s1, the
second at s2. The strings must match, including their terminating NUL
characters, in order for them to be equal.
Return Value
strcmp returns an integer greater than, equal to, or less than zero,
according to whether s1 is lexicographically greater than, equal to, or
less than s2.
Example
To look for the string include:
if (strcmp(buf, include) == 0)
doinclude();
See Also
memcmp, strncmp
Notes
strcmp is packaged in the integer library.
C Library - strcpy
strcpy
Description
Copy one string to another
Syntax
#include <string.h>
char *strcpy(char *s1, char *s2)
Function
strcpy copies the NUL terminated string at s2 to the buffer pointed at
by s1. The terminating NUL is also copied.
Return Value
strcpy returns s1.
Example
To make a copy of the string s2 in dest:
strcpy(dest, s2);
See Also
memcpy, strncpy
Notes
There is no way to specify the size of the destination area, to prevent
storage overwrites.
strcpy is implemented as a builtin function.
C Library - strcspn
strcspn
Description
Find the end of a span of characters in a set
Syntax
#include <string.h>
unsigned int strcspn(char *s1, char *s2)
Function
strcspn scans the string starting at s1 for the first occurrence of a character in the string starting at s2. It computes a subscript i such that:
Return Value
strcspn returns the lowest possible value of i. s1[i] designates the terminating null character if none of the characters in s1 are in s2.
Example
To find the start of a decimal constant in a text string:
if (!str[i = strcspn(str, 0123456789+-)])
printf(can't find number\n);
See Also
memchr, strchr, strpbrk, strrchr, strspn
Notes
strcspn is packaged in the integer library.
C Library - strlen
strlen
Description
Find length of a string
Syntax
#include <string.h>
unsigned int strlen(char *s)
Function
strlen scans the text string starting at s to determine the number of characters before the terminating NUL.
Return Value
The value returned is the number of characters in the string before the
NUL.
Notes
strlen is packaged in the integer library.
C Library - strncat
strncat
Description
Concatenate strings of length n
Syntax
#include <string.h>
char *strncat(char *s1, char *s2, unsigned int n)
Function
strncat appends a copy of the NUL terminated string at s2 to the end of
the NUL terminated string at s1. The first character of s2 overlaps the
NUL at the end of s1. n specifies the maximum number of characters to
be copied, unless the terminating NUL in s2 is encountered first. A terminating NUL is always appended to s1.
Return Value
strncat returns s1.
Example
To concatenate the strings day and light:
strcpy(s, day);
strncat(s + 3, light, 5);
See Also
strcat
Notes
strncat is packaged in the integer library.
C Library - strncmp
strncmp
Description
Compare two n length strings for lexical order
Syntax
#include <string.h>
int strncmp(char *s1, char *s2, unsigned int n)
Function
strncmp compares two text strings, character by character, for lexical
order in the character collating sequence. The first string starts at s1, the
second at s2. n specifies the maximum number of characters to be compared, unless the terminating NUL in s1 or s2 is encountered first. The
strings must match, including their terminating NUL character, in order
for them to be equal.
Return Value
strncmp returns an integer greater than, equal to, or less than zero,
according to whether s1 is lexicographically greater than, equal to, or
less than s2.
Example
To check for a particular error message:
if (strncmp(errmsg,
can't write output file, 23) == 0)
cleanup(errmsg);
See Also
memcmp, strcmp
Notes
strncmp is packaged in the integer library.
C Library - strncpy
strncpy
Description
Copy n length string
Syntax
#include <string.h>
char *strncpy(char *s1, char *s2, unsigned int n)
Function
strncpy copies the first n characters starting at location s2 into the
buffer beginning at s1. n specifies the maximum number of characters
to be copied, unless the terminating NUL in s2 is encountered first. In
that case, additional NUL padding is appended to s2 to copy a total of n
characters.
Return Value
strncpy returns s1.
Example
To make a copy of the string s2 in dest:
strncpy(dest, s2, n);
See Also
memcpy, strcpy
Notes
If the string s2 points at is longer than n characters, the result may not
be NUL-terminated.
strncpy is packaged in the integer library.
C Library - strpbrk
strpbrk
Description
Find occurrence in string of character in set
Syntax
#include <string.h>
char *strpbrk(char *s1, char *s2)
Function
strpbrk scans the NUL terminated string starting at s1 for the first
occurrence of a character in the NUL terminated set s2.
Return Value
strpbrk returns a pointer to the first character in s1 that is also contained
in the set s2, or a NULL if none does.
Example
To replace unprintable characters (as for a 64 character terminal):
while (string = strpbrk(string, {|}~))
*string = '@';
See Also
memchr, strchr, strcspn, strrchr, strspn
Notes
strpbrk is packaged in the integer library.
C Library - strrchr
strrchr
Description
Scan string for last occurrence of character
Syntax
#include <string.h>
char *strrchr(char *s,int c)
Function
strrchr looks for the last occurrence of a specific character c in a NUL
terminated string starting at s.
Return Value
strrchr returns a pointer to the last character that matches c, or NULL if
none does.
Example
To find a filename within a directory pathname:
if (s = strrchr(/usr/lib/libc.user, '/')
++s;
See Also
memchr, strchr, strpbrk, strcspn, strspn
Notes
strrchr is packaged in the integer library.
C Library - strspn
strspn
Description
Find the end of a span of characters not in set
Syntax
#include <string.h>
unsigned int strspn(char *s1, char *s2)
Function
strspn scans the string starting at s1 for the first occurrence of a character not in the string starting at s2. It computes a subscript i such that
Return Value
strspn returns the lowest possible value of i. s1[i] designates the terminating null character if all of the characters in s1 are in s2.
Example
To check a string for characters other than decimal digits:
if (str[strspn(str, 0123456789)])
printf(invalid number\n);
See Also
memchr, strcspn, strchr, strpbrk, strrchr
Notes
strspn is packaged in the integer library.
C Library - strstr
strstr
Description
Scan string for first occurrence of string
Syntax
#include <string.h>
char *strstr(char *s1, char *s2)
Function
strstr looks for the first occurrence of a specific string s2 not including
its terminating NUL, in a NUL terminated target string s1.
Return Value
strstr returns a pointer to the first character that matches c, or NULL if
none does.
Example
To look for a keyword in a string:
if (t = strstr(buf, LIST))
do_list(t);
See Also
memchr, strcspn, strpbrk, strrchr, strspn
Notes
strstr is packaged in the integer library.
C Library - strtod
strtod
Description
Convert buffer to double
Syntax
#include <stdlib.h>
double strtod(char *nptr, char **endptr)
Function
strtod converts the string at nptr into a double. The string is taken as
the text representation of a decimal number, with an optional fraction
and exponent. Leading whitespace is skipped and an optional sign is
permitted; conversion stops on the first unrecognizable character.
Acceptable inputs match the pattern:
[+|-]d*[.d*][e[+|-]dd*]
where d is any decimal digit and e is the character e or E. If endptr is
not a null pointer, *endptr is set to the address of the first unconverted
character remaining in the string nptr. No checks are made against overflow, underflow, or invalid character strings.
Return Value
strtod returns the converted double value. If the string has no recognizable characters, it returns zero.
Example
To read a string from STDIN and convert it to a double at d:
gets(buf);
d = strtod(buf, NULL);
See Also
atoi, atol, strtol, strtoul
Notes
strtod is packaged in the floating point library.
C Library - strtol
strtol
Description
Convert buffer to long
Syntax
#include <stdlib.h>
long strtol(char *nptr, char **endptr, int base)
Function
strtol converts the string at nptr into a long integer. Leading whitespace
is skipped and an optional sign is permitted; conversion stops on the
first unrecognizable character. If base is not zero, characters a-z or A-Z
represents digits in range 10-36. If base is zero, a leading 0x or 0X
in the string indicates hexadecimal, a leading 0 indicates octal, otherwise the string is take as a decimal representation. If base is 16 and a
leading 0x or 0X is present, it is skipped before to convert. If
endptr is not a null pointer, *endptr is set to the address of the first
unconverted character in the string nptr.
No checks are made against overflow or invalid character strings.
Return Value
strtol returns the converted long integer. If the string has no recognizable characters, zero is returned.
Example
To read a string from STDIN and convert it to a long l:
gets(buf);
l = strtol(buf, NULL, 0);
See Also
atof, atoi, strtoul, strtod
Notes
strtol is packaged in the integer library.
C Library - strtoul
strtoul
Description
Convert buffer to unsigned long
Syntax
#include <stdlib.h>
unsigned long strtoul(char *nptr, char **endptr,
int base)
Function
strtoul converts the string at nptr into a long integer. Leading
whitespace is skipped and an optional sign is permitted; conversion
stops on the first unrecognizable character. If base is not zero, characters a-z or A-Z represents digits in range 10-36. If base is zero, a leading 0x or 0X in the string indicates hexadecimal, a leading 0
indicates octal, otherwise the string is take as a decimal representation.
If base is 16 and a leading 0x or 0X is present, it is skipped before
to convert. If endptr is not a null pointer, *endptr is set to the address of
the first unconverted character in the string nptr.
No checks are made against overflow or invalid character strings.
Return Value
strtoul returns the converted long integer. If the string has no recognizable characters, zero is returned.
Example
To read a string from STDIN and convert it to a long l:
gets(buf);
l = strtoul(buf, NULL, 0);
See Also
atof, atoi, strtol, strtod
Notes
strtoul is a macro redefined to strtol.
C Library - tan
tan
Description
Tangent
Syntax
#include <math.h>
double tan(double x)
Function
tan computes the tangent of x, expressed in radians, to full double precision.
Return Value
tan returns the nearest internal representation to tan(x), in the range
[-pi/2, pi/2], expressed as a double floating value. If the number in x is
too large to be represented, tan returns zero. An argument with a large
size may return a meaningless value, i.e. when x / (2 * pi) has no fraction bits.
Example
To compute the tangent of theta:
y = tan(theta);
See Also
cos, sin
Notes
tan is packaged in the floating point library.
C Library - tanh
tanh
Description
Hyperbolic tangent
Syntax
#include <math.h>
double tanh(double x)
Function
tanh computes the value of the hyperbolic tangent of x to double precision.
Return Value
tanh returns the nearest internal representation to tanh(x), expressed as
a double floating value. If the result is too large to be properly represented, tanh returns zero.
Example
To compute the hyperbolic tangent of x:
y = tanh(x);
See Also
cosh, exp, sinh
Notes
tanh is packaged in the floating point library.
C Library - tolower
tolower
Description
Convert character to lower-case if necessary
Syntax
#include <ctype.h>
int tolower(int c)
Function
tolower converts an upper-case letter to its lower-case equivalent, leaving all other characters unmodified.
Return Value
tolower returns the corresponding lower-case letter, or the unchanged
character.
Example
To accumulate a hexadecimal digit:
for (sum = 0; isxdigit(*s); ++s)
if (isdigit(*s)
sum = sum * 16 + *s - '0';
else
sum = sum * 16 + tolower(*s) + (10 - 'a');
See Also
toupper
Notes
tolower is packaged in the integer library.
C Library - toupper
toupper
Description
Convert character to upper-case if necessary
Syntax
#include <ctype.h>
int toupper(int c)
Function
toupper converts a lower-case letter to its upper-case equivalent, leaving all other characters unmodified.
Return Value
toupper returns the corresponding upper-case letter, or the unchanged
character.
Example
To convert a character string to upper-case letters:
for (i = 0; i < size; ++i)
buf[i] = toupper(buf[i]);
See Also
tolower
Notes
toupper is packaged in the integer library.
C Library - va_arg
va_arg
Description
Get pointer to next argument in list
Syntax
#include <stdarg.h>
type va_arg(va_list ap, type)
Function
The macro va_arg is an rvalue that computes the value of the next
argument in a variable length argument list. Information on the argument list is stored in the array data object ap. You must first initialize ap
with the macro va_start, and compute all earlier arguments in the list by
expanding va_arg for each argument.
The type of the next argument is given by the type name type. The type
name must be the same as the type of the next argument. Remember
that the compiler widens an arithmetic argument to int, and converts an
argument of type float to double. You write the type after conversion.
Write int instead of char and double instead of float.
Do not write a type name that contains any parentheses. Use a type definition, if necessary, as in:
typedef int (*pfi)();
/* pointer to function returning int */
...
fun_ptr = va_arg(ap, pfi);
/* get function pointer argument */
Return Value
va_arg expands to an rvalue of type type. Its value is the value of the
next argument. It alters the information stored in ap so that the next
expansion of va_arg accesses the argument following.
Example
To write multiple strings to a file:
C Library - va_arg
#include <stdio.h>
#include <stdarg.h>
main()
{
void strput();
strput(pf, This is one string\n, \
and this is another...\n, (char *)0);
}
void strput(FILE *pf,...);
void strput(char *ptr,...)
void strput(ptr)
char *ptr;
{
char ptr;
va_list va;
if (!ptr)
return;
else
{
puts(ptr);
va_start(va, ptr);
while (ptr = va_arg(va, char *)
puts(ptr);
va_end(va);
}
}
See Also
va_end, va_start
Notes
va_arg is a macro declared in the <stdarg.h> header file. You can use it
with any function that accepts a variable number of arguments, by
including <stdarg.h> with your program.
C Library - va_end
va_end
Description
Stop accessing values in an argument list
Syntax
#include <stdarg.h>
void va_end(va_list ap)
Function
va_end is a macro which you must expand if you expand the macro
va_start within a function that contains a variable length argument list.
Information on the argument list is stored in the data object designated
by ap. Designate the same data object in both va_start and va_end.
You expand va_end after you have accessed all argument values with
the macro va_arg, before your program returns from the function that
contains the variable length argument list. After you expand va_end, do
not expand va_arg with the same ap. You need not expand va_arg
within the function that contains the variable length argument list.
You must write an expansion of va_end as an expression statement containing a function call. The call must be followed by a semicolon.
Return Value
Nothing. va_end expands to a statement, not an expression.
Example
To write multiple strings to a file:
#include <stdio.h>
#include <stdarg.h>
main()
{
void strput();
strput(pf, This is one string\n, \
and this is another...\n, (char *)0);
}
C Library - va_end
See Also
va_arg, va_start
Notes
va_end is a macro declared in the <stdarg.h> header file. You can use it
with any function that accepts a variable number of arguments, by
including <stdarg.h> with your program.
C Library - va_start
va_start
Description
Start accessing values in an argument list
Syntax
#include <stdarg.h>
void va_start(va_list ap, parmN)
Function
va_start is a macro which you must expand before you expand the
macro va_arg. It initializes the information stored in the data object
designated by ap. The argument parmN must be the identifier you
declare as the name of the last specified argument in the variable length
argument list for the function. In the function prototype for the function,
parmN is the argument name you write just before the ,...
The type of parmN must be one of the types assumed by an argument
passed in the absence of a prototype. Its type must not be float or char.
Also, parmN cannot have storage class register.
If you expand va_start, you must expand the macro va_end before your
program returns from the function containing the variable length argument list.
You must write an expansion of va_start as an expression statement
containing a function call. The call must be followed by a semicolon.
Return Value
Nothing. va_start expands to a statement, not an expression.
Example
To write multiple strings to a file:
#include <stdio.h>
#include <stdarg.h>
main()
{
C Library - va_start
void strput();
strput(pf, This is one string\n, \
and this is another...\n, (char *)0);
}
void strput(FILE *pf,...);
void strput(char *ptr,...)
void strput(ptr)
char *ptr;
{
char ptr;
va_list va;
if (!ptr)
return;
else
{
puts(ptr);
va_start(va, ptr);
while (ptr = va_arg(va, char *)
puts(ptr);
va_end(va);
}
}
See Also
va_arg, va_end
Notes
va_start is a macro declared in the <stdarg.h> header file. You can use
it with any function that accepts a variable number of arguments, by
including <stdarg.h> with your program.
C Library - vprintf
vprintf
Description
Output arguments formatted to stdout
Syntax
#include <stdio.h>
#include <stdarg.h>
int vprintf(char *s, char fmt, va_list ap)
Function
vprintf writes formatted to the output stream using the format string at
fmt and the arguments specified by pointer ap, in exactly the same way
as printf. See the description of the printf function for information on
the format conversion specifiers. The va_start macro must be executed
before to call the vprintf function.
vprintf uses putchar to output each character.
Return Value
vprintf returns the numbers of characters transmitted.
Example
To format a double at d into buf:
va_start(aptr, fmt);
vprintf(fmt, aptr);
See Also
printf, vsprintf
Notes
vprintf is packaged in both the integer library and the floating point
library. The functionality of the integer only version of vprintf is a subset of the functionality of the floating point version. The integer only
version cannot print floating point numbers. If your programs call the
integer only version of vprintf, the following conversion specifiers are
invalid: e, E, f, g and G. The L flag is also invalid.
C Library - vsprintf
vsprintf
Description
Output arguments formatted to buffer
Syntax
#include <stdio.h>
#include <stdarg.h>
int vsprintf(char *s, char fmt, va_list ap)
Function
vsprintf writes formatted to the buffer pointed at by s using the format
string at fmt and the arguments specified by pointer ap, in exactly the
same way as printf. See the description of the printf function for information on the format conversion specifiers. A NUL character is written
after the last character in the buffer. The va_start macro must be executed before to call the vsprintf function.
Return Value
vsprintf returns the numbers of characters written, not including the terminating NUL character.
Example
To format a double at d into buf:
va_start(aptr, fmt);
vsprintf(buf, fmt, aptr);
See Also
printf, vprintf
Notes
vsprintf is packaged in both the integer library and the floating point
library. The functionality of the integer only version of vsprintf is a subset of the functionality of the floating point version. The integer only
version cannot print floating point numbers. If your programs call the
integer only version of vsprintf, the following conversion specifiers are
invalid: e, E, f, g and G. The L flag is also invalid.
C Library - wavhc12
wavhc12
Description
Evaluate weighted average
Syntax
#include <fuzzy.h>
char wavhc12(char *op1, char *op2, int nbval)
Function
wavhc12 computes the average of the a list of products between two
arrays provided by the arguments op1 and op2. The argument nbval
specifies the number of input values to be used. Refer to the HC12/
HCS12 Reference Manual, for a complete description of the calculation.
Return Value
wavhc12 returns the average in the b register.
Example
res = wavhc12(tab_1, tab_2, 10);
See Also
memhc12, revhc12, revwhc12
Notes
wavhc12 is a builtin function declared in the <fuzzy.h> header file.
CHAPTER
5
Using The Assembler
The ca6812 cross assembler translates your assembly language source
files into relocatable object files. The C cross compiler calls ca6812 to
assemble your code automatically, unless specified otherwise. ca6812
generates also listings if requested. This chapter includes the following
sections:
Invoking ca6812
Object File
Listings
Branch Optimization
Old Syntax
C Style Directives
Assembler Directives
Invoking ca6812
Invoking ca6812
ca6812 accepts the following command line options, each of which is
described in detail below:
ca6812 [options] <files>
-a
absolute assembler
-b
do not optimizes branches
-c
output cross reference
-d*> define symbol=value
+e* error file name
-ff use formfeed in listing
-ft force title in listing
-f# fill byte value
-h* include header
-i*> include path
-l
output a listing
+l* listing file name
-m
accept old syntax
-mi accept label syntax
-n* processor name
-o* output file name
-pe all equates public
-pl keep local symbol
-p
all symbols public
-u
undefined in listing
-v
be verbose
-x
include line debug info
-xp no path in debug info
-xx include full debug info
-a
-b
do not optimize branch instructions. By default, the assembler replaces long branches by short branches wherever a
shorter instruction can be used, and short branches by long
branches wherever the displacement is too large. This optimization also applies to jump and jump to subroutines
instructions.
-c
Invoking ca6812
-d*>
+e*
log errors from assembler in the text file * instead of displaying the messages on the terminal screen.
-ff
-ft
-f#
define the value of the filling byte used to fill any gap created by the assembler directives. Default is 0.
-h*
-i*>
-l
+l*
-m
-mi
-n*
Invoking ca6812
-o*
-pe
-pl
-p
-u
produce an error message in the listing file for all occurrence of an undefined symbol. This option enforces the -l
option.
-v
-x
-xp
-xx
Object File
Object File
The object file produced by the assembler is a relocatable object in a
format suitable for the linker clnk. This will normally consist of
machine code, initialized data and relocation information. The object
file also contains information about the sections used, a symbol table,
and a debug symbol table.
Listings
The listing stream contains the source code used as input to the assembler, together with the hexadecimal representation of the corresponding
object code and the address for which it was generated. The contents of
the listing stream depends on the occurrence of the list, nolist, clist,
dlist and mlist directives in the source. The format of the output is as
follows:
<address> <generated_code> <source_line>
where <address> is the hexadecimal relocatable address where the
<source_line> has been assembled, <generated_code> is the hexadecimal representation of the object code generated by the assembler and
<source_line> is the original source line input to the assembler. If
expansion of data, macros and included files is not enabled, the
<generated_code> print will not contain a complete listing of all generated code.
Addresses in the listing output are the offsets from the start of the current section. After the linker has been executed, the listing files may be
updated to contain absolute information by the clabs utility. Addresses
and code will be updated to reflect the actual values as built by the
linker.
Several directives are available to modify the listing display, such as
title for the page header, plen for the page length, page for starting a
new page, tabs for the tabulation characters expansion. By default, the
listing file is not paginated. Pagination is enabled by using at least one
title directive in the source file, or by specifying the -ft option on the
command line. Otherwise, the plen and page directives are simply
ignored. Some other directives such as clist, mlist or dlist control the
amount of information produced in the listing.
2004 COSMIC Software
Instructions
ca6812 recognizes the following instructions:
aba
abx
aby
adca
adcb
adda
addb
addd
anda
andb
andcc
asl
asla
bpl
bra
brclr
brn
brset
bset
bsr
bvc
bvs
call
cba
clc
cli
ediv
edivs
emacs
emaxd
emaxm
emind
eminm
emul
emuls
eora
eorb
etbl
exg
lbls
lblt
lbmi
lbne
lbpl
lbra
lbrn
lbsr
lbvc
lbvs
ldaa
ldab
ldd
neg
nega
negb
nop
oraa
orab
orcc
psha
pshb
pshc
pshd
pshx
pshy
sev
sex
staa
stab
std
stop
sts
stx
sty
suba
subb
subd
swi
aslb
asld
asr
asra
asrb
bcc
bclr
bcs
beq
bge
bgnd
bgt
bhi
bhs
bita
bitb
ble
blo
bls
blt
bmi
bne
clr
clra
clrb
clv
cmpa
cmpb
com
coma
comb
cpd
cps
cpx
cpy
daa
dbeq
dbne
dec
deca
decb
des
dex
dey
fdiv
ibeq
ibne
idiv
idivs
inc
inca
incb
ins
inx
iny
jmp
jsr
lbcc
lbcs
lbeq
lbge
lbgt
lbhi
lbhs
lble
lblo
lds
ldx
ldy
leas
leax
leay
lsl
lsla
lslb
lsld
lsr
lsra
lsrb
lsrd
maxa
maxm
mem
mina
minm
movb
movw
mul
pula
pulb
pulc
puld
pulx
puly
rev
revw
rol
rola
rolb
ror
rora
rorb
rtc
rti
rts
sba
sbca
sbcb
sec
sei
tab
tap
tba
tbeq
tbl
tbne
tfr
tpa
tst
tsta
tstb
tsx
tsy
txs
tys
wai
wav
xgdx
xgdy
#1
var
,x
0,x
1,y+
[d,pc]
loop
var,2
var,2,loop
;
;
;
;
;
;
;
;
;
;
implicit
immediate
direct or extended
indexed
indexed
indexed
indexed
relative
bit number
bit test and branch
ldd
ldd
10,pc
symbol,pcr
; absolute offset
; relative offset
The first syntax using the register name pc encoded the specified offset
directly in the instruction. The second syntax using the register name
pcr encodes in the instruction a relative value computed by substracting
the value of the current pc from the value of the specific offset. This is
mainly used with symbolic references.
Wherever the extended addressing mode is not accepted, the assembler
will automatically replace it by an indexed addressing mode using the
pcr relative notation if accepted by the instruction. Then, the two following lines produce the same code:
ldd
ldd
[symbol,pcr]
[symbol]; implied pcr
Labels
A source line may begin with a label. Some directives require a label on
the same line, otherwise this field is optional. A label must begin with
an alphabetic character, the underscore character _ or the period character .. It is continued by alphabetic (A-Z or a-z) or numeric (0,9)
characters, underscores, dollar signs ($) or periods. Labels are case sensitive. The processor register names a, b, x and y are reserved and
cannot be used as labels.
data1: dc.b
_reg: ds.b
$56
1
1,PORTA,\@loop
Temporary Labels
The assembler allows temporary labels to be defined when there is no
need to give them an explicit name. Such a label is composed by a decimal number immediately followed by a $ character. Such a label is
valid until the next standard label or the local directive. Then the same
temporary label may be redefined without getting a multiply defined
error message.
1$:
2$:
deca
bne
decb
bne
1$
2$
Temporary labels do not appear in the symbol table or the cross reference list.
For example, to define 3 different local blocks and create and use 3 different local labels named 10$:
function1:
10$:
ldab
beq
stab
local
10$:
ldaa
beq
staa
rts
function2:
10$:
ldaa
suba
bne
rts
var
10$
var2
var2
10$
var
var2
var
10$
Constants
The assembler accepts numeric constants and string constants.
Numeric constants are expressed in different bases depending on a
prefix character as follows:
Number
Base
10
%1010
binary
@12
octal
$A
hexadecimal
Base
D, d or none
B or b
binary
Q or q
octal
0AH or 0Ah
hexadecimal
0123456789ABCDEF
#A
; ASCII value of A
Expressions
An expression consists of a number of labels and constants connected
together by operators. Expressions are evaluated to 32-bit precision.
Note that operators have the same precedence than in the C language.
212 Using The Assembler
addition
subtraction (negation)
multiplication
division
remainder (modulus)
bitwise and
bitwise or
bitwise exclusive or
bitwise complement
left shift
right shift
equality
difference
less than
less than or equal
greater than
greater than or equal
logical and
logical or
logical complement
NOTE
The difference of two relocatable labels is valid only if both symbols are
not external symbols, and are defined in the same section.
An expression may also be constructed with a special operator. These
expressions cannot be used with the previous operators and have to be
specified alone.
high(expression)
low(expression)
page(expression)
upper byte
lower byte
page byte
These special operators evaluate an expression and extract the appropriate information from the result. The expression may be relocatable,
and may use the set of operators if allowed.
high - extract the upper byte of the 16-bit expression
low - extract the lower byte of the 16-bit expression
page - extract the page value of the expression. It is computed by the
linker according to the -bs option used. This is used to get the address
extension when bank switching is used.
Macro Instructions
A macro instruction is a list of assembler commands collected under a
unique name. This name becomes a new command for the following of
the program. A macro begins with a macro directive and ends with a
endm directive. All the lines between these two directives are recorded
and associated with the macro name specified with the macro directive.
signex:macro
clra
tstb
bpl
coma
\@pos:
endm
\@pos
;
;
;
;
;
sign extension
prepare MSB
test sign
if not positive
invert MSB
; end of macro
This macro is named signex and contains the code needed to perform a
sign extension of a into x. Whenever needed, this macro can be
expanded just by using its name in place of a standard instruction:
ldab
char+1 ; load LSB
signex
; expand macro
std
char
; store result
The resulting code will be the same as if the following code had been
written:
ldab
clra
tstb
bpl
coma
char+1 ;
;
;
pos
;
;
std
char
load LSB
prepare MSB
test sign
if not positive
invert MSB
pos:
; store result
;
;
;
;
;
;
;
sign extension
prepare MSB
load LSB
if not positive
invert MSB
store MSB
end of macro
And called:
signex char
;
;
;
;
;
;
;
sign extension
prepare MSB
load LSB
if not positive
invert MSB
store MSB
end of macro
1,2,3,4
1,2,3,4
The directive mexit may be used at any time to stop the macro expansion. It is generally used in conjunction with a conditional directive.
A macro call may be used within another macro definition. A macro
definition cannot contain another macro definition.
If a listing is produced, the macro expansion lines are printed if enabled
by the mlist directive. If enabled, the invocation line is not printed, and
all the expanded lines are printed with all the parameters replaced by
their corresponding arguments. Otherwise, the invocation line only is
printed.
Conditional Directives
A conditional directive allows parts of the program to be assembled or
not depending on a specific condition expressed in an if directive. The
condition is an expression following the if command. The expression
cannot be relocatable, and shall evaluate to a numeric result. If the condition is false (expression evaluated to zero), the lines following the if
directive are skipped until an endif or else directive. Otherwise, the
lines are normally assembled. If an else directive is encountered, the
condition status is reversed, and the conditional process continues until
the next endif directive.
if
ldx
jsr
endif
debug == 1
#message
print
If the symbol debug is equal to 1, the next two lines are assembled. Otherwise they are skipped.
if
offset != 1
addptr offset
else
inx
endif
;
;
;
;
If the symbol offset is not one, the macro addptr is expanded with offset as argument, otherwise the inx instruction is directly assembled.
Sections
The assembler allows code and data to be splitted in sections. A section
is a set of code or data referenced by a section name, and providing a
contiguous block of relocatable information. A section is defined with a
section directive, which creates a new section and redirects the following code and data thereto. The directive switch can be used to redirect
the following code and data to another section.
data: section
text: section
start: ldx
#value
jmp
print
switch data
value: dc.b
1,2,3
Description
.text
executable code
.data
initialized data
.bss
uninitialized data
.bsct
.ubsct
The sections .bsct and .ubsct are used for locating data in the zero page
of the processor. The zero page is defined as the memory addresses
218 Using The Assembler
between 0x00 and 0xFF inclusive, i.e. the memory directly addressable
by a single byte. Several processors include special instructions and/or
addressing modes that take advantage of this special address range. The
Cosmic assembler will automatically use the most efficient addressing
mode if the data objects are allocated in the .bsct, .ubsct or a section
with the same attributes. If zero page data objects are defined in another
file then the directive xref.b must be used to externally reference the
data object. This directive specifies that the address for these data
object is only one byte and therefore the assembler may use 8 bit
addressing modes.
xref
xref.b
switch
zvar2: ds.b
switch
var2: ds.b
switch
ldaa
ldaa
ldaa
ldaa
end
var
zvar
.bsct
1
.bss
1
.text
var
zvar
var2
var2
Includes
The include directive specifies a file to be included and assembled in
place of the include directive. The file name is written between double
quotes, and may be any character string describing a file on the host
system. If the file cannot be found using the given name, it is searched
from all the include paths defined by the -i options on the command
line, and from the paths defined by the environment symbol CXLIB, if
such a symbol has been defined before the assembler invocation. This
symbol may contain several paths separated by the usual path separator
of the host operating system (; for MSDOS and : for UNIX).
The -h option can specify a file to be included. The file specified will
be included as if the program had an include directive at its very top.
The specified file will be included before any source file specified on
the command line.
Branch Optimization
Branch Optimization
Branch instructions are by default automatically optimized to produce
the shortest code possible. This behaviour may be disabled by the -b
option. This optimization operates on conditional branches, on jumps
and jumps to subroutine.
A conditional branch offset is limited to the range [-128,127]. If such an
instruction cannot be encoded properly, the assembler will replace it by
a sequence containing an inverted branch to the next location followed
immediately by a jump to the original target address. The assembler
keep track of the last replacement for each label, so if a long branch has
already been expanded for the same label at a location close enough
from the current instruction, the target address of the short branch will
be changed only to branch on the already existing jump instruction to
the specified label.
beq
farlabel
becomes
bne
jmp
*+5
farlabel
Old Syntax
The -m option allows the assembler to accept old constructs which are
now obsolete. The following features are added to the standard behaviour:
a label starting in the first column does not need to be ended with
a : character;
C Style Directives
The comment separator at the end of an instruction is still the ; character because the * character is interpreted as the multiply operator.
C Style Directives
The assembler also supports C style directives matching the preprocessor directives of a C compiler. The following directives list shows the
equivalence with the standard directives:
C Style
Assembler Style
#include file
include file
label:
equ expression
#define label
label:
equ 1
#if expression
if expression
#ifdef label
ifdef label
#ifndef label
ifndef label
#else
else
#endif
endif
#error message
fail message
NOTE
The #define directive does not implement all the text replacement features provided by a C compiler. It can be used only to define a symbol
equal to a numerical value.
Assembler Directives
This section consists of quick reference descriptions for each of the
ca6812 assembler directives.
C Library - align
align
Description
Align the next instruction on a given boundary
Syntax
align <expression>,[<fill_value>]
Function
The align directive forces the next instruction to start on a specific
boundary. The align directive is followed by a constant expression
which must be positive. The next instruction will start at the next
address which is a multiple of the specified value. If bytes are added in
the section, they are set to the value of the filling byte defined by the -f
option. If <fill_value>, is specified, it will be used locally as the filling
byte, instead of the one specified by the -f option.
Example
align
ds.b
3
1
See Also
even
C Library - base
base
Description
Define the default base for numerical constants
Syntax
base <expression>
Function
The base directive sets the default base for numerical constants beginning with a digit. The base directive is followed by a constant expression which value must be one of 2, 8, 10 or 16. The decimal base is used
by default. When another base is selected, it is no more possible to enter
decimal constants.
Example
base
lda
8
#377
C Library - bsct
bsct
Description
Switch to the predefined .bsct section.
Syntax
bsct
Function
The bsct directive switches input to a section named .bsct, also known
as the zero page section. The assembler will automatically select the
direct addressing mode when referencing an object defined in the .bsct
section.
Example
bsct
c_reg:
ds.b
Notes
The .bsct section is limited to 256 bytes, but the assembler does not
check the .bsct section size. This will be done by the linker.
See Also
section, switch
C Library - clist
clist
Description
Turn listing of conditionally excluded code on or off.
Syntax
clist [on|off]
Function
The clist directive controls the output in the listing file of conditionally
excluded code. It is effective if and only if listings are requested; it is
ignored otherwise.
The parts of the program to be listed are the program lines which are not
assembled as a consequence of if, else and endif directives.
See Also
if, else, endif
C Library - dc
dc
Description
Allocate constant(s)
Syntax
dc[.size] <expression>[,<expression>...]
Function
The dc directive allocates and initializes storage for constants. If
<expression> is a string constant, one byte is allocated for each character of the string. Initialization can be specified for each item by giving a
series of values separated by commas or by using a repeat count.
The dc and dc.b directives will allocate one byte per <expression>.
The dc.w directive will allocate one word per <expression>.
The dc.l directive will allocate one long word per <expression>.
Example
digit: dc.b
dc.w
10,'0123456789'
digit
Note
For compatibility with previous assemblers, the directive fcb is alias to
dc.b, and the directive fdb is alias to dc.w.
C Library - dcb
dcb
Description
Allocate constant block
Syntax
dcb.<size> <count>,<value>
Function
The dcb directive allocates a memory block and initializes storage for
constants. The size area is the number of the specified value <count> of
<size>. The memory area can be initialized with the <value> specified.
The dcb and dcb.b directives will allocate one byte per <count>.
The dcb.w directive will allocate one word per <count>.
The dcb.l directive will allocate one long word per <count>.
Example
digit: dcb.b
10,5
; allocate 10 bytes,
; all initialized to 5
C Library - dlist
dlist
Description
Turn listing of debug directives on or off.
Syntax
dlist [on|off]
Function
The dlist directive controls the visibility of any debug directives in the
listing. It is effective if and only if listings are requested; it is ignored
otherwise.
C Library - ds
ds
Description
Allocate variable(s)
Syntax
ds[.size] <space>
Function
The ds directive allocates storage space for variables. <space> must be
an absolute expression. Bytes created are set to the value of the filling
byte defined by the -f option.
The ds and ds.b directives will allocate <space> bytes.
The ds.w directive will allocate <space> words.
The ds.l directive will allocate <space> long words.
Example
ptlec:
ptecr:
chrbuf:
ds.b
ds.b
ds.w
2
2
128
Note
For compatibility with previous assemblers, the directive rmb is alias
to ds.b.
C Library - else
else
Description
Conditional assembly
Syntax
if <expression>
instructions
else
instructions
endif
Function
The else directive follows an if directive to define an alternative conditional sequence. It reverts the condition status for the following instructions up to the next matching endif directive. An else directive applies
to the closest previous if directive.
Example
if
offset != 1
addptr offset
else
inx
endif
;
;
;
;
Note
The else and elsec directives are equivalent and may used without distinction. They are provided for compatibility with previous assemblers.
See Also
if, endif, clist
C Library - elsec
elsec
Description
Conditional assembly
Syntax
if <expression>
instructions
elsec
instructions
endc
Function
The elsec directive follows an if directive to define an alternative conditional sequence. It reverts the condition status for the following instructions up to the next matching endc directive. An elsec directive applies
to the closest previous if directive.
Example
ifge
offset-127
addptr offset
elsec
inx
endc
;
;
;
;
Note
The elsec and else directives are equivalent and may used without distinction. They are provided for compatibility with previous assemblers.
See Also
if, endc, clist, else
C Library - end
end
Description
Stop the assembly
Syntax
end
Function
The end directive stops the assembly process. Any statements following it are ignored. If the end directive is encountered in an included file,
it will stop the assembly process for the included file only.
C Library - endc
endc
Description
End conditional assembly
Syntax
if<cc> <expression>
instructions
endc
Function
The endc directive closes an if<cc> or elsec conditional directive. The
conditional status reverts to the one existing before entering the if<cc>
directives. The endc directive applies to the closest previous if<cc> or
elsec directive.
Example
ifge
offset-127
addptr offset
elsec
inx
endc
;
;
;
;
Note
The endc and endif directives are equivalent and may used without distinction. They are provided for compatibility with previous assemblers.
See Also
if<cc>, elsec, clist, end
C Library - endif
endif
Description
End conditional assembly
Syntax
if <expression>
instructions
endif
Function
The endif directive closes an if or else conditional directive. The conditional status reverts to the one existing before entering the if directive.
The endif directive applies to the closest previous if or else directive.
Example
if
offset != 1
addptr offset
else
inx
endif
;
;
;
;
Note
The endif and endc directives are equivalent and may used without distinction. They are provided for compatibility with previous assemblers.
See Also
if, else, clist
C Library - endm
endm
Description
End macro definition
Syntax
label: macro
<macro_body>
endm
Function
The endm directive is used to terminate macro definitions.
Example
; define a macro that places the length of
; a string in a byte prior to the string
ltext: macro
ds.b
\@1:
ds.b
\@2:
endm
\@2 - \@1
\1
See Also
mexit, macro
C Library - endr
endr
Description
End repeat section
Syntax
repeat
<macro_body>
endr
Function
The endr directive is used to terminate repeat sections.
Example
asln:
See Also
repeat, repeatl
C Library - equ
equ
Description
Give a permanent value to a symbol
Syntax
label: equ <expression>
Function
The equ directive is used to associate a permanent value to a symbol
(label). Symbols declared with the equ directive may not subsequently
have their value altered otherwise the set directive should be used.
<expression> must be either a constant expression, or a relocatable
expression involving a symbol declared in the same section as the current one.
Example
false: equ
true: equ
tablen:equ
nul:
equ
soh:
equ
stx:
equ
etx:
equ
eot:
equ
enq:
equ
0
; initialize these values
1
tabfin - tabsta;compute table length
$0
; define strings for ascii characters
$1
$2
$3
$4
$5
See Also
lit, set
C Library - even
even
Description
Assemble next byte at the next even address relative to the start of a
section.
Syntax
even [<fill_value>]
Function
The even directive forces the next assembled byte to the next even
address. If a byte is added to the section, it is set to the value of the filling byte defined by the -f option. If <fill_value> is specified, it will be
used locally as the filling byte, instead of the one specified by the -f
option.
Example
vowtab:dc.b
even
tentab:dc.w
'aeiou'
; ensure aligned at even address
1, 10, 100, 1000
C Library - fail
fail
Description
Generate error message.
Syntax
fail "string"
Function
The fail directive outputs string as an error message. No output file is
produced as this directive creates an assembly error. fail is generally
used with conditional directives.
Example
Max:
equ
ifge
fail
512
value - Max
Value too large
C Library - if
if
Description
Conditional assembly
Syntax
if <expression>
instructions
endif
or
if <expression>
instructions
else
instructions
endif
Function
The if, else and endif directives allow conditional assembly. The if
directive is followed by a constant expression. If the result of the
expression is not zero, the following instructions are assembled up to
the next matching endif or else directive; otherwise, the following
instructions up to the next matching endif or else directive are skipped.
If the if statement ends with an else directive, the expression result is
inverted and the same process applies to the following instructions up to
the next matching endif. So, if the if expression was not zero, the
instructions between else and endif are skipped; otherwise, the instructions between else and endif are assembled. An else directive applies to
the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
if
offset != 1
addptr offset
else
inx
endif
;
;
;
;
See Also
else, endif, clist
C Library - ifc
ifc
Description
Conditional assembly
Syntax
ifc <string1>,<string2>
instructions
endc
orifc <string1>,<string2>
instructions
elsec
instructions
endc
Function
The ifc, else and endc directives allow conditional assembly. The ifc
directive is followed by a constant expression. If <string1> and
<string2> are equals, the following instructions are assembled up to the
next matching endc or elsec directive; otherwise, the following instructions up to the next matching endc or elsec directive are skipped.
If the ifc statement ends with an elsec directive, the expression result is
inverted and the same process applies to the following instructions up to
the next matching endc. So, if the ifc expression was not zero, the
instructions between elsec and endc are skipped; otherwise, the instructions between elsec and endc are assembled. An elsec directive applies
to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifc
ldab
elsec
ldab
endc
hello, \2
#45
#0
See Also
elsec, endc, clist
C Library - ifdef
ifdef
Description
Conditional assembly
Syntax
ifdef <label>
instructions
endc
or
ifdef <label>
instructions
elsec
instructions
endc
Function
The ifdef, elsec and endc directives allow conditional assembly. The
ifdef directive is followed by a label <label>. If <label> is defined, the
following instructions are assembled up to the next matching endc or
elsec directive; otherwise, the following instructions up to the next
matching endc or elsec directive are skipped. <label> must be first
defined. It cannot be a forward reference.
If the ifdef statement ends with an elsec directive, the expression result
is inverted and the same process applies to the following instructions up
to the next matching endif. So, if the ifdef expression was not zero, the
instructions between elsec and endc are skipped; otherwise, the instructions between elsec and endc are assembled. An elsec directive applies
to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not be in
the listing depending on the clist directive status.
Example
ifdef offset1
addptr offset1
elsec
addptr offset2
endif
;
;
;
;
if offset1 is defined
call a macro
otherwise
call a macro
See Also
ifndef, elsec, endc, clist
C Library - ifeq
ifeq
Description
Conditional assembly
Syntax
ifeq <expression>
instructions
endc
or
ifeq <expression>
instructions
elsec
instructions
endc
Function
The ifeq, elsec and endc directives allow conditional assembly. The
ifeq directive is followed by a constant expression. If the result of the
expression is equal to zero, the following instructions are assembled up
to the next matching endc or elsec directive; otherwise, the following
instructions up to the next matching endc or elsec directive are skipped.
If the ifeq statement ends with an elsec directive, the expression result
is inverted and the same process applies to the following instructions up
to the next matching endc. So, if the ifeq expression is equal to zero,
the instructions between elsec and endc are skipped; otherwise, the
instructions between elsec and endc are assembled. An elsec directive
applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifeq
tsta
elsec
add
endc
offset
#offset
;
;
;
;
if offset nul
just test it
otherwise
add to accu
See Also
elsec, endc, clist
C Library - ifge
ifge
Description
Conditional assembly
Syntax
ifge <expression>
instructions
endc
or
ifge <expression>
instructions
elsec
instructions
endc
Function
The ifge, elsec and endc directives allow conditional assembly. The
ifge directive is followed by a constant expression. If the result of the
expression is greater or equal to zero, the following instructions are
assembled up to the next matching endc or elsec directive; otherwise,
the following instructions up to the next matching endc or elsec directive are skipped.
If the ifge statement ends with an elsec directive, the expression result
is inverted and the same process applies to the following instructions up
to the next matching endc. So, if the ifge expression is greater or equal
to zero, the instructions between elsec and endc are skipped; otherwise,
the instructions between elsec and endc are assembled. An elsec directive applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifge
offset-127
addptr offset
elsec
inx
endc
;
;
;
;
See Also
elsec, endc, clist
C Library - ifgt
ifgt
Description
Conditional assembly
Syntax
ifgt <expression>
instructions
endc
or
ifgt <expression>
instructions
elsec
instructions
endc
Function
The ifgt, elsec and endc directives allow conditional assembly. The ifgt
directive is followed by a constant expression. If the result of the
expression is greater than zero, the following instructions are assembled up to the next matching endc or elsec directive; otherwise, the following instructions up to the next matching endc or elsec directive are
skipped.
If the ifgt statement ends with an elsec directive, the expression result is
inverted and the same process applies to the following instructions up to
the next matching endc. So, if the ifgt expression was greater than
zero, the instructions between elsec and endc are skipped; otherwise,
the instructions between elsec and endc are assembled. An elsec directive applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifgt
offset-127
addptr offset
elsec
inx
endc
;
;
;
;
See Also
elsec, endc, clist
C Library - ifle
ifle
Description
Conditional assembly
Syntax
ifle <expression>
instructions
endc
or
ifle <expression>
instructions
elsec
instructions
endc
Function
The ifle, elsec and endc directives allow conditional assembly. The ifle
directive is followed by a constant expression. If the result of the
expression is less or equal to zero, the following instructions are
assembled up to the next matching endc or elsec directive; otherwise,
the following instructions up to the next matching endc or elsec directive are skipped.
If the ifle statement ends with an elsec directive, the expression result is
inverted and the same process applies to the following instructions up to
the next matching endc. So, if the ifle expression was less or equal to
zero, the instructions between elsec and endc are skipped; otherwise,
the instructions between elsec and endc are assembled. An elsec directive applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifle
offset-127
inx
elsec
addptr offset
endc
;
;
;
;
See Also
elsec, endc, clist
C Library - iflt
iflt
Description
Conditional assembly
Syntax
iflt <expression>
instructions
endc
or
iflt <expression>
instructions
elsec
instructions
endc
Function
The iflt, else and endc directives allow conditional assembly. The iflt
directive is followed by a constant expression. If the result of the
expression is less than zero, the following instructions are assembled
up to the next matching endc or elsec directive; otherwise, the following instructions up to the next matching endc or elsec directive are
skipped.
If the iflt statement ends with an elsec directive, the expression result is
inverted and the same process applies to the following instructions up to
the next matching endc. So, if the iflt expression was less than zero,
the instructions between elsec and endc are skipped; otherwise, the
instructions between elsec and endc are assembled. An elsec directive
applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
iflt
offset-127
inx
elsec
addptr offset
endc
;
;
;
;
See Also
elsec, endc, clist
C Library - ifnc
ifnc
Description
Conditional assembly
Syntax
ifnc <string1>,string2> or ifnc <string1><string2>
instructions
instructions
endc
elsec
instructions
endc
Function
The ifnc, elsec and endc directives allow conditional assembly. The
ifnc directive is followed by a constant expression. If <string1> and
<string2> are differents, the following instructions are assembled up to
the next matching endc or elsec directive; otherwise, the following
instructions up to the next matching endc or elsec directive are skipped.
If the ifnc statement ends with an elsec directive, the expression result
is inverted and the same process applies to the following instructions up
to the next matching endc. So, if the ifnc expression was not zero, the
instructions between elsec and endc are skipped; otherwise, the instructions between elsec and endc are assembled. An elsec directive applies
to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifnc
hello, \2
addptr offset
else
inx
endif
; call a macro
; otherwise
; increment X register
See Also
elsec, endc, clist
C Library - ifndef
ifndef
Description
Conditional assembly
Syntax
ifndef <label>
instructions
endc
or
ifndef <label>
instructions
elsec
instructions
endc
Function
The ifndef, else and endc directives allow conditional assembly. The
ifndef directive is followed by a label <label>. If <label> is not
defined, the following instructions are assembled up to the next matching endc or elsec directive; otherwise, the following instructions up to
the next matching endc or elsec directive are skipped. <label> must be
first defined. It cannot be a forward reference.
If the ifndef statement ends with an elsec directive, the expression
result is inverted and the same process applies to the following instructions up to the next matching endif. So, if the ifndef expression was not
zero, the instructions between elsec and endc are skipped; otherwise,
the instructions between elsec and endc are assembled. An elsec directive applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not be in
the listing depending on the clist directive status.
Example
ifndef offset1
addptr offset2
elsec
addptr offset1
endif
;
;
;
;
See Also
ifdef, elsec, endc, clist
C Library - ifne
ifne
Description
Conditional assembly
Syntax
ifne <expression>
instructions
endc
or
ifne <expression>
instructions
elsec
instructions
endc
Function
The ifne, elsec and endc directives allow conditional assembly. The
ifne directive is followed by a constant expression. If the result of the
expression is not equal to zero, the following instructions are assembled up to the next matching endc or elsec directive; otherwise, the following instructions up to the next matching endc or elsec directive are
skipped.
If the ifne statement ends with an elsec directive, the expression result
is inverted and the same process applies to the following instructions up
to the next matching endc. So, if the ifne expression was not equal to
zero, the instructions between elsec and endc are skipped; otherwise,
the instructions between elsec and endc are assembled. An elsec directive applies to the closest previous if directive.
The if directives may be nested. The skipped lines may or may not in
the listing depending on the clist directive status.
Example
ifne
add
elsec
tsta
endc
offset
#offset
;
;
;
;
See Also
elsec, endc, clist
C Library - include
include
Description
Include text from another text file
Syntax
include "filename"
Function
The include directive causes the assembler to switch its input to the
specified filename until end of file is reached, at which point the assembler resumes input from the line following the include directive in the
current file. The directive is followed by a string which gives the name
of the file to be included. This string must match exactly the name and
extension of the file to be included; the host system convention for
uppercase/lowercase characters should be respected.
Example
include
include
include
include
datstr
bldstd
matmac
ports82
;
;
;
;
use
use
use
use
C Library - list
list
Description
Turn on listing during assembly.
Syntax
list
Function
The list directive controls the parts of the program which will be written
to the listing file. It is effective if and only if listings are requested; it is
ignored otherwise.
Example
list
; expand source code until end or nolist
dc.b 1,2,4,8,16
end
See Also
nolist
C Library - lit
lit
Description
Give a text equivalent to a symbol
Syntax
label: lit string
Function
The lit directive is used to associate a text string to a symbol (label).
This symbol is replaced by the string content when parsed in any
assembler instruction or directive.
Example
nbr:
lit
ldx
#5
nbr
; expand as ldx #5
See Also
equ, set
C Library - local
local
Description
Create a new local block
Syntax
local
Function
The local directive is used to create a new local block. When the local
directive is used, all temporary labels defined before the local directive
will be undefined after the local label. New local labels can then be
defined in the new local block. Local labels can only be referenced
within their own local block. A local label block is the area between
two standard labels or local directives or a combination of the two.
Example
var:
ds.b
var2: ds.b
function1:
10$:
ldab
beq
stab
local
10$:
ldaa
beq
staa
rts
1
1
var
10$
var2
var2
10$
var
C Library - macro
macro
Description
Define a macro
Syntax
label: macro
<argument_list>
<macro_body>
endm
Function
The macro directive is used to define a macro. The name may be any
previously unused name, a name already used as a macro, or an instruction mnemonic for the microprocessor.
Macros are expanded when the name of a previously defined macro is
encountered. Operands, where given, follow the name and are separated
from each other by commas.
The <argument_list> is optional and, if specified, is declaring each
argument by name. Each argument name is prefixed by a \ character,
and separated from any other name by a comma. An argument name is
an identifier which may contain . and _ characters.
The <macro_body> consists of a sequence of instructions not including
the directives macro or endm. It may contain macro variables which
will be replaced, when the macro is expanded, by the corresponding
operands following the macro invocation. These macro variables take
the form \1 to \9 to denote the first to ninth operand respectively and \A
to \Z to denote the tenth to 35th operand respectively, if the macro has
been defined without any <argument_list>. Otherwise, macro variables
are denoted by their name prefixed by a \ character. The macro variable
name can also be enclosed by parenthesis to avoid unwanted concatenation with the remaining text. In addition, the macro variable \# contains
the number of actual operands for a macro invocation.
The special parameter \* is expanded to the full list of passed arguments
separated by commas.
C Library - macro
Example
; define a macro that places the length of a string
; in a byte in front of the string using numbered syntax
;
ltext: macro
dc.b
\@2-\@1
\@1:
dc.b
\1 ; text given as first operand
\@2:
endm
; define a macro that places the length of a string
; in a byte in front of the string using named syntax
;
ltext: macro \string
dc.b
\@2-\@1
\@1:
dc.b
\string ; text given as first operand
\@2:
endm
See Also
endm, mexit
C Library - messg
messg
Description
Send a message out to STDOUT
Syntax
messg
messg
<text>
<text>
Function
The messg directive is used to send a message out to the host systems
standard output (STDOUT).
Example
messg
ldaa
staa
See Also
title
C Library - mexit
mexit
Description
Terminate a macro definition
Syntax
mexit
Function
The mexit directive is used to exit from a macro definition before the
endm directive is reached. mexit is usually placed after a conditional
assembly directive.
Example
ctrace:macro
if tflag == 0
mexit
endif
jsr
\1
endm
See Also
endm, macro
C Library - mlist
mlist
Description
Turn on or off listing of macro expansion.
Syntax
mlist [on|off]
Function
The mlist directive controls the parts of the program which will be written to the listing file produced by a macro expansion. It is effective if
and only if listings are requested; it is ignored otherwise.
The parts of the program to be listed are the lines which are assembled
in a macro expansion.
See Also
macro
C Library - nolist
nolist
Description
Turn off listing.
Syntax
nolist
Function
The nolist directive controls the parts of the program which will be not
written to the listing file until an end or a list directive is encountered. It
is effective if and only if listings are requested; it is ignored otherwise.
See Also
list
Note
For compatibility with previous assemblers, the directive nol is alias to
nolist.
C Library - nopage
nopage
Description
Disable pagination in the listing file
Syntax
nopage
Function
The nopage directive stops the pagination mechanism in the listing output. It is ignored if no listing has been required.
Example
xref
mult, div
nopage
ds.b
charin, charout
ds.w
a, b, sum
See Also
plen, title
C Library - offset
offset
Description
Creates absolute symbols
Syntax
offset <expresion>
Function
The offset directive starts an absolute section which will only be used to
define symbols, and not to produce any code or data. This section starts
at the address specified by <expression>, and remains active while no
directive or instructions producing code or data is entered. This absolute section is then destroyed and the current section is restored to the
one which was active when the offset directive has been entered. All the
labels defined is this section become absolute symbols.
<expression> must be a valid absolute expression. It must not contain
any forward or external references.
Example
offset 0
next:
ds.b
ds.b
80
buffer:
switch .text
size:
ldy
next,x
C Library - org
org
Description
Sets the location counter to an offset from the beginning of a section.
Syntax
org <expression>
Function
<expression> must be a valid absolute expression. It must not contain
any forward or external references.
For an absolute section, the first org before any code or data defines the
starting address.
An org directive cannot define an address smaller than the location
counter of the current section.
Any gap created by an org directive is filled with the byte defined by
the -f option.
C Library - page
page
Description
Start a new page in the listing file
Syntax
page
Function
The page directive causes a formfeed to be inserted in the listing output
if pagination is enabled by either a title directive or the -ft option.
Example
xref
page
ds.b
ds.w
mult, div
charin, charout
a, b, sum
See Also
plen, title
C Library - plen
plen
Description
Specify the number of lines per pages in the listing file
Syntax
plen <page_length>
Function
The plen directive causes <page_length> lines to be output per page in
the listing output if pagination is enabled by either a title directive or
the -ft option. If the number of lines already output on the current page
is less than <page_length>, then the new page length becomes effective with <page_length>. If the number of lines already output on the
current page is greater than or equal to <page_length>, a new page will
be started and the new page length is set to <page_length>.
Example
plen
58
See Also
page, title
C Library - repeat
repeat
Description
Repeat a list of lines a number of times
Syntax
repeat <expression>
repeat_body
endr
Function
The repeat directive is used to cause the assembler to repeat the following list of source line up to the next endr directive. The number of
times the source lines will be repeated is specified by the expression
operand. The repeat directive is equivalent to a macro definition followed by the same number of calls on that macro.
A repeat directive may be terminated early by using the rexit directive
which, when encountered, acts as if the end of the repeat has been
reached.
Example
; shift a value n times
asln: macro
repeat \1
aslb
endr
endm
; use of above macro
asln
5
See Also
endr, repeatl, rexit
C Library - repeatl
repeatl
Description
Repeat a list of lines a number of times
Syntax
repeatl <arguments>
repeat_body
endr
Function
The repeatl directive is used to cause the assembler to repeat the following list of source line up to the next endr directive. The number of
times the source lines will be repeated is specified by the number of
arguments, separated with commas (with a maximum of 36 arguments)
and executed each time with the value of an argument. The repeatl
directive is equivalent to a macro definition followed by the same
number of calls on that macro with each time a different argument. The
repeat argument is denoted \1 unless the argument list is starting by a
name prefixed by a \ character. In such a case, the repeat argument is
specified by its name prefixed by a \ character.
A repeatl directive may be terminated early by using the rexit directive
which, when encountered, acts as if the end of the repeatl has been
reached.
Example
; test a value using the numbered syntax
repeatl1,2,3
addd
#\1
; add to accu
endr
end
or
; test a value using the named syntax
repeatl\count,1,2,3
addd
#\count; add to accu
endr
end
C Library - repeatl
; test
0000 c30001addd
0003 c30002addd
0006 c30003addd
end
a value
#1
; add to accu
#2
; add to accu
#3
; add to accu
See Also
endr, repeat, rexit
C Library - restore
restore
Description
Restore saved section
Syntax
restore
Function
The restore directive is used to restore the last saved section. This is
equivalent to a switch to the saved section.
Example
switch .bss
var:
ds.b
1
var2: ds.b
1
save
switch .text
function1:
10$:
ldab
var
beq
10$
stab
var2
function2:
10$:
ldaa
var2
suba
var
bne
10$
rts
restore
var3: ds.b
1
var4: ds.b
1
switch .text
ldaa
staa
var3
var4
end
See Also
save, section
C Library - rexit
rexit
Description
Terminate a repeat definition
Syntax
rexit
Function
The rexit directive is used to exit from a repeat definition before the
endr directive is reached. rexit is usually placed after a conditional
assembly directive.
Example
; shift a value n times
asln: macro
repeat \1
if \1 == 0
rexit
endif
aslb
endr
endm
; use of above macro
asln
5
See Also
endr, repeat, repeatl
C Library - save
save
Description
Save section
Syntax
save
Function
The save directive is used to save the current section so it may be
restored later in the source file.
Example
var:
var2:
switch
ds.b
ds.b
save
switch
.bss
1
1
.text
function1:
10$:
ldab
var
beq
10$
stab
var2
function2:
10$:
ldaa
var2
suba
var
bne
10$
rts
restore
var3: ds.b
1
var4: ds.b
1
switch .text
ldaa
staa
var3
var4
end
See Also
restore, section
C Library - section
section
Description
Define a new section
Syntax
<section_name>: section [<attributes>]
Function
The section directive defines a new section, and indicates that the following program is to be assembled into a section named
<section_name>. The section directive cannot be used to redefine an
already existing section. If no name and no attributes are specified to
the section, the default is to defined the section as a text section with its
same attributes. It is possible to associate <attributes> to the new section. An attribute is either the name of an existing section or an attribute
keyword. Attributes may be added if prefixed by a + character or not
prefixed, or deleted if prefixed by a - character. Several attributes may
be specified separated by commas. Attribute keywords are:
abs
absolute section
bss
hilo
even
zpage
long
Example
CODE:
lab1:
DATA:
lab2:
lab3:
lab4:
C Library - section
This will place lab1 and then lab3 into consecutive locations in section CODE and lab2 and lab4 in consecutive locations in section
DATA.
.frame: section .bsct,even
The .frame section is declared with same attributes than the .bsct section and with the even attribute.
.bit:
section +zpage,+even,-hilo
The .bit section is declared using 8 bit relocation, with an even alignment and storing data with an ascending order of significance.
When the -m option is used, the section directive also accepts a number
as operand. In that case, a labelled directive is considered as a section
definition, and an unlabelled directive is considered as a section opening (switch).
.rom:
.ram:
section1
nop
section 2
dc.b
1
section 1
nop
; define section 1
; define section 2
; switch back to section 1
See Also
switch, bsct
C Library - set
set
Description
Give a resetable value to a symbol
Syntax
label: set <expression>
Function
The set directive allows a value to be associated with a symbol. Symbols declared with set may be altered by a subsequent set. The equ
directive should be used for symbols that will have a constant value.
<expression> must be fully defined at the time the equ directive is
assembled.
Example
OFST:
set
10
See Also
equ, lit
C Library - spc
spc
Description
Insert a number of blank lines before the next statement in the listing
file.
Syntax
spc <num_lines>
Function
The spc directive causes <num_lines> blank lines to be inserted in the
listing output before the next statement.
Example
spc
title
5
new file
If listing is requested, 5 blank lines will be inserted, then the title will be
output.
See Also
title
C Library - switch
switch
Description
Place code into a section.
Syntax
switch <section_name>
Function
The switch directive switches output to the section defined with the
section directive. <section_name> is the name of the target section,
and has to be already defined. All code and data following the switch
directive up to the next section, switch, bsct or end directive are placed
in the section <section_name>.
Example
switch .bss
buffer:ds.b
512
xdef
buffer
See Also
section, bsct
C Library - tabs
tabs
Description
Specify the number of spaces for a tab character in the listing file
Syntax
tabs <tab_size>
Function
The tabs directive sets the number of spaces to be substituted to the tab
character in the listing output. The minimum value of <tab_size> is 0
and the maximum value is 128.
Example
tabs
C Library - title
title
Description
Define default header
Syntax
title "name"
Function
The title directive is used to enable the listing pagination and to set the
default page header used when a new page is written to the listing output.
Example
title
My Application
See Also
messg, page, plen
Note
For compatibility with previous assemblers, the directive ttl is alias to
title.
C Library - xdef
xdef
Description
Declare a variable to be visible
Syntax
xdef identifier[,identifier...]
Function
Visibility of symbols between modules is controlled by the xdef and
xref directives. A symbol may only be declared as xdef in one module.
A symbol may be declared both xdef and xref in the same module, to
allow for usage of common headers.
Example
xdef
sqrt
sqrt:
;
;
;
;
See Also
xref
C Library - xref
xref
Description
Declare symbol as being defined elsewhere
Syntax
xref[.b] identifier[,identifier...]
Function
Visibility of symbols between modules is controlled by the xref and
xdef directives. Symbols which are defined in other modules must be
declared as xref. A symbol may be declared both xdef and xref in the
same module, to allow for usage of common headers.
The directive xref.b declares external symbols located in the .bsct section.
Example
xref
otherprog
xref.b zpage ; is in .bsct section
See Also
xdef
C Library - xref.5
xref.5
Description
Declare a special external symbol
Syntax
xref.5 identifier[,identifier...]
Function
The directive xref.5 declares external symbols to be handled as 5 bits
signed values, allowing the assembler to encode an indexed addressing
mode with the smallest size as possible. The linker will verify that the
final value is compatible with the encoded addressing mode, and will
output an error message if not.
Example
xref.5 small
ldd
See Also
xref, xref.9
C Library - xref.9
xref.9
Description
Declare a special external symbol
Syntax
xref.9 identifier[,identifier...]
Function
The directive xref.9 declares external symbols to be handled as 9 bits
signed values, allowing the assembler to encode an indexed addressing
mode with the appropriate size. The linker will verify that the final
value is compatible with the encoded addressing mode, and will output
an error message if not.
Example
xref.9 medium
ldd
See Also
xref, xref.9
CHAPTER
6
Using The Linker
This chapter discusses the clnk linker and details how it operates. It
describes each linker option, and explains how to use the linker's many
special features. It also provides example linker command lines that
show you how to perform some useful operations. This chapter includes
the following sections:
Introduction
Overview
Linker Options
Section Relocation
Linking Objects
Bank Switching
Moveable Code
Checksum Computation
Special Topics
Introduction
Introduction
The linker combines relocatable object files, selectively loading from
libraries of such files made with clib, to create an executable image for
standalone execution or for input to other binary reformatters.
clnk will also allow the object image that it creates to have local symbol
regions, so the same library can be loaded multiple times for different
segments, and so that more control is provided over which symbols are
exposed. On microcontroller architectures this feature is useful if your
executable image must be loaded into several noncontiguous areas in
memory.
NOTE
The terms segment and section refer to different entities and are
carefully kept distinct throughout this chapter. A section is a contiguous subcomponent of an object module that the linker treats as indivisible.
The assembler creates several sections in each object module. The
linker combines input sections in various ways, but will not break one
up. The linker then maps these combined input sections into output segments in the executable image using the options you specify.
A segment is a logically unified block of memory in the executable
image. An example is the code segment which contains the executable
instructions.
For most applications, the sections in an object module that the linker
accepts as input are equivalent to the segments of the executable
image that the linker generates as output.
Overview
Overview
You use the linker to build your executable program from a variety of
modules. These modules can be the output of the C cross compiler, or
can be generated from handwritten assembly language code. Some
modules can be linked unconditionally, while others can be selected
only as needed from function libraries. All input to the linker, regardless of its source, must be reduced to object modules, which are then
combined to produce the program file.
The output of the linker can be in the same format as its input. Thus, a
program can be built in several stages, possibly with special handling at
some of the stages. It can be used to build freestanding programs such
as system bootstraps and embedded applications. It can also be used to
make object modules that are loaded one place in memory but are
designed to execute somewhere else. For example, a data segment in
ROM to be copied into RAM at program startup can be linked to run at
its actual target memory location. Pointers will be initialized and
address references will be in place.
As a side effect of producing files that can be reprocessed, clnk retains
information in the final program file that can be quite useful. The symbol table, or list of external identifiers, is handy when debugging programs, and the utility cobj can be made to produce a readable list of
symbols from an object file. Finally, each object module has in its
header useful information such as segment sizes.
In most cases, the final program file created by clnk is structurally identical to the object module input to clnk. The only difference is that the
executable file is complete and contains everything that it needs to run.
There are a variety of utilities which will take the executable file and
convert it to a form required for execution in specific microcontroller
environments. The linker itself can perform some conversions, if all
that is required is for certain portions of the executable file to be
stripped off and for segments to be relocated in a particular way. You
can therefore create executable programs using the linker that can be
passed directly to a PROM programmer.
Overview
The final output of the linker is a header, followed by all the segments and the symbol table. There may also be an additional
debug symbol table, which contains information used for debugging purposes.
Group 2
(+inc*) is used to include files
Group 3
(+new, +pub and +pri) controls name regions and takes no parameters.
Group 4
(+def <symbol>) is used to define symbols and aliases and takes one
required parameter, a string of the form ident1=ident2, a string of the
form ident1=constant, or a string of the form ident1=@segment.
Group 5
(+spc <segment>) is used to reserve space in a particular <segment>
and has a required parameter
The manner in which the linker relocates the various sections is controlled by the +seg option and its parameters. If the size of a current segment is zero when a command to start a new segment of the same name
is encountered, it is discarded. Several different sections can be redirected directly to the same segment by using the +grp option.
clnk links the <files> you specify in order. If a file is a library, it is
scanned as long as there are modules to load. Only those library modules that define public symbols for which there are currently outstanding unsatisfied references are included.
Linker Options
Linker Options
The linker accepts the following options, each of which is described in
detail below.
clnk [options] <file.lkf> [<files>]
-bs# bank size
-e* error file name
-l*> library path
-m* map file name
-o* output file name
-p
phys addr in map
-s
symbol table only
-sa sort symbol by address
-sl output local symbols
-v
verbose
The output file name and the link command file must be present on
the command line. The options are described in terms of the two groups
listed above; the global options that apply to the linker, and the segment
control options that apply only to specific segments.
Linker Options
-bs#
-e*
log errors in the text file * instead of displaying the messages on the terminal screen.
-l*>
-m*
-o*
-p
-s
-sa
-sl
-v
be verbose.
!! IMPORTANT !!
Applications not using bank switching should specified the -bs0 option to
disabled the internal banking verification.
Linker Options
-a*
-b*
-c
-ck
mark the segment you want to check. For more information, see Checksum Computation on page 310.
-ds#
-e*
-f#
-k
Linker Options
-i?
-it
-id
-ib
-is
-ik
-ic
-m*
-n*
Linker Options
-o*
-r*
round up the starting address of the segment. The expression defines the power of two of the alignment value. The
option -r3 will align the start address to an 8 bytes boundary. This option has no effect if the start address is explicitly defined by a -b option.
-s*
-v
-w*
-x
Linker Options
without any priority and parenthesis () are not allowed. Such expressions CANNOT contain any whitespace. For example:
+def START=0x1000
+def MAXSIZE=0x2000
+seg .text -bSTART+0x100 -mMAXSIZE-0x100
The first line defines the symbol START equals to the absolute value
1000 (hex value), the second line defines the symbol MAXSIZE equals
to the absolute value 2000 (hex value). The last line opens a .text segment located at 1100 (hex value) with a maximum size of 1f00 (hex
value). For more information, see the section Symbol Definition
Option on page 298.
Unless -b* is given to set the bss segment start address, the bss segment
will be made to follow the last data segment in the output file. Unless
-b* is given to set the data segment start address, the data segment will
be made to follow the last bsct segment in the output file. The bsct and
text segments are set to start at zero unless you specify otherwise by
using -b option. It is permissible for all segments to overlap, as far as
clnk is concerned; the target machine may or may not make sense of
this situation (as with separate instruction and data spaces).
NOTE
A new segment of the specified type will not actually be created if the last
segment of the same name has a size of zero. However, the new options
will be processed and will override the previous values.
Segment Grouping
Different sections can be redirected directly to the same segment with
the +grp directive:
Linker Options
NOTE
Whitespaces are not allowed aside the equal sign = and the commas.
Example
Linking objects from the command line:
clnk -o test.h12 test.lkf file1.o file2.o
## Test.lkf:
+seg .text -b0x5000
+seg .data -b0x100
@1
+seg .text -b0x7000
@2
Is equivalent to
clnk -otest.h12 test.lkf
## test.lkf
+seg .text -b0x5000
+seg .data -b0x100
file1.o
+seg .text -b0x7000
file2.o
296 Using The Linker
Linker Options
Include Option
Subparts of the link command file can be included from other files by
using the following option:
+inc*
Example
Include the file seg2.txt in the link file test.lkf:
## Test.lkf:
+seg .text -b0x5000
+seg .data -b0x100
file1.o file2.o
+seg .text -b0x7000
+inc seg2.txt
## seg2.txt:
mod1.o mod2.o mod3.o
## Resultant link file
+seg .text -b0x5000
+seg .data -b0x100
file1.o file2.o
+seg .text -b0x7000
mod1.o mod2.o mod3.o
+new
+pub
+pri
Linker Options
+def*
Linker Options
Section Relocation
NOTE
Whitespaces are not allowed aside the equal sign =.
Section Relocation
The linker relocates the sections of the input files into the segments of
the output file.
An absolute section, by definition, cannot and should not be relocated.
The linker will detect any conflicts between the placement of this file
and its absolute address given at compile/assemble time.
In the case of a bank switched system, it is still possible for an absolute
section to specify a physical address different from the one and at compile/assembly time, the logical address MUST match the one specified
at compile/assemble time.
Address Arithmetic
The two most important parameters describing a segment are its bias
and its offset, respectively its physical and logical start addresses. In
nonsegmented architectures there is no distinction between bias and offset. The bias is the address of the location in memory where the segment is relocated to run. The offset of a segment will be equal to the
bias. In this case you must set only the bias. The linker sets the offset
automatically.
In the paged architecture of the HC12/HCS12, the bias is the physical
address of the start of the segment in question, as seen from memory.
The offset is the logical address of the start of the segment, as seen from
the processor.
The window shift specified by the -bs# option gives a measure of the
resolution used to hold the bias value of a segment. If the value specified by the -bs# option is n, then the resolution is 2**n. For example,
the value of n is 14 for the HC12/HCS12.
In segmented architectures, the fundamental relationship between the
bias and the offset is:
Overlapping Control
The linker is verifying that a segment does not overlap any other one,
by checking the physical addresses (bias). This control can be locally
disabled for one segment by using the -v option. For targets implementing separated address spaces (such as bank switching), the linker allows
several segments to be isolated from the other ones, by giving them a
space name with the -s option. In such a case, a segment in a named
space is checked only against the other segments of the same space. The
unnamed segments are checked together.
Linking Objects
Linking Objects
A new segment is built by concatenating the corresponding sections of
the input object modules in the order the linker encounters them. As
each input section is added to the output segment, it is adjusted to be
relocated relative to the end portion of the output segment so far constructed. The first input object module encountered is relocated relative
to a value that can be specified to the linker. The size of the output bss
segment is the sum of the sizes of the input bss sections.
Unless the -v option has been specified on a segment definition, the
linker checks that the segment physical address range does not overlap
any other segment of the application. Logical addresses are not checked
as bank switching creates several segments starting at the same logical
address.
libf.h12
NOTE
The +sprec compiler option MUST be used if you want to use the Single
Precision library in order to suppress normal ANSI float to double promotions.
libi.h12
Integer only Library. This library is designed for applications where no floating point is used. Floats can still be
used for arithmetic but not with the standard library. Link
this library before the other libraries when only integer
libraries are needed.
Machine
Library
Libm.h12
DP256
eeprom
Library
Libe.h12
Integer
Only
Library
libi.h12
Single
Precision
Floats
libf.h12
Double
Precision
Floats
libd.h12
NOTE
Compiler libraries must be located in a non-banked area of memory or
duplicated in each bank that uses them.
Library Order
You should link your application with the libraries in the following
orders:
Integer Only
Application
(libe.h12)
(libe.h12)
(libe.h12)
libi.h12
libf.h12
libd.h12
libm.h12
libi.h12
libi.h12
libm.h12
libm.h12
NOTE
The libe.h12 is only necessary when building applications using eeprom
functions and targeting the DP256 derivative.
For more information, see Linker Command Line Examples on page
320.
Bank Switching
Bank Switching
The linker is able to build banked segments for large applications. Such
banks can be built explicitly, or automatically. A banked segment is
described by a physical start address, specified by the -b option, a logical start address, specified by the -o option, and a window size. The logical address is the processor address, and should match the windowed
area (0x8000 to 0xbfff for the HC12/HCS12). The physical address is
the memory address and should match the hardware specifications.
A single bank is defined by using the -b and -o only. The bank size
should be specified by the -m option to check any bank overflow. Several banks can be defined by several independent segment directives.
Multiple banks are automatically defined by using the -b, -o and -w
options. The bank size is defined by the -w option which also sets up
the automatic filling mechanism. The -m option still can be used, but
then defines the maximum available space for all the possible consecutive banks. When automatic filling is activated, a new segment is started
when the current bank size exceeds the value given by the -w option.
The new bank physical start address is obtained by adding the window
size to the current bank physical start address. The new logical start
address is equal to the current bank logical start address. If a maximum
size has been specified for the current bank by the -m option, a maximum size is defined for the new bank with a new value obtained by substracting the window size to the current bank maximum size.
Here is an example for a link file using single banks:
# Link for EPROM
+seg .data -b0x2000
# start data address
+seg .text -b 0x10000 -o 0x8000 -m 0x4000
func1.o func2.o func3.o
+seg .text -b 0x14000 -o 0x8000 -m 0x4000
func4.o func5.o func6.o
+seg .text -b0xc000 -o0xc000 -n.text# start eprom address
+seg .const -a .text
# constants follow code
\cx\lib\crts.h12
# startup object file
mod1.o mod2.o
# input object files
\cx\lib\libi.h12
# C library
\cx\lib\libm.h12
# machine library
+seg .const -b0xffce
# vectors eprom address
vectors.o
# reset and interrupt vectors
Bank Switching
The following link file shows the use of a multiple banks: the -w option
specifies a size of the window (0x4000). In this case, when the current
bank size exceeds, a new segment is created with a logical start address
of 0x8000, and the new physical address will be 0xc000.
# Link for EPROM
+seg .data -b0x2000
# start data address
+seg .text -b 0x10000 -o 0x8000 -m 0x8000 -w0x4000
func1.o func2.o func3.o
func4.o func5.o func6.o
+seg .text -b0xc000 -o0xc000 -n.text# start eprom address
+seg .const -a .text
# constants follow code
\cx\lib\crts.h12
# startup object file
mod1.o mod2.o
# input object files
\cx\lib\libi.h12
# C library
\cx\lib\libm.h12
# machine library
+seg .const -b0xffce
# vectors eprom address
vectors.o
# reset and interrupt vectors
The linker also verifies that a bank is properly entered with a call
instruction. Any attempt to enter a bank with a jsr instruction will be
reported as an error, unless the jsr is issued from the same bank.
Descriptor Format
The created descriptor has the following format:
dc.w start_prom_address
; for
dc.b
dc.w
dc.w
each segment:
flag
start_ram_address
end_prom_address
segment type
start address of segment in ram
address of last data byte
plus one in prom
The flag byte is used to detect the end of the descriptor, and also to
specify a type for the data segment. The actual value is equal to the
code of the first letter in the segment name.
The end address in PROM of one segment gives also the starting
address in prom of the following segment, if any.
Moveable Code
Moveable Code
The linker allows a code segment to be stored in the ROM part, but
linked at another address which is supposed to be located in RAM. This
feature is specially designed to allow an application to run FLASH programming routines from the RAM space. This feature is sharing the
same global mechanism than initialized data, and the common descriptor built by the linker contains both record types. The flag byte is used
to qualify each entry. In order to implement such a feature, the link
command file should contain a dedicated code segment marked with the
-ic option:
#
LINKER EXAMPLE FOR MOVEABLE CODE
#
# mark this segment with -ic and link it at RAM address
#
+seg .text -b 0x100 -n boot -ic
flash.o
+seg .text -b 0x8000 -n code# application code
file.o
...
The function contained in the object flash.o is now linked at the RAM
address 0x100 but stored somewhere in the code space along with any
other initialized data. It is not necessary to link the application with the
startup routine crtsi.s if the application does not contain initialized data
but the descriptor will be built as soon as a moveable function is used
by the application, but if the crtsi.s startup is used, moveable code segments are not copied in RAM at the application start up.
In order to use such a function, it is necessary to first copy it from ROM
to RAM. This is done by calling the library function _fctcpy() with one
Checksum Computation
Checksum Computation
This feature is activated by the detection of the symbol __ckdesc__ as
an undefined symbol. This is practically done by calling one of the provided checksum functions which uses that symbol and returns 0 if the
checksum is correct. These functions are provided in the integer library
and are the following:
_checksum()
_checksumx()
_checksum16()
_checksum16x()
You then have to update the link command file in two ways:
310 Using The Linker
Checksum Computation
Special Topics
a DEF if that symbol is not already entered in the symbol table; its
value is adjusted to reflect how the linker is relocating the input object
module in which it occurred. If it is present as a REF, the entry is
changed to a DEF and the symbols adjusted value is entered in the
symbol table entry. If it is present as a DEF, an error occurs (multiply
defined symbol).
When the linker is processing a library, an object module in the library
becomes an input object module to the linker only if it has at least one
DEF which satisfies some outstanding REF in the linker's internal symbol table. Thus, the simplest use of clnk is to combine two files and
check that no unused references remain.
The executable file created by the linker must have no REFs in its symbol table. Otherwise, the linker emits the error message undefined symbol and returns failure.
Special Topics
This section explains some special linker capabilities that may have
limited applicability for building most kinds of microcontroller applications.
Special Topics
Any symbols defined in <public files> are known outside this private
name region. Any symbols defined in <private libraries> are known
only within this region; hence they may safely be redefined as private to
other regions as well.
NOTE
All symbols defined in a private region are local symbols and will not
appear in the symbol table of the output file.
Renaming Symbols
At times it may be desirable to provide a symbol with an alias and to
hide the original name (i.e., to prevent its definition from being used by
the linker as a DEF which satisfies REFs to that symbol name). As an
example, suppose that the function func in the C library provided with
the compiler does not do everything that is desired of it for some special
application. There are three methods of handling this situation (we will
ignore the alternative of trying to live with the existing functions deficiencies).
The first method is to write a new version of the function that performs
as required and link it into the program being built before linking in the
libraries. This will cause the new definition of func to satisfy any references to that function, so the linker does not include the version from
the library because it is not needed. This method has two major drawbacks: first, a new function must be written and debugged to provide
something which basically already exists; second, the details of exactly
what the function must do and how it must do it may not be available,
thus preventing a proper implementation of the function.
The second approach is to write a new function, say my_func, which
does the extra processing required and then calls the standard function
func. This approach will generally work, unless the original function
func is called by other functions in the libraries. In that case, the extra
function behavior cannot occur when func is called from library functions, since it is actually my_func that performs it.
Special Topics
The third approach is to use the aliasing capabilities of the linker. Like
the second method, a new function will be written which performs the
new behavior and then calls the old function. The twist is to give the old
function a new name and hide its old name. Then the new function is
given the old functions name and, when it calls the old function, it uses
the new name, or alias, for that function. The following linker script
provides a specific example of this technique for the function func:
line
line
line
line
line
line
line
line
line
1
2
3
4
5
6
7
8
9
NOTE
The function name func as referenced here is the name as seen by the C
programmer. The name which is used in the linker for purposes of aliasing is the name as seen at the object module level. For more information
on this transformation, see the section Interfacing C to Assembly Language in Chapter 3.
The main thing to note here is that func.o and new_func.o both define a
(different) function named func. The second function func defined in
newfunc.o calls the old func function by its alias oldfunc.
Name regions provide limited scope control for symbol names. The
+new command starts a new name region, which will be in effect until
the next +new command. Within a region there are public and private
name spaces. These are entered by the +pub and +pri commands; by
default, +new starts in the public name space.
Lines 1,2 are the basic linker commands for setting up a separate I/D
program. Note that there may be other options required here, either by
the system itself or by the user.
Line 3 starts a new region, initially in the public name space.
Special Topics
Line 4 specifies the startup code for the system being used.
Line 5 establishes the symbol _oldfunc as an alias for the symbol _func.
The symbol _oldfunc is entered in the symbol table as a public definition. The symbol _func is entered as a private reference in the current
region.
Line 6 switches to the private name space in the current region. Then
func.o is linked and provides a definition (private, of course) which satisfies the reference to _func.
Line 7 starts a new name region, which is in the public name space by
default. Now no reference to the symbol _func can reach the definition
created on Line 6. That definition can only be reached now by using the
symbol _oldfunc, which is publicly defined as an alias for it.
Line 8 links the user program and the module newfunc.o, which provides a new (and public) definition of _func. In this module the old version is accessed by its alias. This new version will satisfy all references
to _func made in prog.o and the libraries.
Line 9 links in the required libraries.
The rules governing which name space a symbol belongs to are as follows:
All private definitions of a symbol must occur before a public definition of that symbol. After a public definition of a symbol, any
other definition of that symbol will cause a multiply defined symbol error.
Special Topics
Any new reference is associated with the region in which the reference is made. It can be satisfied by a private definition in that
region, or by a public definition. A previous definition of that
symbol will satisfy the reference if that definition is public, or if
the definition is private and the reference is made in the same
region as the definition.
The first link builds the application itself using the appli.lkf command
file. The second link uses the same command file and creates an object
Special Topics
file containing only an absolute symbol table. This file can then be used
as an input object file in any other link command file.
Segment Describe the different segments which compose the application, specifying for each of them: the start address (in
hexa), the end address (in hexa), the length (in decimal),
and the name of the segment. Note that the end value is the
address of the byte following the last one of the segment,
meaning that an empty segment will have the same start
and end addresses. If a segment is initialized, it is displayed twice, the first time with its final address, the second time with the address of the image copy.
Modules List all the modules which compose the application, giving
for each the description of all the defined sections with the
same format as in the Segment section. If an object has
been assembled with the -pl option, local symbols are displayed just after the module description.
Stack Usage Describe the amount of memory needed for the stack.
Each function of the application is listed by its name, followed by a > character indicating that this function is not
called by any other one (the main function, interrupt functions, task entries...). The first number is the total size of
the stack used by the function including all the internal
calls. The second number between braces shows the stack
need for that function alone. The entry may be flagged by
the keyword Recursive meaning that this function is
itself recursive or is calling directly or indirectly a recursive function, and that the total stack space displayed is not
accurate. The linker may detect potential but not actual
recursive functions when such functions are called by
pointer.The linker displays at the end of the list a total
stack size assuming interrupt functions cannot be themselves interrupted. Interrupt frames and machine library
calls are properly counted.
Return Value
Return Value
clnk returns success if no error messages are printed to STDOUT; that
is, if no undefined symbols remain and if all reads and writes succeed.
Otherwise it returns failure.
automatic init
# program start address
# constants follow program
# start data address
# symbol used by startup
# startup with auto-init
# main program
# module program
# single prec.
# integer lib.
# machine lib.
# vectors eprom address
# reset & interrupt vectors
# end of bss segment
# stack pointer initial value
CHAPTER
7
Debugging Support
This chapter describes the debugging support available with the cross
compiler targeting the HC12/HCS12. There are two levels of debugging
support available, so you can use either the COSMICs Zap C source
level cross debugger or your own debugger or in-circuit emulator to
debug your application. This chapter includes the following sections:
where <file> is an object file compiled from C source with the compiler command line option +debug set.
-fc*
-fl*
-o*
print debugging information to file *. Debugging information is written to your terminal screen by default.
-r
-s
Examples
The following example show sample output generated by running the
cprd utility on an object file created by compiling the program acia.c
with the compiler option +debug set.
cprd acia.h12
Information extracted from acia.h12
source file acia.c:
unsigned char buffer[512] at 0x0804
unsigned char *ptlec at 0x0802
unsigned char *ptecr at 0x0800
unsigned char getch() lines 26 to 36 at 0xf016-0xf02b
auto unsigned char c at -1 from frame pointer
void outch() lines 40 to 45 at 0xf02c-0xf032
argument unsigned char c at 1 from frame pointer
void recept() lines 51 to 57 at 0xf033-0xf047
(no locals)
void main() lines 63 to 71 at 0xf048-0xf061
(no locals)
source file vectors.c:
void (*_vectab[25])() at 0x3ffce
-a
-f*>
-i*>
-l#
-o*
redirect output from clst to file *. You can achieve a similar effect by redirecting output in the command line.
clst -o acia.lst acia.h12
is equivalent to:
clst acia.h12 >acia.lst
-p
-r#:#
CHAPTER
8
Programming Support
This chapter describes each of the programming support utilities packaged with the C cross compiler targeting the HC12/HCS12. The following utilities are available:
cbank
chex
clabs
clib
cobj
cv695
cvdwarf
-m#
-n*
-o*
-w##
Return Status
cbank returns success if no error messages are printed. Otherwise it
returns failure.
Examples
The following command:
cbank -o bk_list -w 0x1000 obj_list
will generate bk_list as the result file, with a page window of size
0x1000 from the given list obj_list which contains:
file1.o
file2.o
file3.o
file4.o
The first value is the space used in the bank, and the second value is the
bank size.
Bank start addresses can be included into the input file, such as:
-b0x10000 -o 0x8000 -n bank1
-b0x18000 -o 0x8000 -n bank2
-b0x20000 -o 0x8000 -n bank3
file1.o
file2.o
file3.o
file4.o
-a##
-b##
-e##
define ## as the entry point address encoded in the dedicated record of the output format, if available.
-f?
Motorola S2 format
Motorola S3 format
-h
+h*
-m#
-n*>
-o*
-p
-pl##
-pn
-pp
behaves as -p but uses paged addresses for all banked segments, mapped or unmapped. This option has to be selectd
when producing an hex file for Promic tools.
-s
-x*>
Return Status
chex returns success if no error messages are printed; that is, if all
records are valid and all reads and writes succeed. Otherwise it returns
failure.
Examples
The file hello.c, consisting of:
char *p = {hello world};
-a
-cl*
-l
-p
-pn
-pp
behaves as -p but uses paged addresses for all banked segments, mapped or unmapped.
-r*
specify the input suffix, including or not the dot . character. Default is .ls
-s*
specify the output suffix, including or not the dot . character. Default is .la
-v
Return Status
clabs returns success if no error messages are printed; that is, if all reads
and writes succeed. An error message is output if no relocatable listing
files are found. Otherwise it returns failure.
Examples
The following command line:
clabs -v acia.h12
will output:
crts.ls
acia.ls
vector.ls
will generate:
crts.lx
acia.lx
vector.lx
-a
-c
-d
-i*
take object files from a list *. You can put several files per
line or put one file per line. Each lines can include comments. They must be prefixed by the # character. If the
command line contains <files>, then <files> will be also
added to the library.
-l
when a library is built with this flag set, all the modules of
the library will be loaded at link time. By default, the
linker only loads modules necessary for the application.
-r
-s
-t
-v
be verbose
-x
At most one of the options -[c r t x] may be specified at the same time.
If none of these is specified, the -t option is assumed.
Return Status
clib returns success if no problems are encountered. Otherwise it
returns failure. After most failures, an error message is printed to
STDERR and the library file is not modified. Output from the -t, -s
options, and verbose remarks, are written to STDOUT.
Examples
To build a library and check its contents:
clib -c libc one.o two.o three.o
clib -t libc
will output:
one.o
two.o
three.o
-d
-h
-n
-o*
-r
-s
-v
-x
Return Status
cobj returns success if no diagnostics are produced (i.e. if all reads are
successful and all file formats are valid).
Examples
For example, to get the symbol table:
cobj -s acia.o
symbols:
_main:
_outch:
_buffer:
_ptecr:
_getch:
_ptlec:
_recept:
0000003e
0000001b
00000000
00000000
00000000
00000002
00000028
section
section
section
section
section
section
section
The information for each symbol is: name, address, section to which it
belongs and attribute.
-V4
+bit
-dpage
-d
-mod?
+old
-o*
+page#
for no paging.
for
pages
with
banked
addresses
<page><offset_in_page>
-rb
-v
Return Status
cv695 returns success if no problems are encountered. Otherwise it
returns failure.
Examples
Under MS/DOS, the command could be:
cv695 C:\test\basic.h12
-bp#
-bs#
-loc
-o*
+page#
-rb
-v
Return Status
cvdwarf returns success if no problems are encountered. Otherwise it
returns failure.
Examples
Under MS/DOS, the command could be:
cvdwarfC:\test\basic.h12
APPENDIX
A
Compiler Error
Messages
This appendix lists the error messages that the compiler may generate in
response to errors in your program, or in response to problems in your
host system environment, such as inadequate space for temporary intermediate files that the compiler creates.
The first pass of the compiler generally produces all user diagnostics.
This pass deals with # control lines and lexical analysis, and then with
everything else having to do with semantics. Only machine-dependent
extensions are diagnosed in the code generator pass. If a pass produces
diagnostics, later passes will not be run.
Any compiler message containing an exclamation mark ! or the word
PANIC indicates that the compiler has detected an inconsistent internal state. Such occurrences are uncommon and should be reported to
the maintainers.
bad #endif - a #endif occurs without a previous #if, #ifdef, #ifndef, #elif
or #else
bad #if expression - the expression part of a #if is not a constant
expression
bad #ifdef syntax - extra characters are found after the symbol name
bad #ifndef syntax - extra characters are found after the symbol name
bad #include syntax - extra characters are found after the file name
bad #pragma section directive - syntax for the #pragma section directive is incorrect
bad #pragma space directive - syntax for the #pragma space directive
is incorrect
bad #undef syntax - #undef is not followed by an identifier
bad _asm() argument type - the first argument passed to _asm is missing or is not a character string
bad alias expression - alias definition is not a valid expression
bad alias value - alias definition is not a constant expression
bad bit number - a bit number is not a constant between 0 and 7
bad character <character> - <character> is not part of a legal token
bad defined syntax - the defined operator must be followed by an identifier, or by an identifier enclosed in parenthesis
bad function declaration - function declaration has not been terminated by a right parenthesis
bad integer constant - an invalid integer constant has been specified
bad invocation of macro <name> - a #define macro defined without
arguments has been invoked with arguments
invalid bitfield type - a type other than int, unsigned int, char,
unsigned char has been used in a bitfield.
invalid break - a break may be used only in while, for, do, or switch
statements
invalid case operand - a case label has to be followed by a constant
expression
invalid cast operand - the operand of a cast operator in not an expression
invalid cast type - a cast has been applied to an object that cannot be
coerced to a specific type
invalid conditional operand - the operands of a conditional operator
are not compatible
invalid constant expression - a constant expression is missing or is not
reduced to a constant value
invalid continue - a continue statement may be used only in while, for,
or do statements
invalid do test type - the expression of a do ... while() instruction is not
a testable expression
invalid expression - an incomplete or ill-formed expression has been
detected
invalid external initialization - an external object has been initialized
invalid floating point operation - an invalid operator has been applied
to floating point operands
invalid for test type - the second expression of a for(;;) instruction is
not a testable expression
invalid function member - a function has been declared within a structure or an union
invalid function type - the function call operator () has been applied to
an object which is not a function or a pointer to a function
invalid if test type - the expression of an if () instruction is not a testable expression
invalid indirection operand - the operand of unary * is not a pointer
invalid line number - the first parameter of a #line directive is not an
integer
invalid local initialization - the initialization of a local object is incomplete or ill-formed
invalid lvalue - the left operand of an assignment operator is not a variable or a pointer reference
invalid narrow pointer cast - a cast operator is attempting to reduce
the size of a pointer
invalid operand type - the operand of a unary operator has an incompatible type
invalid pointer cast operand - a cast to a function pointer has been
applied to a pointer that is not a function pointer
invalid pointer initializer - initializer must be a pointer expression or
the constant expression 0
invalid pointer operand - an expression which is not of integer type
has been added to a pointer
invalid pointer operation - an illegal operator has been applied to a
pointer operand
invalid pointer types - two incompatible pointers have been substracted
invalid shift count type - the right expression of a shift operator is not
an integer
invalid sizeof operand type - the sizeof operator has been applied to a
function
invalid storage class - storage class is not legal in this context
invalid struct/union operation - a structure or an union has been used
as operand of an arithmetic operator
invalid switch test type - the expression of a switch () instruction must
be of integer type
invalid typedef usage - a typedef identifier is used in an expression
invalid void pointer - a void pointer has been used as operand of an
addition or a substraction
invalid while test type - the expression of a while () instruction is not a
testable expression
missing ## argument in macro <name> - an argument of a ## operator in a #define macro is missing
missing > in #include - a file name of a #include directive begins
with < and does not end with >
missing ) in defined expansion - a ( does not have a balancing ) in a
defined operator
missing ; in argument declaration - the declaration of a function argument does not end with ;
missing ; in local declaration - the declaration of a local variable does
not end with ;
missing ; in member declaration - the declaration of a structure or
union member does not end with ;
missing ? test expression - the test expression is missing in a ternary
operator (? :)
missing _asm() argument - the _asm function needs at least one argument
360 Compiler Error Messages
bad string constant - a character constant does not end with a single or
double quote
bad symbol name: <name> - an expected symbol is not an identifier
can't create <name> - the file <name> cannot be opened for writing
can't open <name> - the file <name> cannot be opened for reading
can't open source <name> - the file <name> cannot be included
cannot include from a macro - the directive include cannot be specified within a macro definition
cannot move back current pc - an org directive has a negative offset
illegal size - the size of a ds directive is negative or zero
missing label - a label must be specified for this directive
missing operand - operand is expected for this instruction
missing register - a register is expected for this instruction
missing string - a character string is expected for this directive
relocatable expression not allowed - a constant is needed
section name <name> too long - a section name has more than 15
characters
string constant too long - a string constant is longer than 255 characters
symbol <name> already defined - attempt to redefine an existing
symbol
symbol <name> not defined - a symbol has been used but not declared
syntax error - an unexpected identifier or operator has been found
too many arguments - a macro has been invoked with more than 9
arguments
368 Compiler Error Messages
APPENDIX
B
Modifying Compiler
Operation
This chapter tells you how to modify compiler operation by making
changes to the standard configuration file. It also explains how to create
your own programmable options which you can use to modify compiler operation from the cx6812.cxf.
-m pgff:,t1,,na,std
-m std:,t0,,na,pgff
-o
-o
-o
-o
The first field defines the option name and must be ended by a colon
character :. The four next fields describe the effect of this option on
the four passes of the compiler, respectively the parser, the generator,
the optimizer and the assembler. These fields are separated by a comma
character ,. If no specific option is needed on a pass, the field has to be
specified empty. The remaining fields, if specified, describe a exclusive
relationship with other defined options. If two exclusive options are
specified on the command line, the compiler will stop with an error
message. You may define up to 20 programmable options. At least one
Example
field has to be specified. Empty fields need to be specified only if a useful field has to be entered after.
In the following example:
-m dl1:l,dl1,,,dl2# dl1: line option 1
-m dl2:l,dl2,,,dl1# dl1: line option 2
the two options dl1 and dl2 are defined. If the option +dl1 is specified
on the compiler command line, the specific option -l will be used for the
parser and the specific option -dl1 will be used for the code generator.
No specific option will be used for the optimizer and for the assembler.
The option dl1 is also declared to be exclusive with the option dl2,
meaning that dl1 and dl2 will not be allowed together on the compiler
command line. The option dl2 is defined in the same way.
Example
The following command line
cx6812 +nobss +rev hello.c
APPENDIX
C
HC12/HCS12 Machine
Library
This appendix describes each of the functions in the Machine Library
(libm). These functions provide the interface between the HC12/
HCS12 microcontroller hardware and the functions required by the
code generator. They are described in reference form, and listed alphabetically.
Note that machine library functions return values as follows:
integer in D register.
longs and floats in a register pair (float register or long register depending on context) whose low word is the D register and
whose high word is in the X register.
far pointer in a register pair whose low word (offset) is the X register and whose high word is the D register, the page number in A
register, B register beeing always zero.
In the functions description below, left and right refer to left and right
operands, or first and second operands, of library functions.
2004 COSMIC Software
C Library - c_bfget
c_bfget
Description
Get a long bitfield
Syntax
; raw value in long register
jsr c_bfget
dc.l mask
; result in long register
Function
c_bfget is extracting a long bitfield from the value loaded in the long
register using the mask specified in the program memory just after the
jsr instruction.
Returns
The resulting value is in long register.
See Also
c_bfput
C Library - c_bfput
c_bfput
Description
Store a long bitfield
Syntax
; value in long register
; pointer to bitfield in y register
jsr c_bfput
dc.l mask
; result in long register
Function
c_bfput is storing a long bitfield at the address loaded in the Y register
by shifting and masking the long register from a mask specified in the
program memory just after the jsr instruction.
Returns
Nothing.
See Also
c_bfget
C Library - c_check
c_check
Description
Check stack growth
Syntax
leay #<size>,s
jsr c_check
Function
c_check is used to check that the stack pointer is not overwriting valid
data in memory. Users must write their own check functions, because
the memory map is application-dependent. The value in Y is the new
stack pointer value.
Returns
c_check returns only if the stack pointer is correct. Otherwise, the
behavior is user-dependent. c_check is called when the -ck flag is specified (raised) to the code generator (cg6812). This option produces
larger and slower code. It should only be used for test and debugging.
The libraries provided with the compiler include a version of c_check
that always returns. It may be used as a template for user-written versions of this function.
C Library - c_dadd
c_dadd
Description
Add double to double
Syntax
; pointer to left in x register
; pointer to right in y register
jsr c_dadd
; result in left
Function
c_dadd adds the double in left to the double in right. No check is made
for overflow.
Returns
The resulting value is in left. Flags have no meaningful value upon
return.
See Also
c_dsub
C Library - c_dcmp
c_dcmp
Description
Compare double with double
Syntax
; pointer to left in x register
; pointer to right in y register
jsr c_dcmp
; result in flags
Function
c_dcmp compares the double in left with the double in right.
Returns
The N and Z flags are set to reflect the value of (left-right).
C Library - c_ddiv
c_ddiv
Description
Divide double by double
Syntax
; pointer to left in x register
; pointer to right in y register
jsr c_ddiv
; result in left
Function
c_ddiv divides the double in left by the double in right.
Returns
The resulting value is in left. A zero divide leaves the operand
unchanged. Flags have no meaningful value upon return.
C Library - c_dmul
c_dmul
Description
Multiply double by double
Syntax
; pointer to left in x register
; pointer to right in y register
jsr c_dmul
; result in left
Function
c_dmul multiplies the double in left by the double in right.
Returns
The resulting value is in left. Flags have no meaningful value upon
return.
C Library - c_dneg
c_dneg
Description
Negate a double
Syntax
; pointer to operand in y register
jsr c_dneg
; result in operand
Function
c_dneg negates the double pointed at by the Y register.
Returns
The result stays in operand. The flags are not significant on return.
C Library - c_dsmov
c_dsmov
Description
Move a structure in DPAGE space
Syntax
; source address on the stack
; destination address in X:D
ldy #<size>
jsr c_dsmov
Function
c_dsmov moves a structure inside the DPAGE data space. Both source
and destination addresses are far pointer, pointer to source is on the
stack, and pointer to destination is in the register pair X:D. The structure size is in the Y register.
See Also
c_esmov
C Library - c_dsub
c_dsub
Description
Subtract double from double
Syntax
; pointer to left in x register
; pointer to right in y register
jsr c_dsub
; result in left
Function
c_dsub subtracts the double in right from the double in left. No check is
made for overflow.
Returns
The resulting value is in left. Flags have no meaningful value upon
return.
See Also
c_dadd
C Library - c_dtod
c_dtod
Description
Copy a double into a double
Syntax
; pointer to left in x register
; pointer to right in y register
jsr c_dtod
; result in left
Function
c_dtod copies the double in right to left.
Returns
The right value is in left. Flags have no meaningful value upon return.
C Library - c_dtof
c_dtof
Description
Convert double to float
Syntax
; pointer to double in y register
jsr c_dtof
; result in float register
Function
c_dtof converts the double pointed at by Y to a float in the float register.
No check is made for overflow.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
C Library - c_dtoi
c_dtoi
Description
Convert double to integer
Syntax
; pointer to operand in y register
jsr c_dtoi
; result in d
Function
c_dtoi converts the double pointed at by Y to a two byte integer in D.
No check is made for overflow.
Returns
The resulting value is in D and flags are set accordingly.
C Library - c_dtol
c_dtol
Description
Convert double into long integer
Syntax
; pointer to double in y register
jsr c_dtol
; result in long register
Function
c_dtol converts the double in memory pointed at by Y to a long in the
long register. No check is made for overflow.
Returns
The resulting value is in the long register.
C Library - c_dtos
c_dtos
Description
Copy a double onto the stack
Syntax
; pointer to double in y register
jsr c_dtos
Function
c_dtos copies the double pointed to by Y onto the stack.
Returns
c_dtos returns nothing; the stack is updated.
C Library - c_eewbfb
c_eewbfb
Description
Eeprom char bit field update
Syntax
ldb
ldy
jsr
dc.b
#value
#address
c_eewbfb
<mask>
Function
c_eewbfb updates a char bit field (8 bits sized) located in eeprom with a
new value. The new value is in B and is right justified. The byte address
in eeprom is in Y, and the mask, giving the bit field size and location, is
a byte located in memory just after the call. The function waits for the
time necessary to program the new value.
See Also
c_eewbfd, c_eewbfx, c_eewstx, c_eewsty
C Library - c_eewbfd
c_eewbfd
Description
Eeprom short bit field update
Syntax
ldd
ldy
jsr
dc.w
#value
#address
c_eewbfd
<mask>
Function
c_eewbfd updates a short bit field (16 bits sized) located in eeprom
with a new value. The new value is in D and is right justified. The word
address in eeprom is in Y, and the mask, giving the bit field size and
location, is a word located in memory just after the call. The function
waits as required to program the new value.
See Also
c_eewbfb, c_eewbfx, c_eewstx, c_eewsty
C Library - c_eewbfx
c_eewbfx
Description
Eeprom long bit field update
Syntax
; value in
ldy
jsr
dc.w
long register
#address
c_eewbfx
<mask>
Function
c_eewbfx updates a long bit field (32 bits sized) located in eeprom with
a new value. The new value is in X:D and is right justified. The long
address in eeprom is in Y, and the mask, giving the bit field size and
location, is a word located in memory just after the call. The function
waits as required to program the new value.
See Also
c_eewbfb, c_eewbfd, c_eewstx, c_eewsty
C Library - c_eewra
c_eewra
Description
Write a short int aligned in eeprom
Syntax
ldd
ldy
jsr
#value
#address
c_eewra
Function
c_eewra writes a short int in eeprom. The new value is in D, and its
address in eeprom is in Y, and is assumed to be even allowing the full
word to be programmed with one single cycle.
See Also
c_eewrc, c_eewrd, c_eewrl, c_eewrw
C Library - c_eewrc
c_eewrc
Description
Write a char int in eeprom
Syntax
ldb
ldy
jsr
#value
#address
c_eewrc
Function
c_eewrc writes a byte in eeprom. The new byte value is in B and its
address in eeprom is in Y. The function tests if the erasure is necessary,
and it performs only in that case. Then if the new value is different from
the one in eeprom, the new byte is programmed. The function waits for
the time necessary to correctly program the byte. The delay function
included in this module assumes that the clock frequency is 8 Mhz. The
function does not test if the byte address is in the address range corresponding to the existing eeprom.
See Also
c_eewra, c_eewrd, c_eewrl, c_eewrw
C Library - c_eewrd
c_eewrd
Description
Write a double in eeprom
Syntax
; pointer to destination in x register
; pointer to source in y register
jsr c_eewrd
Function
c_eewrd writes a double in eeprom. If the destination address is even,
all words are programmed by the c_eewra function. Otherwise, the first
and last bytes are programmed by the c_eewrc function, and the middle
words are programmed by the c_eewra function. The function waits as
required to program all the bytes.
See Also
c_eewra, c_eewrc, c_eewrl, c_eewrw
C Library - c_eewrl
c_eewrl
Description
Write a long int in eeprom
Syntax
; value in long register
ldy #address
jsr c_eewrl
Function
c_eewrl writes a long int in eeprom. The new value is in the long register, and its address in eeprom is in Y. If the destination is even, each
word is written by the c_eewra function. Otherwise, the first and last
bytes are programmed independently by the c_eewrc function, and the
middle word is programmed by the c_eewra function. The function
waits as required to program all the bytes.
See Also
c_eewra, c_eewrc, c_eewrd, c_eewrw
C Library - c_eewrw
c_eewrw
Description
Write a short int in eeprom
Syntax
ldd
ldy
jsr
#value
#address
c_eewrw
Function
c_eewrw writes a short int in eeprom. The new value is in D, and its
address in eeprom is in Y. If the destination address is even, the word is
programmed directly by a single programming cycle. Otherwise, each
byte is programmed independently by the c_eewrc function.
See Also
c_eewra, c_eewrc, c_eewrd, c_eewrl
C Library - c_eewstx
c_eewstx
Description
Move a structure in eeprom
Syntax
ldy
ldx
ldd
jsr
#source_address
#destination_address
#<size>
c_eewstx
Function
c_eewstx moves a structure into an eeprom memory location.Pointer to
source is in Y, and pointer to destination is in X. The structure size is
given by a word located in the D register. Depending on the size and the
destination address alignment, as many words as possible are programmed by the c_eewra function. Remainning bytes are programmed
by the c_eewrc function.
See Also
c_eewbfb, c_eewbfd, c_eewbfx, c_eewra, c_eewrc, c_eewsty
C Library - c_eewsty
c_eewsty
Description
Move a structure in eeprom
Syntax
ldx
ldy
ldd
jsr
#source_address
#destination_address
#<size>
c_eewsty
Function
c_eewsty moves a structure into an eeprom memory location.Pointer to
source is in X, and pointer to destination is in Y. The structure size is
given by a word located in the D register. Depending on the size and the
destination address alignment, as many words as possible are programmed by the c_eewra function. Remainning bytes are programmed
by the c_eewrc function.
See Also
c_eewbfb, c_eewbfd, c_eewbfx, c_eewra, c_eewrc, c_eewstx
C Library - c_emuld
c_emuld
Description
Multiply signed int by unsigned int
Syntax
; signed int in d register
; unsigned int in y register
jsr c_emuld
; long result in y:d register pair
Function
c_emuld multiplies the signed int value in the D register by the
unsigned int value in the Y register. The 32 bits result is stored in the
register pair Y:D.
See Also
c_emuly
C Library - c_emuly
c_emuly
Description
Multiply unsigned int by signed int
Syntax
; unsigned int in d register
; signed int in y register
jsr c_emuly
; long result in y:d register pair
Function
c_emuly multiplies the unsigned int value in the D register by the
signed int value in the Y register. The 32 bits result is stored in the register pair Y:D.
See Also
c_emuld
C Library - c_esmov
c_esmov
Description
Move a structure in EPAGE space
Syntax
; source address on the stack
; destination address in x:d
ldy #<size>
jsr c_esmov
Function
c_esmov moves a structure inside the EPAGE data space. Both source
and destination addresses are far pointer, pointer to source is on the
stack, and pointer to destination is in the register pair X:D. The structure size is in the Y register.
See Also
c_dsmov
C Library - c_fadd
c_fadd
Description
Add float to float
Syntax
; left in float register
; pointer to right in y register
jsr c_fadd
; result in float register
Function
c_fadd adds the float in float register to the float indicated by the
pointer in Y. No check is made for overflow.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
See Also
c_fsub
C Library - c_fcmp
c_fcmp
Description
Compare floats
Syntax
; left in float register
; pointer to right in y register
jsr c_fcmp
; result in flags
Function
c_fcmp compares the float in the float register with the float pointed at
by the Y register.
Returns
The N and Z flags are set to reflect the value (left-right).
C Library - c_fdiv
c_fdiv
Description
Divide float by float
Syntax
; left in float register
; pointer to right in y register
jsr c_fdiv
; result in float register
Function
c_fdiv divides the float in the float register by the float pointed to by the
Y register.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
C Library - c_fgadd
c_fgadd
Description
Float addition
Syntax
; pointer to left in y register
; right in float register
jsr c_lgadd
; result in left
Function
c_fgadd performs the float addition of the value pointed at by Y and the
value in the float register.
Returns
The result is stored at the location pointed at by the Y register.
C Library - c_fgdiv
c_fgdiv
Description
Float division
Syntax
; pointer to left in y register
; right in float register
jsr c_fgdiv
; result in left
Function
c_fgdiv performs the float division of the value pointed at by the Y register by the value in float register.
Returns
The result is stored in the location pointed at by Y.
C Library - c_fgmul
c_fgmul
Description
Float multiplication
Syntax
; pointer to left in y register
; right in float register
jsr c_fgmul
; result in left
Function
c_fgmul performs the float multiplication of the value pointed at by the
Y register by the value in float register.
Returns
The result is stored in the location pointed at by Y.
C Library - c_fgsub
c_fgsub
Description
Float subtraction
Syntax
; pointer to left in y register
; right operand in float register
jsr c_fgsub
; result in left
Function
c_fgsub evaluates the (float) difference between the value pointed at by
the Y register and the value in float register
Returns
The result is stored in the location pointed at by Y.
C Library - c_fmul
c_fmul
Description
Multiply float by float
Syntax
; left in float register
; pointer to right in y register
jsr c_fmul
; result in float register
Function
c_fmul multiplies the float in the float register by the float pointed to by
the Y register.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
C Library - c_fsub
c_fsub
Description
Subtract float from float
Syntax
; left in float register
; pointer to right in y register
jsr c_fsub
; result in float register
Function
c_fsub subtracts the float pointed to by the Y register from the float in
the float register. No check is made for overflow.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
See Also
c_fadd
C Library - c_ftod
c_ftod
Description
Convert float into double
Syntax
; pointer to double in y register
; float in float register
jsr c_ftod
; result in memory
Function
c_ftod converts the float in the float register to a double in the memory
pointed at by Y.
Returns
The resulting value is in memory at the location pointedt by the Y register. Flags have no meaningful value upon return.
C Library - c_ftoi
c_ftoi
Description
Convert float to integer
Syntax
; float in float register
jsr c_ftoi
; result in d
Function
c_ftoi converts the float in the float register to a two byte integer in D.
No check is made for overflow.
Returns
The resulting value is in d. Flags have no meaningful value upon return.
C Library - c_ftol
c_ftol
Description
Convert float into long integer
Syntax
; float in float register
jsr c_ftol
; result in long register
Function
c_ftol converts the float in the float register to a four byte integer in
long register. No check is made for overflow.
Returns
The resulting value is in the long register. Flags have no meaningful
value upon return.
C Library - c_itod
c_itod
Description
Convert integer into double
Syntax
; pointer to double in y register
ldd value
jsr c_itod
; result in memory
Function
c_itod converts the two byte integer in D to a double stored in memory
at the address specified by the Y register.
Returns
The resulting value is in memory at the address specified by the Y register. Flags have no meaningful value upon return.
C Library - c_itof
c_itof
Description
Convert integer into float
Syntax
ldd value
jsr c_itof
; result in float register
Function
c_itof converts the two byte integer in D to a float stored in the float
register.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
C Library - c_jltab
c_jltab
Description
Perform C switch statement on long
Syntax
; <value> in long register
ldy #swtab
jsr c_jltab
Function
c_jltab is called to switch to the proper code sequence, depending on a
value and an address table. The top of the table is specified in the Y register, and consists of a list of ranges followed by a list of pairs. A range
consists of a header, made of a count followed by a starting value, followed by an address list. A header with a zero count indicates the final
list of pairs. The count is followed in this case by the number of following pairs. A pair consists of an address followed by a value. The pair list
is ended by the default address. All values are four byte integers. All
addresses are two byte integers.
Returns
c_jltab jumps to the proper code. It never returns.
C Library - c_jptab
c_jptab
Description
Perform C switch statement in PIC mode
Syntax
ldd value
jsr c_jptab,pcr
<offsets>
Function
c_jptab is called to switch to the proper code sequence, depending on a
value and an offset table. The top of the table is found on the stack after
the function is entered, and consists of a list of offsets allowing the
functions to compute the physical target address.
Returns
c_jptab jumps to the proper code. It never returns.
C Library - c_jtab
c_jtab
Description
Perform C switch statement
Syntax
ldd
ldy
jsr
value
#swtab
c_jtab
Function
c_jtab is called to switch to the proper code sequence, depending on a
value and an address table. The top of the table is specified in the Y register, and consists of a list of ranges followed by a list of pairs. A range
consists of a header, made of a count followed by a starting value, followed by an address list. A header with a zero count indicates the final
list of pairs. The count is followed in this case by the number of following pairs. A pair consists of an address followed by a value. The pair list
is ended by the default address. All values and addresses are two byte
integers.
Returns
c_jtab jumps to the proper code. It never returns.
C Library - c_ladd
c_ladd
Description
Long integer addition
Syntax
; left in long register
; pointer to right in y register
jsr c_ladd
; result in long register
Function
c_ladd adds the four byte integer, left and the four byte integer, right.
Returns
The result is in left. Flags are not significant on return.
See Also
c_lcmp, c_lsub
C Library - c_land
c_land
Description
Bitwise AND for long integers
Syntax
; left in long register
; pointer to right in y register
jsr c_land
; result in long register
Function
c_land operates a bitwise AND between the operands. Each operand is
taken to be a four byte integer.
Returns
The result is in the long register. Flags are not significant on return.
See Also
c_lor, c_lxor
C Library - c_lcmp
c_lcmp
Description
Long integer compare
Syntax
; left in long register
; pointer to right in y register
jsr c_lcmp
; result in flags
Function
c_lcmp compares the four byte integer, left with the four byte integer
pointed at by Y.
Returns
Flags are set accordingly.
See Also
c_ladd, c_lsub, c_pcmp
C Library - c_ldiv
c_ldiv
Description
Quotient of long integer division
Syntax
; left in long register
; pointer to right in y register
jsr c_ldiv
; quotient in long register
Function
c_ldiv divides the four byte integer in the long register by the four byte
integer pointed at by Y. Values are assumed to be signed. If division by
zero is attempted, results are as provided by the divide instruction.
Return
The quotient is in the long register; The flags are not significant on
return.
See Also
c_ludv, c_lmod, c_umd
C Library - c_lgadd
c_lgadd
Description
Long addition
Syntax
; pointer to left in y register
; right in long register
jsr c_lgadd
; result in left
Function
c_lgadd performs the long addition of the value pointed at by Y and the
value in the long register.
Returns
The result is stored at the location pointed at by the Y register.
C Library - c_lgand
c_lgand
Description
Long bitwise AND
Syntax
; pointer to left in y register
; right in long register
jsr c_lgand
; result in memory (left is updated)
Function
c_lgand performs the long bitwise AND of the value pointed at by the
Y register and the value in the long register.
Returns
The results is stored at the location pointed at by the Y register, meaning that the left operand is updated.
C Library - c_lgdiv
c_lgdiv
Description
Quotient of long division
Syntax
; pointer to left in y register
; right in long register
jsr c_lgdiv
; result in left
Function
c_lgdiv performs the long division of the value pointed at by the Y register by the value in long register.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lglsh
c_lglsh
Description
Long shift left
Syntax
; pointer to long in y register
; shift count in d register
jsr c_lglsh
; result in memory
Function
c_lglsh performs the long left shift of the value pointed at by the Y register, by the bit count in D. No check is done against silly counts.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgmod
c_lgmod
Description
Remainder of long division
Syntax
; pointer to left in y register
; right in long register
jsr c_lgmod
; result in left
Function
c_lgmod performs the long division of the value pointed at by the Y
register by the value in long register and stores the remainder.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgmul
c_lgmul
Description
Long multiplication
Syntax
; pointer to left in y register
; right in long register
jsr c_lgmul
; result in left
Function
c_lgmul performs the long multiplication of the value pointed at by the
Y register by the value in long register.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgor
c_lgor
Description
Long bitwise OR
Syntax
; pointer to left in y register
; right operand in long register
jsr c_lgor
; result in left
Function
c_lgor performs the long bitwise OR of the value pointed at by Y and
the value in the long register.
C Library - c_lgrsh
c_lgrsh
Description
Signed long shift right
Syntax
; pointer to long in y register
; shift count in d register
jsr c_lgrsh
; result in memory
Function
c_lgrsh performs the signed long right shift of the value pointed at by
the Y register, by the bit count in the D register. No check is done
against silly counts. Because the value is signed, arithmetic shift
instructions are used.
Returns
The result is stored in the location pointed at by y.
C Library - c_lgudv
c_lgudv
Description
Quotient of unsigned long division
Syntax
; pointer to left in y register
; right in long register
jsr c_lgudv
; result in left
Function
c_lgudv performs the unsigned long division of the value pointed at by
the Y register by the value in long register.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgumd
c_lgumd
Description
Remainder of unsigned long division
Syntax
; pointer to left in y register
; right in long register
jsr c_lgumd
; result in left
Function
c_lgumd performs the unsigned long division of the value pointed at by
the Y register by the value in long register and stores the remainder.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgursh
c_lgursh
Description
Unsigned long shift right
Syntax
; pointer to long in y register
; shift count in d register
jsr c_lgursh
; result in memory
Function
c_lgursh performs the unsigned long right shift of the value pointed at
by the Y register, by the bit count in the D register. No check is done
against silly counts. Because the value is unsigned, logical shift instructions are used.
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgsub
c_lgsub
Description
Long subtraction
Syntax
; pointer to left in y register
; right operand in long register
jsr c_lgsub
; result in left
Function
c_lgsub evaluates the (long) difference between the value pointed at by
the Y register and the value in long register
Returns
The result is stored in the location pointed at by Y.
C Library - c_lgxor
c_lgxor
Description
Long bitwise exclusive OR
Syntax
; pointer to left in y register
; right operand in long register
jsr c_lgxor
; result in left
Function
c_lgxor performs the long bitwise EXOR (exclusive OR) of the value
pointed at by the Y register and the value in long register.
Returns
The result is stored in the location pointed at by Y.
C Library - c_llsh
c_llsh
Description
Long shift left
Syntax
; operand in long register
; shift count in y register
jsr c_llsh
; result in long register
Function
c_llsh performs the long left shift of the value in the long register, by
the bit count in Y. No check is done against silly counts.
Returns
The result is in the long register.
C Library - c_lmod
c_lmod
Description
Remainder of long integer division
Syntax
; left in long register
; pointer to right in y register
jsr c_lmod
; remainder in long register
Function
c_lmod divides the four byte integer in long register by the four byte
integer pointed at by the Y register. Values are assumed to be signed.
The dividend is returned in the case of a division by zero.
Returns
The remainder appears in the long register.
See Also
c_lumd, c_ldiv, c_udiv
C Library - c_lmul
c_lmul
Description
Multiply long integer by long integer
Syntax
; left in long register
; pointer to right in y register
jsr c_lmul
; result in long register
Function
c_lmul multiplies the four byte integer in the long register by the four
byte integer pointed at by the Y register. No check is made for overflow.
Returns
The resulting value is in the long register.
C Library - c_lneg
c_lneg
Description
Negate a long integer
Syntax
; value in long register
jsr c_lneg
; result in long register
Function
c_lneg negates the four byte integer in the long register.
Returns
The result stays in the long register. The flags are not significant on
return.
See Also
c_lcom
C Library - c_lor
c_lor
Description
Bitwise OR with long integers
Syntax
; left in long register
; pointer to right in y register
jsr c_lor
; result in long register
Function
c_lor operates a bitwise OR between the contents of the long register
and the long pointed at by the Y register. Each operand is taken to be a
four byte integer.
Returns
The result is in the long register. The flags are not significant on return.
See Also
c_land, c_lxor
C Library - c_lrsh
c_lrsh
Description
Signed long shift right
Syntax
; operand in long register
; shift count in y register
jsr c_lrsh
; result in long register
Function
c_lrsh performs the signed long right shift of the value in the long register, by the bit count in the Y register. No check is done against silly
counts. Because the value is signed, arithmetic shift instructions are
used.
Returns
The result is in the long register.
C Library - c_lrzmp
c_lrzmp
Description
Long test against zero
Syntax
; value in long register
jsr c_lrzmp
; result in the flags
Function
c_lrzmp tests the value in the long register and updates the sign and zero
flags.
Returns
Nothing, but the (possibly changed) flags.
C Library - c_lsub
c_lsub
Description
Long integer subtraction
Syntax
; long in long register
; pointer to right in y register
jsr c_lsub
; result in long register
Function
c_lsub subtracts the four byte integer pointed at by the Y register from
the four byte integer in the long register.
Returns
The result is in the long register. Flags are not significant on return.
See Also
c_ladd, c_lcmp
C Library - c_ltod
c_ltod
Description
Convert long integer into double
Syntax
; pointer to double in y register
; long in long register
jsr c_ltod
; result in memory
Function
c_ltod converts the four byte integer in the long register to a double
pointed at by the Y register.
Returns
The resulting value is in memory. Flags have no meaningful value upon
return.
C Library - c_ltof
c_ltof
Description
Convert long integer into float
Syntax
; value in long register
jsr c_ltof
; result in float register
Function
c_ltof converts the four byte integer in the long register to a float.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
C Library - c_ludv
c_ludv
Description
Quotient of unsigned long integer division
Syntax
; left in long register
; pointer to right in y register
jsr c_lduv
; quotient in long register
Function
c_ludv divides the four byte integer in the long register by the four byte
integer pointed at by the Y register. Values are assumed to be unsigned.
The dividend is returned in the case of a division by zero.
Returns
The quotient is in the long register. The flags are not significant on
return.
See Also
c_ldiv, c_lmod, c_lumd
C Library - c_lumd
c_lumd
Description
Remainder of unsigned long integer division
Syntax
; left in long register
; pointer to right in y register
jsr c_lumd
; remainder in long register
Function
c_lumd divides the four byte integer in the long register by the four byte
integer pointed at by the Y register. Values are assumed to be unsigned.
The dividend is returned in the case of a division by zero.
Returns
The remainder is in the long register. The flags are not significant on
return.
See Also
c_lmod, c_ldiv, c_ludv
C Library - c_lursh
c_lursh
Description
Unsigned long shift right
Syntax
; operand in long register
; shift count in y register
jsr c_lursh
; result in long register
Function
c_lursh performs the unsigned long right shift of the value in the long
register, by the bit count in the Y register. No check is done against silly
counts. Because the value is unsigned, logical shift instructions are
used.
Returns
The result is in the long register.
C Library - c_lxor
c_lxor
Description
Bitwise exclusive OR with long integers
Syntax
; left in long register
; pointer to right in y register
jsr c_lxor
; result in long result
Function
c_lxor operates a bitwise exclusive OR between the contents of the long
register and the long pointed at by the Y register. Each operand is taken
to be a four byte integer.
Returns
The result is in the long register. The flags are not significant on return.
See Also
c_land, c_lor
C Library - c_lzmp
c_lzmp
Description
Compare a long integer to zero
Syntax
; value in long register
jsr c_lzmp
; result in the flags
Function
c_lzmp compares the four byte integer in the long register with zero.
Returns
Nothing. The Z flags is updated.
C Library - c_pcmp
c_pcmp
Description
Far pointer compare
Syntax
; left in far pointer register
; pointer to right in y register
jsr c_pcmd
; result in flags
Function
c_pcmp compares the three byte pointer, left with the three byte pointer
pointed at by Y.
Returns
Flags are set accordingly.
See Also
c_lcmp
C Library - c_uitod
c_uitod
Description
Convert unsigned integer into double
Syntax
; pointer to double in y register
ldd value
jsr c_uitod
; result in memory
Function
c_uitod converts the two byte unsigned integer in D to a double stored
in memory, and pointed at by the Y register.
Returns
The resulting value is in memory at the address specified by the Y register. Flags have no meaningful value upon return.
C Library - c_uitof
c_uitof
Description
Convert unsigned integer into float
Syntax
ldd value
jsr c_uitof
; result in float register
Function
c_uitof converts the two byte unsigned integer in D to a float stored in
the float register.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
C Library - c_ultod
c_ultod
Description
Convert unsigned long integer into double
Syntax
; pointer to double in y register
; long in long register
jsr c_ultod
; result in memory
Function
c_ultod converts the four byte unsigned integer in the long register to a
double pointed at by the Y register.
Returns
The resulting value is in memory. Flags have no meaningful value upon
return.
C Library - c_ultof
c_ultof
Description
Convert unsigned long integer into float
Syntax
; value in long register
jsr c_ultof
; result in float register
Function
c_ultof converts the four byte unsigned integer in the long register to a
float.
Returns
The resulting value is in the float register. Flags have no meaningful
value upon return.
APPENDIX
D
Compiler Passes
The information contained in this appendix is of interest to those users
who want to modify the default operation of the cross compiler by
changing the configuration file that the cx6812 compiler uses to control
the compilation process.
This appendix describes each of the passes of the compiler:
cp6812
cg6812
co6812
the parser
the code generator
the assembly language optimizer
-ad
-b
-bc
-c99
-ck
-cp
-d*^
specify * as the name of a user-defined preprocessor symbol (#define). The form of the definition is
-dsymbol[=value]; the symbol is set to 1 if value is omitted. You can specify up to 60 such definitions.
-e
+e*
log errors in the text file * instead of displaying the messages on the terminal screen.
-f
-h*>
-i*>
-l
-m#
@tiny
0x20
@near
0x30
@far
@pack
0x04
@nostack
Note that all the combinations are not significant for all the
target processors.
-nb
-nc
-ne
-np
-nw
-o*
write the output to the file *. Default is STDOUT for output if -e is specified. Otherwise, an output file name is
required.
-p
enforce prototype declaration for functions. An error message is issued if a function is used and no prototype declaration is found for it. By default, the compiler accepts both
syntaxes without any error.
-rb
-s
-sa
-u
-x
-xd
-xp
-xx
Return Status
cp6812 returns success if it produces no error diagnostics.
Example
cp6812 is usually invoked before cg6812 the code generator, as in:
cp6812 -o \2.cx1 -u -i \cosmic\h6812 file.c
cg6812 -o \2.cx2 \2.cx1
-a
-bss
-bv
-ck
-cr#
-cs
split the const section into two sections. One for single
byte constants and another for the rest so that can be allocated separately to avoid odd accesses.
-ct
output constant in the .text section. By default, the compiler outputs literals and constants in the .const section.
-df
-dl#
+e*
log errors in the text file * instead of displaying the messages on the terminal screen.
-f
-i
-l
merge C source listing with assembly language code; listing output defaults to <file>.ls.
-na
do not produce an xdef directive for the equate names created for each C object declared with an absolute address.
-no
-o*
-r*
define the I/O registers base address to allow the code generator to access the PPAGE, DPAGE and EPAGE registers directly, if no specific header file has been included.
The compiler locates those registers in page 0 by default
and uses the -t option value to select the proper addresses.
The -r operand can be an absolute value or a symbol name
which must be defined somewhere in the application.
-sf
-t#
-tf
-v
Return Status
cg6812 returns success if it produces no diagnostics.
Example
cg6812 usually follows cp6812 as follows:
cp6812 -o \2.cx1 -u -i\cosmic\h6812 file.c
cg6812 -o \2.cx2 \2.cx1
-c
-d*
-o*
-v
Disabling Optimization
When using the optimizer with the -c option, lines which are changed or
removed are kept in the assembly source as comment, followed by a
code composed with a letter and a digit, identifying the internal function which performs the optimization. If an optimization appears to do
something wrong, it is possible to disable selectively that function by
specifying its code with the -d option. Several functions can be disabled
by specifying a list of codes without any whitespaces. The code letter
can be enter both lower or uppercase.
Return Status
co6812 returns success if it produces no diagnostics.
Example
co6812 is usually invoked after cg6812 as follows:
cp6812 -o \2.cx1 -u -i\cosmic\h6812 file.c
cg6812 -o \2.cx2 \2.cx1
co6812 -o file.s \2.cx2
Index
Symbols
#asm
directive 463
#asm directive 47
#define
replacement in assembly 48
#endasm
directive 463
#endasm directive 47
#pragma
asm directive 47
endasm directive 47
+grp directive 295
+seg option 292
.bsct
+zpage option 39
data defined in 78
default section 41
generate in 25
initialized data 38
label defined in 209
section 20
.bss
default section 41
section 20
.const
constant aligned 76
default section 41
output section 468
section 20
segment 302
splitting section 76
.const.w
section 20
.data
default section 41
section 20
.eeprom
default section 20, 41
section 40
.fdata
default section 41
section 20, 76, 468
.ftext
default section 20, 41
section 76, 469
.text
default section 41
section 20, 469
.ubsct
default section 41
generate data 25
section 20
uninitialized data 38
@dir
space modifier 59
type qualifier 25
@eeprom
type qualifier 13, 40
variable allocation 40
@far
function 59
modifier 20
qualifier 12
Index 1
type qualifier 12
variables 468
@interrupt
functions 51
modifier 51
qualifier 51
@svpage modifier 56
__ckdesc__l 310
__idesc__ 308, 309
__memory symbol 22, 33, 63
__sbss symbol 21, 33
__stack symbol 22, 33
_asm
argument string size 48
assembly sequence 49
code optimization 467
function() 86
return type 50
sequence 49
_asm()
inserting assembler function 81
_BASE
preprocessor symbol 84
symbol 46
_checksum
function 99
_checksum16 function 101
_checksum16x function 102
_checksumx function 100
_fctcpy function 112
_main
entry point 32
_sbreak function 63
Numerics
32 bits, float 463
68HC12A4
family 469
processor 55
8-bit precision,operation 11
2 Index
A
abort function 87
abs function 88
absolute
address 324
address in listing 337
double value 111
find value 88
hex file generator 9
listing file 337
listing utility 10
long value 131
path name 466
referencing address 44
section 272
section relocation 300
section,org 263
symbol 294
symbol in library 340
symbol table 291
symbol tables 317
symbol,flagged 317
accumulate 130
acos function 89
address
banked 346
banked data 345
default format 335, 337
extension,page 214
linear physical 346
logical end 294
logical start segment 300
logical start set 294
paged format 335, 337
physical 294, 346, 349
physical end 292
physical start 292
physical start segment 300
set logical 294
align
assembler directive 222
object 76
align constant
+ceven option 20, 42
aligned constant
.constw section 59
allocate new 161
alphabetic character 120
alphabetic string 120
alphanumeric characters 119
application
embedded 286
non-banked 335
system bootstrap 286
Arccosine 89
Arcsine 90
Arctangent 91
Arctangent of y/x 92
argument
widen 465
argument widening 194
asin function 90
assembler
branch shortening 220
C style directives 221
code inline 48
conditional branch range 220
conditional directive 217
create listing file 205
endm directive 214
environment symbol 219
expression 212
label 210
listing process 337
macro
instruction 214
macro directive 214
operators 213
sections 218
switch directive 218
assembly language
code optimizer 471
atan function 91
atan2 function 92
atof function 93
atoi function 94
atol function 95
automatic
bank filling 306, 332
data initialization 32
filling, activated 306
B
bank
+modf option 53
+seg directive 54
@far type modifier 53
automatic filling 54
automatic segment creation 294
call instruction 55
default mode 349
jsr instruction 55
link application 53
logical start address 53, 306
multiple 306
number 53
optimize filling 9, 332
overflow 306
page operator 214
physical start address 53, 306
single definition 306
size setting 292, 332
size specification 306
switched system 300
window base register 53
window maximum size 53
window mechanism 12
window size 54, 306
bank switching
definition 53
support 12
banked
build segment 306
base directive 223
bias
segment parameter 300
Index 3
setting 301
bitfield
filling 465
filling order 77
reverse order 465
bitfields
volatile 468
boolean function
@bool type modifier 44
optimizing 44
boundary
align 222
even align 76
even start 463
round up 294
bsct directive 224
bss section 33
buffer
compare for lexical order 141
convert to double 93, 187
convert to integer 94
convert to long 95, 188
convert to unsigned long 189
copy from one to another 142, 144
copy string 177
copy to eeprom 106
fill character 145
output formatted argument 170
put to output 156
C
C identifier 119
C interface
extra character for far function 59
to assembly language 59
underscore character prefix 59
C library
builtin functions 83
floating point functions 82
function descriptions 85
fuzzy functions 82
integer functions 81
4 Index
macro functions 82
package 81
C source
lines merging 468
calling environment 136
calloc function 96
carry function 97
cbank utility 332
ceil function 98
char
signed 466
unsigned 466
character 155
fill throughout eeprom buffer 108
find first character in string 175
first occurrence in buffer 140
get 117
get string 118
underscore,start 65
checksum
-ck option 311
crc 311
functions 310
-ik option 311
clabs utility 337
clib utillity 340
clist directive 225, 240, 242, 243, 244,
245, 246, 247, 248, 249, 250
clst utility 328
cobj utility 343
code generator
compiler pass 467
error log file 468
code optimizer
compiler pass 471
code/data, no output 292
coercion 139, 146
comment
character 21
common log 135
compare for lexical order 176, 181
compilation model,selected 346
compiler
+pic option 57, 58
+picd option 57
+picds option 57
@far function 76
ANSI checking 465
assembler 9
assembler option specification 73
bitfield reverse option 77
C preprocessor and language parser 8
code generator 8
code generator option specification
74
code optimization 11
code optimizer 8
combination of options 375
command line options 72
configuration file 374
configuration file specification 74
default behavior 72
default configuration file 74
default file name 79
default operations 461
default option 72
default options 374
driver 4
error message 72
exclusive options 375
flags 6
force single precision 78
generate error 351
generate error file 80
generate listing 80
invoking 72
listing file 75
name 72
optimizer option specification 75
options 72
parser option specification 75
pc relative addressing mode 57
Position Independant Code 57
position independant code 77
predefined option 75
produce debug information 76
programmable option 374, 375
specific options 4
specify option 73
temporary file path 75
type checking 78, 463
user-defined preprocessor symbol 74
verbose 75
verbose mode 19
compute 110, 149, 168, 190
concatenate 174, 180
const
data 36
qualifier 36
constant
in .text section 468
prefix character 211
storage boundaries enforcing 463
string character 212
suffix character 212
constant bank
@far type modifier 56
const keyword 56
in .text section 56
PPAGE register 56
convert
decimal digit string to a number 122
ELF/DWARF format 348
hex format 334
IEEE695 format 345
to lowercase 192
to uppercase 193
cos function 103
cosh function 104
cosine 103
cprd utility 326
cross-reference
information 204
output 19
table in listing 208
cv695 utility 345
Index 5
D
data
automatic initialization 33
bank support 12
const type 37
external,PPAGE register 56
in eeprom space 40
in zero page 38
initalized 38
mapped in code section,+picd 57, 77
mapped in usual section,+picds 58,
77
storage boundaries enforcing 463
volatile type 36
data ban
CSD chip select 57
data bank
+nofds option 56
.fdata section 56
@epage type modifier 56
@far type modifier 55
far pointer calculation 57
mechanism 55
page boundary 57
page number 57
range extension 55
data object
automatic 326
scope 324
type 324
data page
page size 57
data representation
short int,16 bit pointers 68
@far pointer 68
char 68
float and double 68
long integer 68
dc directive 226
6 Index
partition 116
return 60
DP256 Eeprom Library 304
DPAGE
address 469
area 55
-ds12 option 57
move structure in 386
register 55
register access 46, 469
register location 77
segment 57
ds directive 229
E
eepcpy function 106
eepera function 107
eeprom
location 13, 40
eepset function 108
ELF/DWARF
format converter 10
else directive 230, 231, 234, 240, 242,
249
end directive 232
endc directive 242, 249
endif directive 230, 233, 240
endm
directive 255
endm directive 235, 258, 270
endr 266, 267
directive 236
enum
size optimization 464
EPAGE
address 469
area 56
-ds10 option 57
move structure in 405
register 55
register access 46, 469
segment 57
F
fabs function 111
fail directive 239
far code
+nofts option 59
far data
+nofds option 59
faster code
production 469
file
preprocessed only 75
file length restriction 324
fill
bank 332
byte 205, 222, 229, 238, 263
find
character in string 183
first occurrence of string 186
Index 7
8 Index
G
generate
.bsct section 59
.bss section 59
.const section 59
.const.w section 59
.data section 59
.fdata section 59
.ftext section 59
.text section 59
.ubsct section 59
error message 239
hex record 293
inline assembly code 86
listing file 206
object file 206
output files 17
pseudo-random number 157
getchar function 117
gets function 118
group
option 288
H
HC12/HCS12
addressing mode 209
mnemonics 208
HC12DG128
family support 77
HC12DP256
eeprom feature 40
HCS12
family 205
header files 46, 83
support 78
header
files 83
input/output file 83
heap
allocate space on 138
allocation 63
area 65
free space 115
location 65
name 63
pointer 63
reallocate space on 158
size 63
space allocation 96
stack 63
start 63
top 63
-help option 6
hexadecimal digit 130
hyperbolic
cosine 104
sine 169
tangent 191
I
IEEE695
format converter 10
if
directive 217, 230, 234, 240
ifc directive 241
ifdef directive 242
ifeq directive 243
ifge directive 244
ifgt directive 245
ifle directive 246
iflt directive 247
ifnc directive 248
ifndef directive 249
Index 9
L
labs function 131
ldexp function 132
ldiv function 133
leading whitespace 128
librariy
building and maintaining 340
library
build and maintain 10
create 340
delete file 340
double precision 303
extract file 341
file 303
floating point 81
fuzzy 81
fuzzy functions 58
included file 83
integer 81, 304
10 Index
M
macro
argument 215
directive 255
expansion 48
internal label 210
named syntax 216
named syntax, example 256
numbered syntax 215
numbered syntax, example 256
parameter 215
special parameter \# 215
special parameter \* 216, 255
special parameter \0 216, 256
main
function 319
routine 33
malloc function 138
map
file description 319
modules section 319
produce information 291
segment section 319
stack usage section 319
symbols section 319
max function 139
maximum 139
maximum available space 306
memchr function 140
memcmp function 141
memcpy function 142
memmove function 144
memory 161
location 44
mapped I/O 44
memset function 145
N
natural 134
natural logarithm 134
new
segment control 288
start region 297
nolist directive 260
nopage directive 261
numeric constants 211
O
object
file location 28
file path specification 74
image 285
module 286
module inspector 10
relocatable 343
relocatable file output 207
relocatable file size 343
reorganization 332
size 343
offset
Index 11
narrow 465
Position Independant Code 468
pow function 149
PPAGE
address 469
definition 99, 100, 101, 102
register access 46, 469
prefix
filename 466
preprocessor
#define 462
#include 462
run only 463
printable characters 125
printf function 150
private name region
use 313
processor
address 306
select type 205
pseudo-random number 172
putchar function 155
puts function 156
page
assembler directive 264
boundary 12
value 214, 335
paged
architecture 300
paginating output 329
parser
behaviour 464
compiler pass 462
error log file 463
path
define include 75
pc relative addressing mode 209, 468
pcr register 210
plen directive 265
pointer
12 Index
R
rand function 157
random number generation 172
range specification 329
realloc function 158
redirect output 329
REFs 312
region
name 288
private 297
public 297
use of private name 313
register
input/output 46
relative address 324
S
save
calling environment 166
save directive 271
sbreak function 161
scanf function 162
section
curly braces,initiliazed data 41
definition 285
map to absolute 204
name 42, 218
parenthesis,code 41
pragma definition 41
pragma directive 42
predefinition 218
single 469
square brackets, uninitialized data 41
user defined 41
section directive 272
sections
default 41
predefined 41
relocation 300
seed 172
segment
bsct start address 295
bss start address 295
build new 303
control options 290, 292
data start address 295
definition 285
fill 292
Index 13
14 Index
alias 314
define 288
define alias 298
define new 298
definition 298
export 317
logical end value,equal 298
logical start value,equal 298
physical end value,equal 299
physical start value,equal 299
size value,equal 299
sort alphabetically 291
sort by address 291
user-defined 463
symbol table
add 298
information 343
new 312
T
tabs directive 277
tan function 190
tangent 190
tanh function 191
task entries 319
test 120
test for 119, 122, 128, 129, 130, 139,
146
title directive 278
tolower function 192
toupper function 193
translate executable images 334
type 139, 146
type cast 96
type casting 139, 146
type definition 194
type name 194
U
unreachable code
eliminate 11
unsigned long division 435, 436
zpage
section 38
V
va_arg macro 194
va_end function 196
va_start macro 198
variable
reorder local 465
variable length argument list 196, 198
variables in data bank 12
volatile
data 36
memory mapped control registers 36
qualifier 36
using keyword 36
vprintf function 200
vsprintf function 201
W
whitespace character 128
widen to int 194
window
set shift 291, 348
size 294
window shift 300
windowed area, matching 306
write to output stream 155
X
x to the y power 149
xdef directive 279, 280
xref directive 279, 280
xref.b directive, external 219
Z
zero page 25
#pragma directive 38
@dir modifier 20
@dir type qualifier 38
section 38
zero page section 224
Index 15