Professional Documents
Culture Documents
and Utilities
A166 Macro Assembler
L166 Linker/Locator
LIB166 Library Manager
OH166 Object File Converter
RTX166 Tiny Real-Time Operating System
Monitor166 Target Monitor
Information in this document is subject to change without notice and does not
represent a commitment on the part of the manufacturer. The software described
in this document is furnished under license agreement or nondisclosure agreement
and may be used or copied only in accordance with the terms of the agreement. It
is against the law to copy the software on any medium except as specifically
allowed in the license or nondisclosure agreement. The purchaser may make one
copy of the software for backup purposes. No part of this manual may be
reproduced or transmitted in any form or by any means, electronic or mechanical,
including photocopying, recording, or information storage and retrieval systems,
for any purpose other than for the purchaser’s personal use, without written
permission.
Every effort was made to ensure accuracy in this manual and to give appropriate
credit to persons, companies, and trademarks referenced herein.
166/167 Assembler and Utilities iii
Preface
This manual describes the application range and use of the A166 Macro
Assembler and utilities. The assembler translates programs written in assembly
language into executable machine instructions. The A166 assembler may be used
for all processors of the 166/167 family including the 80C167CR and the 80C165.
This user’s guide assumes that you are familiar with the MS-DOS operating
system and how to program the 166/167 processors.
“Chapter 6. Error Messages”, contains a list of all A166 error messages and
describes their causes and how to avoid them.
“Chapter 8. L166 Linker/Locator”, describes the linker and explains how to use
the command-line directives. This chapter also includes a reference section of all
linker directives and application examples.
The Appendix explains the 166/167 utility tools: LIB166 Library Manager,
OH166 Object Hex Converter, RTX166 Tiny Real-Time Operating System,
Monitor-166 Target Monitor, the dScope Monitor Interface, and the AMAKE
DOS-based Project Management Utility.
iv Preface
Document Conventions
This document uses the following conventions:
Examples Description
README.TXT Bold capital text is used for the names of executable programs, data files,
source files, environment variables, and commands you enter at the
MS-DOS command prompt. This text usually represents commands that
you must type in literally. For example:
Note that you are not required to enter these commands using all capital
letters.
Courier Text in this typeface is used to represent information that displays on screen
or prints at the printer.
This typeface is also used within the text when discussing or describing
command line items.
Variables Text in italics represents information that you must provide. For example,
projectfile in a syntax string means that you must supply the actual project
file name.
Occasionally, italics are also used to emphasize words in the text.
Elements that repeat… Ellipses (…) are used in examples to indicate an item that may be repeated.
Omitted code Vertical ellipses are used in source code examples to indicate that a
. fragment of the program is omitted. For example:
. void main (void) {
.
.
.
.
while (1);
Optional Items Optional arguments in command-line and option fields are indicated by
double brackets. For example:
Contents
Chapter 1. Introduction................................................................................... 1
What is an Assembler? ............................................................................................ 1
How to Develop A Program ..................................................................................... 2
Advantages of Modular Programming................................................................ 2
Efficient Program Development ......................................................................... 2
Multiple Use of Subprograms ............................................................................. 3
Ease of Debugging and Modifying ..................................................................... 3
Modular Program Development Process .................................................................. 3
Sections, Modules, and Programs ....................................................................... 3
Program Entry and Exit ..................................................................................... 4
Assembly ........................................................................................................... 4
Relocation and Linkage...................................................................................... 4
Keeping Track of Files ....................................................................................... 5
Writing and Assembling Programs .......................................................................... 6
Chapter 2. Operands and Expressions.......................................................... 11
Instruction Operands ............................................................................................. 12
Expressions ........................................................................................................... 13
Numbers................................................................................................................ 13
Character Strings................................................................................................... 13
Symbols................................................................................................................. 14
Labels .............................................................................................................. 15
Special Assembly Symbols ............................................................................... 16
Operators............................................................................................................... 17
Addition and Subtraction ................................................................................. 18
Multiplication, Division, Modulo ..................................................................... 19
Sign Operators ................................................................................................. 19
Shift Operators................................................................................................. 20
Relational Operators ........................................................................................ 20
Logical Operators............................................................................................. 20
HIGH and LOW............................................................................................... 21
DOT Operator.................................................................................................. 21
Page Override Operator.................................................................................... 22
PTR Operator................................................................................................... 22
DATA Operator ............................................................................................... 23
SHORT Operator ............................................................................................. 24
SEG Operator .................................................................................................. 25
PAG Operator .................................................................................................. 25
SOF Operator................................................................................................... 26
POF Operator................................................................................................... 26
BOF Operator .................................................................................................. 27
Chapter 3. Assembler Directives ................................................................... 31
SECTIONS............................................................................................................ 31
vi Contents
SECTION / ENDS............................................................................................32
GROUP..................................................................................................................37
ASSUME ...............................................................................................................38
REGDEF / REGBANK ..........................................................................................41
PECDEF ................................................................................................................42
SSKDEF ................................................................................................................42
PROC / ENDP........................................................................................................43
EQU.......................................................................................................................46
SET........................................................................................................................47
BIT ........................................................................................................................48
LABEL ..................................................................................................................49
DEFR / DEFA / DEFB ...........................................................................................50
LIT ........................................................................................................................52
TYPEDEC .............................................................................................................53
ORG ......................................................................................................................53
EVEN ....................................................................................................................54
EXTERN / EXTRN................................................................................................55
PUBLIC / GLOBAL...............................................................................................57
Defining and Initializing Variables ........................................................................59
Defining and Initializing Pointers ..........................................................................62
NAME ...................................................................................................................63
END.......................................................................................................................63
Chapter 4. Invocation and Controls................................................................65
Running A166........................................................................................................65
Command Files.................................................................................................66
DOS ERRORLEVEL........................................................................................66
Output Files......................................................................................................67
Assembler Controls ................................................................................................67
ABSOLUTE .....................................................................................................70
CASE / NOCASE.............................................................................................71
COND / NOCOND...........................................................................................72
DATE...............................................................................................................73
DEBUG / NODEBUG.......................................................................................74
EJECT..............................................................................................................75
ERRORPRINT / NOERRORPRINT..................................................................76
EXPDECNUM .................................................................................................77
GEN / GENONLY / NOGEN ...........................................................................78
INCDIR............................................................................................................79
INCLUDE ........................................................................................................80
LIST / NOLIST ................................................................................................81
MACRO / NOMACRO.....................................................................................82
MOD166 / NOMOD166 ...................................................................................83
MOD167 ..........................................................................................................84
OBJECT / NOOBJECT.....................................................................................85
PAGELENGTH................................................................................................86
PAGEWIDTH ..................................................................................................87
166/167 Assembler and Utilities vii
NOMAP..........................................................................................................183
NOPUBLICS ..................................................................................................184
NOTYPE ........................................................................................................185
NOVECTAB...................................................................................................186
OBJECTCONTROLS .....................................................................................187
PAGELENGTH ..............................................................................................188
PAGEWIDTH.................................................................................................189
PRINT ............................................................................................................190
PRINTCONTROLS ........................................................................................191
PUBLICSONLY .............................................................................................192
PURGE ...........................................................................................................193
REGBANK .....................................................................................................194
REGFILE........................................................................................................195
RESERVE ......................................................................................................196
RTX166 ..........................................................................................................197
RTX166TINY.................................................................................................198
SECSIZE ........................................................................................................199
SECTIONS .....................................................................................................200
VECTAB ........................................................................................................201
WARNINGLEVEL .........................................................................................202
Definition of the Physical Memory Layout ............................................................203
Advanced Techniques .....................................................................................205
TGROUPS (Siemens Task Concept) .....................................................................207
Compatibility to Siemens Tools.......................................................................208
Error Messages.....................................................................................................210
Warnings ........................................................................................................210
Non Fatal Errors .............................................................................................212
Fatal Errors.....................................................................................................215
Exception Messages ........................................................................................218
Application Example ............................................................................................219
Appendix A. LIB166 Library Manager ...................................................... 229
Using LIB166.......................................................................................................229
Interactive Mode...................................................................................................229
Command Summary.............................................................................................230
Creating a Library ................................................................................................231
Adding Object Modules ........................................................................................232
Removing Object Modules....................................................................................233
Listing Library Contents.......................................................................................234
Help Information ..................................................................................................235
LIB166 Error Messages ........................................................................................236
Fatal Errors.....................................................................................................236
Errors..............................................................................................................237
Appendix B. OH166 Object-Hex Converter ............................................... 239
Using OH166........................................................................................................239
OH166 Error Messages.........................................................................................240
x Contents
Chapter 1. Introduction
This manual describes the A166 macro assembler and explains the process of
developing software in assembly language for the 166/167 microcontroller family.
1
Assembly language programs translate directly into machine instructions which
instruct the processor what operations to perform. Therefore, to effectively write
assembly programs, you should be familiar with both the microcomputer
architecture and assembly language. This chapter presents an overview of the
A166 macro assembler and how it is used.
What is an Assembler?
An assembler is a software tool—a program—designed to simplify the task of
writing computer programs. It performs the clerical task of translating symbolic
code into executable object code. This object code may then be programmed into
an 166/167 microcontroller and executed. If you have ever written a computer
program directly in machine-recognizable form, such as binary or hexadecimal
code, you will appreciate the advantages of programming in symbolic assembly
language.
Machine instructions
Assembler directives
Assembler controls
1 Assembler directives are used to define the program structure and symbols, and
generate non-executable code (data, messages, etc.). Refer to “Chapter 3.
Assembler Directives” on page 31 for details on all of the assembler directives.
Assembler controls set the assembly modes and direct the assembly flow.
“Chapter 4. Invocation and Controls” on page 65 contains a comprehensive guide
to all the assembler controls.
Assembly
The A166 assembler translates the source code into object code. The assembler
produces a relocatable object file and a listing file showing the results of the
assembly. When the assembler invocation contains the DEBUG control, the
object file also receives the debug information for use during the symbolic
debugging of the program. This debugging may be via the dScope-166
Debugger/Simulator, or in-circuit emulators available from many vendors.
Object File: the object file contains machine language instructions and data that
can be loaded into memory for execution or interpretation. In addition, it contains
control information governing the loading process.
Listing File: The listing file provides both the source program and the object
code. The assembler also produces diagnostic messages in the listing file for
syntax and other coding errors. For example, if you specify a 16-bit value for an
instruction that can only use an 8-bit value, the assembler tells you that the value
exceeds the permissible range. Appendix F describes the format of the listing file.
In addition, you can also request a symbol table to be appended to the listing. The
symbol table lists all the symbols and their attributes.
Assembler
Source File
A166
Macro Assembler
Listing
File
Object
Other File
Objects or
Libraries
L166
Linker/Locater
MAP
File
Absolute
Object
File
HEX
File
PROM Programmer
166/167 Assembler and Utilities 7
If you are developing hardware for your application, consult the 166/167
hardware manuals.
1 $SEGMENTED
2
3 $IF MEDIUM OR LARGE
Model LIT 'FAR'
$ELSE
6 Model LIT 'NEAR'
7 $ENDIF
8
9 PUBLIC SERINIT, timerstop, timerstart
10 ASSUME DPP3:SYSTEM
11
12 ?PR?SERINIT section code
13
14 SERINIT proc NEAR
15
16 ;*******************************
17 ;*** INIT SERIAL INTERFACE 0 ***
18 ;*******************************
19
0000 AFE2 20 BSET P3.10 ; OUTPUT LATCH (TXD)
0002 AFE3 21 BSET DP3.10 ; DIR-CONTROL (TXD OUTPUT)
0004 BEE3 22 BCLR DP3.11 ; DIR-CONTROL (RXD INPUT)
0006 E7B68000 23 MOVB S0TIC,#080H ; TRANSMIT INTERRUPT FLAG
000A E7B70000 24 MOVB S0RIC,#000H ; RECEIVE INTERRUPT FLAG
000E E65A4000 25 MOV S0BG ,#0040H ; 9600 BAUD
0012 E6D81180 26 MOV S0CON,#8011H ; SET SERIAL MODE
0016 CB00 27 RET
28 SERINIT endp
29
30
31 timerstart proc NEAR
0018 E6A00000 32 MOV T2CON,#0
001C E6A10000 33 MOV T3CON,#0
0020 E6200000 34 MOV T2,#0
0024 E6210000 35 MOV T3,#0
0028 E6A14000 36 MOV T3CON,#0040H
002C E6A04F00 37 MOV T2CON,#004FH
0030 CB00 38 RET
39 timerstart endp
40
41
42 timerstop proc NEAR
0032 E6A00000 43 MOV T2CON,#0
0036 E6A10000 44 MOV T3CON,#0
003A F2F442FE 45 MOV R4,T3
003E F2F540FE 46 MOV R5,T2
0042 CB00 47 RET
48 timerstop endp
49
50 ?PR?SERINIT ends
51
52 end
8 Chapter 1. Introduction
The NAME field shows the name of the symbol. The TYPE field specifies the
type of the symbol which is one of the following:
166/167 Assembler and Utilities 9
Type Description
BIT type bit
BTWRD
BYTE
type BITWORD (word in bit-addressable space)
type byte (8 bit)
1
DAT16 a constant value in range 0 to 65535
DATA3 a constant value in range 0 to 7
DATA4 a constant value in range 0 to 15
DATA8 a constant value in range 0 to 255
FAR a label of type far
INTNO a symbolic interrupt number
LIT a text literal
NEAR a label of type near
RBANK a symbolic name for a register bank
SHORT a short label (+127/-128 words short range)
WORD type word (16 bit)
The VALUE field shows the numeric value of the symbol. The value is shown as
a hexadecimal number. In case of type LIT, the literal expansion text is shown for
the value.
A character (A) following the value indicates an absolute value. A character (R)
following the values designates a relocatable value. Expressions with relocatable,
external or section symbols are calculated during link/locate time by L166.
The ATTRIBUTES column shows attributes and line numbers of the particular
symbol:
Attributes Description
EXT The symbol is external in some other module
GLB The symbol is global
GROUP The symbol represents a group name
PUB The symbol is public
SECTION The symbol represents a section name
SFR The symbol is a special function register (SFR)
If the symbol is a member of some section, then the name of the parent section
containing the symbol is displayed in the form SEC=<section_name>.
The line numbers contain each line of code in which the symbol was referenced. A
hash mark (#) following a line number indicates that the value of the symbol was
defined in that line. A cross reference is listed only if the XREF directive is used.
10 Chapter 1. Introduction
1 relocatable
To assemble the above module, the assembler was invoked using the following
command line:
A166 SAMPLE.A66 SET(SMALL) XREF PW(78)
After assembly, the object modules are linked and all variables and addresses are
resolved and located into an executable program by the L166 linker. The linker is
invoked with the following command line.
L166 SAMPLE.OBJ
The linker generates an absolute object file as well as a listing file and screen
messages. The screen output for the linker is:
DOS LINKER/LOCATOR L166 V3.00
COPYRIGHT KEIL ELEKTRONIK GmbH 1992 - 1996
the 166/167 instruction at the label can be jumped to by using the symbolic
label name for the destination address. The same also applies for subroutine
calls.
labels are also available for symbolic debugging. This simplifies the testing of
software since physical addresses can be specified using the symbolic name.
The number and required type of operands expected depend entirely on the
assembler mnemonic. Some instructions require no operands, some require one,
two or three operands to form a valid instruction. Operands can be classified as
follows:
Comments can be inserted into the source program. A comment is introduced with
a leading semicolon (;). The rest of the line following the semicolon is ignored.
START: CALLS SEG (FARPROC), FARPROC ; comment after instruction
; a pure comment line.
Comments may be used liberally for documenting programs. They do not affect
the object code.
12 Chapter 2. Operands and Expressions
Instruction Operands
An operand is part of the instruction that follows the instruction opcode. The
instructions for the 166/167 require zero to three operands. Depending on the
instruction, the type of operands differs:
CADDR 16-bit code address within the current 64K segment for use in
branch instructions.
Expressions
Instruction operands are primarily expressions. Expressions consist of numbers,
symbols and operators. If all components of an expression are known at assembly
time, (no external at relocatable components), then the expression is considered to
be an absolute expression, otherwise it is a relocatable expression where the final
value will be computed by the linker/locator L166.
The following chapters describe the basic components of an expression and the
2
operators.
Numbers
Numbers can be specified in hexadecimal (base 16), decimal (base 10), octal (base
8) and binary (base 2). A number without an explicit base is interpreted as
decimal, this being the default representation. The first character of a number must
always be a digit between 0 and 9. Hexadecimal numbers which do not have a
digit as the first character must have a 0 placed in front of them.
Dollar ($) signs can be placed within numbers to make them more readable.
However a $ sign is not allowed to be the first or last character of a number and
will not be interpreted.
1111$0000$1010$0011B - is equivalent to - 1111000010100011B
1$2$3$4 - is equivalent to - 1234
Character Strings
The A166 assembler allows the use of ASCII character strings in expressions. An
expression is permitted to have a maximum of two ASCII characters enclosed in
single quote characters (’).
14 Chapter 2. Operands and Expressions
NOTE
Character strings are not permitted to have a null length!
A null character string consists of two single quotes that enclose no other
2 characters (‘’).
Symbols
The A166 assembler allows the use of symbols. Symbols may represent numeric
values or addresses and make a program easier to read and understand. Symbols
have the following attributes:
TYPE: each symbol has a type, for example: bit, byte, word, or
data3. The type is used by the assembler to determine the
access type and generate the appropriate instruction, example
MOVB vs. MOVW. Another purpose is type checking so that
for example a call to a data label instead of a code address
will be caught by the assembler.
166/167 Assembler and Utilities 15
CHANGEABLE: Symbols that have been defined using the SET directive can
2
be changed using the SET directive. Symbols which have not
been defined using the SET directive may not be redefined.
The assembler contains predefined symbols for mnemonics, operands and 166/167
specific data and bit addresses. These names are described as reserved words and
are not allowed to be used by the programmer to define symbols or labels.
Labels
A label is a symbol, and the rules for symbols also apply to labels. A label is the
first field in a line, but may be preceded by tabs or spaces. A colon (:) must be
placed after a label to identify it as a label. Only one label is permitted per line.
When a label is defined, it receives the current numerical value of the address
counter of the currently active section. A label may not be defined more than once
and is not allowed to have the name of a reserved word.
2 The dollar sign ($) represents the current offset in the active section. There is a
separate address counter for each section. The address counter is increased after
each instruction by length. The ORG directive can be used to change the value of
the address counter. The address counter automatically changes to the new
segment if the current section is changed.
Note that $ is incremented with every instruction. But this only occurs when the
instruction has been completely translated. On DB (define byte) and DW (define
word) statements, the address counter is advanced on each element of the list.
Section names
The name of a section specifies the address of the section (base-relocatable).
Group names
A group name specifies the address of the group of sections (base-
relocatable).
Variables and labels
The offset of variables and labels, which are defined inside of relocatable
sections, are relocatable (offset relocatable).
External constants
Externally defined constants are relocatable values. Relocatable in this context
means that L166 will ‘fill in’ the constant value which must be defined in
some other source module.
166/167 Assembler and Utilities 17
The following examples show how the above mentioned relocatable symbols are
generated. The details on the used keywords can be found in the appropriate
chapters.
Operators
Operators fall into two classes: unary operators and binary operators. Unary
operators require one operand whereas binary operands require two operands. If
the grouping of the is not specified with parentheses, the operator priority is used
to determine evaluation order. The operators and default priority levels are listed
in the following table in decreasing priority.
2 2
2
POF
BOF
POF var
BOF xbit
Get Page Offset Of ‘Var’
Get Bitpos Of ‘Xbit’ Within Bitword Base
3 HIGH HIGH 1234H Get High Value From Expression (12H)
3 LOW LOW 1234H Get Low Value From Expression (34H)
3 NOT NOT 0 Bit Complement Operator
3 +, - -2 Unary Plus, Minus
4 *, /, MOD 100 MOD 7 Multiply, Division, Remainder
5 +, - 4 + 100 Addition, Subtraction
6 SHL, << 1 SHL 3 Shift Left
6 SHR, >> 100 >> 7 Shift Right
7 AND, & 1234 & 7 Bit And
7 OR, | 1234 | 1 Bit Or
7 XOR, ^ 1234 XOR 5 Bit Xor
8 LT, < 5<2 Lower Than
8 LE, <= 5 <= 2 Lower Than Or Equal
8 GT, > 5>2 Greater Than
8 GE, >= 5 >= 2 Greater Than Or Equal
8 ULT 5 ULT 3 Unsigned Lower Than
8 ULE 5 ULE 3 Unsigned Lower Than Or Equal
8 UGT 5 UGT 3 Unsigned Greater Than
8 UGE 5 UGE 3 Unsigned Greater Than Or Equal
9 SHORT SHORT lab Short Jump-Range Operator
Sign Operators
The unary plus operator does not modify its operand. The unary minus makes its
operand negative by evaluating ‘0 - operand’.
Syntax: + operand
- operand
20 Chapter 2. Operands and Expressions
Shift Operators
These operators shift their left operand either left (SHL, <<) or right (SHR, >>)
by the number of bits specified in the operand right to the operator. Both operands
required to be absolute.
Relational Operators
The relational operators compare their operands. The result is either 0 (‘false’) or
1 (‘true’). The operands can be either absolute or offset-relocatable.
Logical Operators
The logical operators operate on absolute operands only and evaluate to an
absolute result. The NOT operator performs a bitwise complementation on its
operand.
DOT Operator
Syntax: bitword.bitpos
The dot (.) operator serves the purpose to designate a bit to the right of the
operator from the bitword-base to the left of the dot operator. The ‘bitpos’
operand must be an absolute operand evaluating to a number in range 0 to 15. The
bitword base identifies a bit-addressable word in internal RAM or SFR area:
00000H to 0007FH: 8-bit word number in RAM
00080H to 000EFH: 8-bit word number in SFR area
0FD00H to 0FDFEH: bitword in internal RAM
0FF00H to 0FFDEH: SFR area
Another possibility for the bitword base is an even aligned word in a bit-
addressable data section:
BD10 SECTION DATA BITADDRESSABLE
BW0 DSW1
BD10 ENDS
EXTRN BW1 : BITWORD ; external bitword
Each variable is physically located somewhere in memory. The 16K page, which
contains a variable, is the parent page. Access to the content of the variable
requires a data page pointer (one of DPP0 to DPP3) to hold the page number of
2 the target page. In practice, A166 keeps track of what DPP will keep the section
or group base address by means of the ASSUME directive.
The page override undergoes the ASSUME mechanism by using the DPP from the
prefix for addressing. It is the users responsibility to make sure, that the given
DPP is loaded with the correct base to get a valid runtime address.
Example:
ASSUME DPP2:D100
PTR Operator
Syntax: type PTR : operand
The PTR operator is used to give a memory reference a specified type and may
therefore override the real type of the operand. The keyword ‘PTR’ is optional, the
operand can be any address expression which represents a data variable or a code
label.
BIT
BYTE
166/167 Assembler and Utilities 23
WORD
BITWORD
NEAR
FAR
The PTR operator cannot be used on section and group names and external
constants (extern DATAn:name). The type ‘BIT PTR’ can only by applied on bits,
it is not possible to change the access type from some other type to type bit.
2
Examples:
D100 SECTION DATA
V1 DSW 1
V2 DSW 1
B1 DSB 1
B2 DSB 1
D100 ENDS
EXTRN XPROC:NEAR
DATA Operator
Syntax: DATAn operand
The DATAn operator is used to specify the type of constants in both instructions
and externally defined constants. There are four different DATAn operators, each
defines a specific value range. ‘n’ specifies the number of bits:
references. Due to the three pass nature of A166, it is not necessary to use the
DATAn operator in instructions and still get the shortest possible instruction
opcodes.
Examples:
1 C100 SECTION CODE
2 P100 PROC NEAR
0000 E070 3 MOV R0,#CONS
2 0002 E6F10700
0006 E002
4
E 5
6
7
P100
C100
MOV
MOV
ENDP
ENDS
R1,#DATA16 CONS
R2,#CON3
8
9 EXTRN CON3 : DATA3
10 CONS EQU 7 ; DATA3 type derived
11 ; from value 7
12 END
The example shows the use of the DATAn operator. Although forward references
are contained (CON3 and CONS), the assembler still generates the short form of
the MOV instruction. The DATAn operator can be used to ‘enlarge’ the type, it is
not possible to ‘shrink’ the type of a constant, for example ‘DATA3 12’. In this
case the assembler will truncate the value and give a warning.
SHORT Operator
Syntax: SHORT label
The SHORT operator is used to generate a short distance branch (call or jump
relative to within -128 to +127 words to the current instruction) to a forward
referenced label. The branch target will be checked in pass2 against violence of the
maximum relative distance.
Due to the three pass nature of A166, it is not necessary to use the SHORT
operator in forward references. Pass 2 of the A166 automatically determines
distances and will use the shortest form of the branch instructions (JMPR,
CALLR).
Example:
C100 SECTION CODE
P100 PROC NEAR
JMP LAB
JMP SHORT LAB
LAB: MOV R15,R3
P100 ENDP
C100 ENDS
166/167 Assembler and Utilities 25
SEG Operator
Syntax: SEG operand
The SEG operator returns a relocatable 2-bit (8-bit for 167) segment number of
the named operand. The segment number is the number of the 64K segment where
the operand is located in.
The operand normally should be the name of a variable, section, group or a special 2
function register (SFR) or registerbank. If SEG is used on system names (SFR’s)
the result is absolute and has value 0.
Examples:
PAG Operator
Syntax: PAG operand
The PAG operator returns a relocatable 4-bit (10-bit for 80C167) page number of
the named operand. The page number is the number of 16K page which the
operand is located in.
The operand normally should be the name of a variable, section, group, special
function register (SFR) or registerbank. If PAG is used on system names (SFR’s)
the result is the absolute page number 3.]
Examples:
1 D100 SECTION DATA ; relocatable data
section
0000 2 V1 DSW 1
3 D100 ENDS ; end of section
4
5 C100 SECTION CODE
6 P100 PROC NEAR
0000 E6020000 R 7 MOV DPP2,#PAG D100 ; base page of section
D100
0004 E6030300 8 MOV DPP3,#PAG SYSCON; page nr. of internal
RAM
0008 E6F00300 9 MOV R0,#PAG SYSCON ; result: 3
000C E6F10000 R 10 MOV R1,#PAG P100 ; relocatable
26 Chapter 2. Operands and Expressions
SOF Operator
The SOF operator returns the 16-bit offset of its operand from the base of the 64K
segment in which it is defined. SOF cannot be applied to group names.
The primary use of the SOF operator is for loading the peripheral event controller
with source and destination addresses. Since the PEC unit works with linear
addresses not using the DPPn mechanism, the user must use the SOF operator to
obtain linear addresses.
The operand normally should be the name of a variable, section, special function
register (SFR) or registerbank. If SOF is used on system names (SFR’s) the result
is the absolute offset relative to segment 0.
Examples:
1 D100 SECTION DATA
0000 2 V1 DSW 20
0028 0000 R 3 V2 DW SOF V1 ; segment offset of V1
002A 0000 R 4 V3 DW PAG V1 ; page offset of V1
5 D100 ENDS
6
7 DSTP7 EQU 0FDFEH
8
9 C100 SECTION CODE
10 P100 PROC NEAR
0000 E6F80000 R 11 MOV R8,#SOF V1 ; segment offset
0004 F6F8FEFD 12 MOV DSTP7,R8 ; destination for PECC7
0008 E6F50000 R 13 MOV R5,#SOF P100 ; SOF of parent
procedure
14 P100 ENDP
15 C100 ENDS
16 END
POF Operator
Syntax: POF operand
The POF operator returns the 14-bit page offset of its operand from the base of
the 16K page in which it is defined. POF cannot be applied to group names.
166/167 Assembler and Utilities 27
The operand normally should be the name of a variable, section, special function
register (SFR) or registerbank. If POF is used on system names (SFR’s) the result
is the absolute page offset relative to page 3.
Examples:
1 D100 SECTION DATA
0000 2 V1 DSW 20
0028 0000 R 3 V2 DW POF V1 ; page offset of V1
002A 0000 R 4
5
6
7
V3
D100
DSTP7
DW
ENDS
EQU
PAG V1
0FDFEH
; page number of V1
2
8
9 C100 SECTION CODE
10 P100 PROC NEAR
0000 E6F80000 R 11 MOV R8,#POF V1
0004 E6F92800 R 12 MOV R9,#POF V2
0008 E6F70C3F 13 MOV R7,#POF SYSCON ; system name
000C E6F60000 R 14 MOV R6,#POF C100 ; segment to page conv
0010 E6F5FE3D 15 MOV R5,#POF DSTP7 ; result is 3DFEH
16 P100 ENDP
17 C100 ENDS
18 END
The POF operator is implied when memory accesses to data variables are coded
since data is always located in 16K pages (MOV R8,V2).
BOF Operator
Syntax: BOF bit-operand
The BOF operator returns the bit position of a bit variable from the bit-
addressable word, in which it is defined. The result is always an absolute number
(exception: BOF applied to an externally defined bit variable). The operand to
BOF must be of type bit, otherwise an error occurs.
Examples:
1 D100 SECTION DATA BITADDRESSABLE
0000 2 V1 DSW 1
3 D100 ENDS
4
5 BIT1 BIT V1.15
6 BIT2 BIT V1.1
7 BIT3 BIT 0FD10H.8
8 EXTRN EBIT : BIT
9
10 C100 SECTION CODE
11 P100 PROC NEAR
0000 E084 12 MOV R4,#BOF BIT3 ; result is 8
0002 E0F5 13 MOV R5,#BOF BIT1 ; result is 15
0004 E015 14 MOV R5,#BOF BIT2 ; result is 1
0006 E005 E 15 MOV R5,#BOF EBIT ; result determined by
L166
16 P100 ENDP
28 Chapter 2. Operands and Expressions
17 C100 ENDS
18 END
2
166/167 Assembler and Utilities 29
2
166/167 Assembler and Utilities 31
SECTIONS
A Section is a portion of memory which may be addressed by a section base and
an offset. Sections of different modules may be combined to a larger section or a
group at link time and may have a class name to allow different sections to be
placed near each other in memory. Due to the difference in addressing code and
data, different types of sections and groups are provided.
DATA Address: Page number supplied via data page pointer for 166/167 (10
bits, 0 to 1023), offset (14 bits, 0 to 16383)
32 Chapter 3. Assembler Directives
SECTION / ENDS
The SECTION / ENDS directive is used to define logical memory sections which
may be combined with sections of equal names. Sections are placed within
physical segments in case of code sections or physical pages in case of data
sections. Within one source module, each occurrence of an equivalent section
(having the same name) is viewed as one section consisting of two or more partial
sections. The 166/167 knows two fundamental operating modes: the segmented
mode and the non-segmented mode. In segmented mode, the CPU can address up
to 16MB of memory. In non-segmented mode, the CPU can address up to 64K of
memory, the total space required for code and data must not exceed 64K. All
references are of type near since the data page pointers are loaded once on startup
3 and no segmented calls (CALLS) are necessary.
Description of fields:
combine-type This field specifies how sections are combined with sections
from other modules to form a page or segment in memory.
The actual combination of sections is processed by the
linker/locator L166. The following combine-type specifiers
are possible:
Example:
C100 SECTION CODE ‘INITROM’
C100 ENDS
A Section may be opened and closed many times. All parts of the section are
combined to one section. When a section is reopened, the attributes (with the
exception of section-type) need not be specified. If the attributes are specified,
they cannot re-specify previous attributes.
The following example shows multiple sections using the same name, one
generating an error because of section attribute redefinition:
1 D100 SECTION DATA BITADDRESSABLE
0000 2 V1 DSW 1 ; reserve one word of storage
3 D100 ENDS
4
5 D100 SECTION DATA
0002 6 V2 DSW 1 ; reserve one word of storage
7 D100 ENDS
8
9 ; the above sections are equal to:
10
11 ;D100 SECTION DATA BITADDRESSABLE
36 Chapter 3. Assembler Directives
Nested Sections
3 The definition of sections can be nested, although sections are never nested
physically in memory. Nesting of code sections is not allowed. Data sections may
be defined within code sections. Up to ten nested sections are allowed. Nested
sections must be closed inside out, that is, the innermost section must be closed
first and so on. The following examples shows a nested section definition, where
an absolute data section is nested within a relocatable data section:
1 D100 SECTION DATA BITADDRESSABLE
0000 2 V1 DSW 1 ; relocatable word
3 D200 SECTION DATA AT 4000H
0000 4 A1 DSW 1 ; absolute word at 4000H
0002 5 A2 DSW 1 ; absolute word at 4002H
6 D200 ENDS ; D200 gets closed
0002 7 V2 DSW 1 ; section D100 is resumed
8 D100 ENDS
166/167 Assembler and Utilities 37
GROUP
The GROUP directive is used to define groups of sections. A group is a collection
of one or more sections, all contained within one data page in case of a data group
or within one segment in case of a code group. The reason for having two types of
groups (code groups and data groups) is the difference of the 166/167 CPU in
addressing code and data. A GROUP serves as shorthand to refer to a collection
of sections.
Description of fields:
3
group-name is the name of the group. The name must be an unique
identifier.
3
0004 CC00 18 NOP ; pipeline delay
0006 F2F10000 R 19 MOV R1,V2 ; load content of 'V1'
000A E6F50000 R 20 MOV R5,#POF V1 ; derive page offset of 'V1'
000E E6F60000 R 21 MOV R6,#POF V2 ; derive page offset of 'V2'
22 P100 ENDP
23 C100 ENDS
24
25 END
ASSUME
At runtime, every data memory reference requires two parts of information in
order to form a valid data address:
The page number is contained in one of the data page pointers. The information,
which data page pointer is to be used is contained in the instruction opcode. It is
possible to use any of the four data page pointers.
The assembler receives the information about runtime contents of the data page
pointers per ASSUME. Going this way, the assembler makes sure that a variable
will be correctly addressed at runtime. The ASSUME directive does not initialize
data page pointers in any sense, it is used by the assembler to help you be aware of
the consistent addressing of your data. If the assembler finds an instruction
operand not having an associated DPP or an explicit page override operator, it
reports an error. The ASSUME directive gives the assembler the required
information for automatic generation of the page override instruction prefix.
166/167 Assembler and Utilities 39
Description of fields:
section-name all references to variables of the given section will use the
given data page pointer.
NOTHING resets the previous ASSUME for the given DPP. The
assembler is informed that the given DPP is no longer valid.
To invalidate all DPP-assumes, the short form ASSUME
NOTHING is provided.
The assume(s) are valid until another assume changes the runtime assumptions on
the given data page pointer.
Data page information can be also given by means of an explicit page override, for
example:
40 Chapter 3. Assembler Directives
As a general rule, explicit page overrides should be avoided since programs may
become hard to maintain, if excessive used. In case of configuration changes on
sections or groups, every DPP override has to be changed by hand which tends to
be erroneous. When using the ASSUME directive, only a few assumes along with
some MOV DPP instructions must be changed to get a new data page
configuration.
Examples:
1 $SEGMENTED
2
3 GDATA DGROUP D100, D200
4 GCODE CGROUP C100
3 0000
5
6
7
8
D100
V1
D100
SECTION DATA
DSW
ENDS
1
9
10 D200 SECTION DATA
0000 11 V2 DSW 1
12 D200 ENDS
13
14 C100 SECTION CODE PUBLIC 'ROM1'
15 P100 PROC NEAR
16 ASSUME DPP2 : D200 ;
0000 E6020000 R 17 MOV DPP2,#PAG D200 ; page number of 'D200'
0004 CC00 18 NOP ; pipeline delay
0006 F2FF0000 R 19 MOV R15,V2 ; DPP2 is used for reference
20
21 MOV P1,P2 ; move Port-2 content to
Port1
*** ____________________________________^
*** ERROR #77, LINE #21, MISSING 'DPP' INFORMATION
22 ; an error: no associated
DPP!
23 ASSUME DPP3 : SYSTEM ; est addressability of
SFR's
000E E6030300 24 MOV DPP3,#PAG P1 ; Page-3 is the system page
0012 CC00 25 NOP ; pipeline delay
0014 F282C0FF 26 MOV P1,P2 ; now correct
27
28 ASSUME DPP2 : GDATA ; D100 and D200 use DPP2 now
0018 E6020000 R 29 MOV DPP2,#PAG GDATA
001C CC00 30 NOP
001E F2F10000 R 31 MOV R1,V1
0022 02F10000 R 32 ADD R1,V2
0026 F6F10000 R 33 MOV V2,R1
34 P100 ENDP
35 C100 ENDS
36
37 END
The error in line 21 results from an access to SFR port-2 with no associated DPP
for the system area.
166/167 Assembler and Utilities 41
REGDEF / REGBANK
All 16 of the 166/167 general purpose registers (GPRs) are mapped to on-chip
RAM. A context switch to a new register bank can be done very quickly using a
different register bank by name. The base of the actual register bank is contained
in the context pointer register, which is a special function register.
The REGBANK directive is used to create a new register bank. The register bank
name can be assigned to a memory range located in internal RAM holding the
GPR’s, specified by the register range. If the register range is missing, the
assembler will automatically supply a mask of all register used in the source
3
module.
The REGDEF directive is used to create a register bank having an optional name.
The difference to REGBANK is that a register range is required. A warning is
displayed if the actual register used in the source module are not a subset or equal
to the registers given in register range.
Register banks are handled by the linker/locator like data sections with the
exception that they are always located in internal RAM at addresses 0FA00H to
0FDFFH.
The register range has the form ‘Rn [-Rm]’ (m,n: 0 to 15) or ‘Rn[,Rm[, …]]’.
Example:
BANK1 REGBANK R0-R15 ; define a complete register bank
1 $SEGMENTED
2
3 BANK2 REGBANK R0-R15
4
5 C100 SECTION CODE PUBLIC 'ROM1'
6 INIT PROC FAR
0000 E6030300 7 MOV DPP3,#PAG SYSCON
0004 CC00 8 NOP
0006 C6080000 R 9 SCXT CP,#BANK2 ; save & load context
pointer
000A CC00 10 NOP ; pipeline delay
000C E6FF3412 11 MOV R15,#1234H ; access to GPR's now valid
0010 DB00 12 RET
13 INIT ENDP
14 C100 ENDS
15
16 END
42 Chapter 3. Assembler Directives
Register banks are handled by the linker/locator like data sections with the
exception that they are always located in internal RAM.
PECDEF
The 166/167 controller contains 8 Peripheral event controllers, referred to as PEC
channels. Each channel has associated counter and control registers (implemented
in the SFR area) and a source and destination pointer which specify the transfer
addresses. The source and destination pointers are located in on-chip RAM at
addresses 0FDE0H to 0FDFFH. If the PEC channels are not used, this RAM can
be used as ordinary RAM, otherwise it must be reserved by means of the
3 PECDEF directive which prevents the linker/locator from placing other sections in
this specific area. The PEC channels are referred to as PECC0, PECC1, …
PECC7. One source module can contain only one PECDEF directive.
Example:
PECDEF PECC0-PECC2, PECC6,PECC7
PECDEF PECC0-PECC7
SSKDEF
The SSKDEF directive specifies the size of the system stack. One module may
contain only one SSKDEF directive.
Example:
SSKDEF 1
166/167 Assembler and Utilities 43
PROC / ENDP
The PROC and ENDP directive pair is used to define a label for a sequence of
machine instructions called a procedure. A procedure is called within the same
physical segment (near call) or from a different segment (far call). A procedure
may have either type near or type far. Unless procedures known from high level
languages, the scope of identifiers is different in the assembly language so that
identifiers must be unique because the visibility is module wide.
A procedure normally ends with a RET instruction. The software instruction RET
will be automatically converted to an appropriate machine return instruction, that
is,
The assembler does not check the flow of control to figure out whether a return
instruction is present or not, it is up to the user to have a return instruction coded.
Description of fields:
type Specifies the type of the procedure, it may receive one of the
following values:
NOTE
the TASK is implemented for compatibility to the Siemens
tool chain. TASK denotes a TGROUP and not a task of a
real-time operating system. Instead of TASK use the
INTERRUPT keyword.
USING Defines the register bank used for the interrupt procedure.
Example:
LOC OBJ LINE SOURCE
3
1 $SEGMENTED
2
3 MyBank1 REGBANK
4 MyBank2 REGBANK
5
6 C100 SECTION CODE
7
8 int10 PROC INTERRUPT I10=10 USING MyBank2
000000 F6F00000 R 9 MOV MyBank2,R0
000004 C6080000 R 10 SCXT CP,#MyBank2
000008 CC00 11 NOP
12 ; ...
00000A FC08 13 POP CP
00000C FB88 14 RET
15 int10 ENDP
16
17 proc1 PROC USING MyBank1
00000E F6F00000 R 18 MOV MyBank1,R0
000012 C6080000 R 19 SCXT CP,#MyBank1
000016 CC00 20 NOP
21 ; ...
000018 FC08 22 POP CP
00001A C600 23 RET
24 proc1 ENDP
25
26 C100 ENDS
27
28 C101 SECTION CODE
29
30 P101 PROC NEAR
000000 DA000000 R 31 CALL P102 ; far call for P102
000004 CB00 32 RET ; near return
33 P101 ENDP
34
35 P102 PROC FAR
000006 BBFC 36 CALL P101 ; near call for P101
000008 9B0A 37 TRAP #I10 ; call int10
00000A DB00 38 RET ; far return
39 P102 ENDP
46 Chapter 3. Assembler Directives
40
41 END
EQU
Syntax: name EQU expression
EQU creates a new symbol with the name and the value of the expression. A
symbol created by EQU cannot be redefined elsewhere. The expression can have
the following values:
The expression must not have forward references. All identifiers used in the
expression must have been previously defined.
The following example shows the use of EQU and the resulting symbol listing
created by the assembler. Note that symbols, which represent registers are not
displayed by the assembler.
LOC OBJ LINE SOURCE
SET creates a new symbol with name name and the value of the expression. A
symbol created by SET may be redefined. The expression can have the following
values:
a constant value
an identifier
an expression having a prefix (PAG,POF,SEG,SOF)
The expression must not have forward references, that means all identifiers used in
the expression must have been previously defined. A SET symbol cannot be made
PUBLIC or GLOBAL.
Example:
LOC OBJ LINE SOURCE
BIT
Syntax: bit-name BIT expression
3 The BIT directive assigns the value of expression to the specified bit-name. Such
a bit-name cannot be redefined elsewhere in the source module. The expression
may not contain forward references.
The BIT directive can be used to create a bit-name for an bit-addressable item
Example:
LOC OBJ LINE SOURCE
The label directive is useful to define a different name with possibly a different
type. Example: a label of the type WORD for a location of two consecutive bytes.
This is required since the assembler checks variable accesses against type
mismatches.
none given the label receives a default type, depending on the parent
section:
CODE SECTION: type NEAR
DATA SECTION: type BYTE
BIT SECTION: type BIT
NEAR or FAR the label receives type near or far. This implies that the label
must have been defined within a section of type code,
otherwise an error will result.
50 Chapter 3. Assembler Directives
BYTE or WORD the label receives type byte or word. The parent section must
be of type CODE or DATA. In case of type WORD, the
label must have an even address (so called word address).
BIT creates a bit label. The parent section must be of type BIT.
Example:
LOC OBJ LINE SOURCE
3 0000
7
8
9
10
B100
BLAB
BIT1
B100
SECTION BIT
LABEL
DBIT
ENDS
BIT
11
12 D200 SECTION DATA BITADDRESSABLE
13 DLAB LABEL BYTE
0000 14 WORD1 DSW 1
15 D200 ENDS
16
17 C100 SECTION CODE
18 P100 PROC NEAR
0000 F2F00000 R 19 MOV R0,XWORD
0004 F3FF0000 R 20 MOV RH7,DLAB
21 MOV R5,DLAB ; error, type mismatch
*** _____________________________________________^
*** ERROR #74, LINE #21, ILLEGAL OPERAND TYPE
22 FLAB LABEL FAR
23 YLAB: LABEL FAR
24
000C CB00 25 RET
26 P100 ENDP
27 C100 ENDS
28
29 END
These directives define SFR names (DEFR), names for absolute internal RAM
addresses (DEFA) and bit-addresses (DEFB). The optional attribute can be:
The assembler knows the 80C166 SFR names and the associated bits. If you use
a derivative, like the 167 you can define the SFR register set as follows:
NOTE
The ASM directory contains already several include files for most of the
166/167 derivatives available.
3
The arguments must follow the rules for each of the three directives:
Examples:
LOC OBJ LINE SOURCE
3 LIT
Syntax: lit-name LIT ‘literal string’
lit-name LIT “literal string”
The LIT directive provides a simple text substitution facility. Every time the
identifier lit-name is encountered, it will be replaced by the literal string assigned
to lit-name. The lit-name follows the same rules as other identifiers, that is, a
literal name is not encountered if it not forms a separate token. If a sub-string is to
be replaced, then lit-name must be enclosed in braces: Text{lit-name}. The
assembler listing shows the expanded lines where literals are substituted.
0008 0DFF
000A CB00
15
16
17
18
LABR1:
P100
JMP
RET
ENDP
LABR1 3
19 C100 ENDS
20 END
TYPEDEC
Syntax: TYPEDEC name : type [, name : type [, …]]
A166 ignores the TYPEDEC directive completely. Since A166 is a three pass
assembler, it is not required to declare forward referenced symbols. A166 uses the
pass 2 to determine symbol types. The keyword TYPEDEC has been included for
compatibility with assemblers from other vendors.
ORG
Syntax: ORG expression
The ORG directive can be used to change the value of the location counter within
the currently active section. The value of expression sets the location counter to
the desired value relative to the start address of the section. Care should be taken
when the new location counter value indicates an offset below the previous value.
In this case code or data may be overwritten which may cause runtime errors.
54 Chapter 3. Assembler Directives
ORG may be used in absolute sections to set the location counter to an absolute
address.
The expressions value may not be greater than 65535, forward references are not
allowed. The current value of the location counter is represented by the dollar
symbol $ and can be part of the expression. ORG cannot be used in sections of
the type BIT.
Example:
LOC OBJ LINE SOURCE
3
3 ORG $ + 20H ; gap of 16 words
0022 4 V2 DSW 1
5 D_ABS ENDS
6
7 C100 SECTION CODE
8 P100 PROC NEAR
0000 0D32 9 JMP XLAB
10 ORG $ + 100
0066 F2F12240 11 XLAB: MOV R1,V2
006A CB00 12 RET
13 P100 ENDP
14 C100 ENDS
15 END
EVEN
Syntax: EVEN
The EVEN directive ensures that code or data following EVEN is aligned on a
word boundary. The assembler creates a gap of one byte if necessary, the content
of the byte gap is left undefined. Accesses to words require even addresses,
otherwise the 166/167 CPU will generate a runtime exception (trap).
Example:
LOC OBJ LINE SOURCE
EXTERN / EXTRN
Syntax: EXTERN [DPPn] name : type [, …]
EXTRN [DPPn] name : type [, …]
The EXTERN directive is used to specify those symbols which will be referenced
in the current source module, but are defined in other source modules. The 3
module, which defines those symbols must declare them as PUBLIC or GLOBAL.
The EXTERN directive specifies the name of the external symbol and its type.
Field Values:
DPPn: is one of DPP0, DPP1, DPP2, DPP3. The DPP specified will be used
for references to the external symbol. Note that this can become very
dangerous since you have to know in what kind of section the external symbol
is defined and which DPP will hold the page base of that section. In case of
DPP configuration changes within your application, this method may cause a
lot of changes of the DPP’s in the source files.
The following examples show a more flexible approach to solve this problem.
3
DSEC ENDS
Module 2: $SEGMENTED
ASSUME DPP2 : DSEC
DSEC SECTION DATA PUBLIC
EXTRN VAR1 : WORD
EXTRN VAR2 : BYTE
DSEC ENDS
The above example gives the way how to deal with PUBLICS and EXTERNALS.
Note that this does not apply in non-segmented mode since the DPP registers are
not changed.
Example:
LOC OBJ LINE SOURCE
1 $SEGMENTED
2
3 ASSUME DPP2 : DSEC ; DPP2 for accesses in
DSEC
4 ASSUME DPP3 : SYSTEM ; DPP3 for SFR addressing
5
6 EXTERN RBANK : REGBANK
7 EXTERN EXBIT : BIT, FPROC : FAR, NPROC : NEAR
8 EXTRN TRAPX : INTNO
9 EXTRN yvar : word
10
11 DSEC SECTION DATA PUBLIC
12 EXTERN ExtW1 : WORD, ExtB1 : BYTE
0000 13 LOCV DSW 1
0002 14 LOCB DSB 1
15 DSEC ENDS
16
17 C100 SECTION CODE
18 P100 PROC FAR
0000 E6030300 19 MOV DPP3,#PAG SYSCON; DPP3 = 3
0004 E6020000 R 20 MOV DPP2,#PAG DSEC ;
0008 C6080000 E 21 SCXT CP,#RBANK ; switch to new
RegBank
000C 0E00 E 22 BCLR EXBIT ; clear external bit
000E 9B00 E 23 TRAP #TRAPX ; force sw-trap
0010 CA000000 E 24 CALL NPROC ; near call
0014 DA000000 E 25 CALL FPROC ; far call
0018 F2F10000 E 26 MOV R1,ExtW1 ; use DPP2 per ASSUME
166/167 Assembler and Utilities 57
3
C100 . . . . . . . ---- ---- SECTION
CP . . . . . . . . WORD FE10H A SFR
DPP1 . . . . . . . WORD FE02H A SFR
DPP2 . . . . . . . WORD FE04H A SFR
DPP3 . . . . . . . WORD FE06H A SFR
DSEC . . . . . . . ---- ---- SECTION
EXBIT. . . . . . . BIT ---- EXT
EXTB1. . . . . . . BYTE ---- R EXT SEC=DSEC
EXTW1. . . . . . . WORD ---- R EXT SEC=DSEC
FPROC. . . . . . . FAR ---- EXT
LOCB . . . . . . . BYTE 0002H R SEC=DSEC
LOCV . . . . . . . WORD 0000H R SEC=DSEC
NPROC. . . . . . . NEAR ---- EXT
P100 . . . . . . . FAR 0000H R SEC=C100
RBANK. . . . . . . RBANK ---- EXT
SYSCON . . . . . . WORD FF0CH A SFR
TRAPX. . . . . . . INTNO ---- EXT
YVAR . . . . . . . WORD ---- EXT
PUBLIC / GLOBAL
Syntax: PUBLIC name [, name] [, …]
GLOBAL name [, name] [, …]
The PUBLIC directive specifies one or more symbols that may be used by other
source modules in the same TGROUP. The GLOBAL directive specifies one or
more symbols that may be used by other modules, even from different TGROUPS.
All other type of symbols are not allowed. PUBLIC and GLOBAL symbols can
be accessed by other modules if the same symbol name has been declared
EXTERN in that module.
Example:
LOC OBJ LINE SOURCE
1 $SEGMENTED
2
3 BSEC SECTION BIT PUBLIC
0000 4 BIT0 DBIT
0001 5 BIT1 DBIT
6 BSEC ENDS
7
8 CON3 EQU DATA3 7
3 9
10
11
12
RB1 REGBANK
PUBLIC
PUBLIC
R0-R15
RB1,CON3,P100
BIT0, BIT1
This directives allow to reserve or initialize memory. The colon may optionally
follow the name.
Examples:
bit1: DBIT ; reserve one bit
bit2: DBIT 10 ; reserve ten bits
bit3 DBIT 1 ; reserve one bit
CONSTANT EXPRESSION
3 the expression represents a constant value. The value of the constant
expression must be in range 0 to 255 when bytes are initialized. In case of
word initialization, the value must be in range 0 to 65535. An expression may
contain a character string not longer than two characters.
DB 13,10
DB “hello world”, 13,10,0, 4 * 8, -2
If you want to include a single or double quote within a string, use two
consecutive quotes or use a single quote in a string enclosed within double
quotes or vice versa. The following example shows two equivalent
initializations using a string:
DB ‘what’’s going on’
DB “what’s going on”
DW may receive a string of length one ore two characters (example: ‘a’, ‘ab’,
“a” or “ab”). DB may receive a string consisting of up to about 500
characters. A string of length zero is not allowed.
ADDRESS EXPRESSION
the expression represents the address of a variable or segment or page number:
DW PAG symbol
DW POF symbol
DW data_symbol
The next example initializes three words with the current offset. Note that the
offset advanced (by two because of DW), therefore three different values are
stored:
DW $, $, $
166/167 Assembler and Utilities 61
When you use a section name or group name in a DW directive, the segment
number for code sections or page number for data sections is stored:
DW section_symbol
DW code_label ; store segment offset
DW group_symbol ; page or segment number
In SEGMENTED mode of operation it is possible to generate data addresses
which contain the offset of some data variable and the DPP bits in one word. This
compares to the method of the C166 compiler when dealing with near pointers:
$SEGMENTED
$ASSUME DPP1 : D100
In the above case, the word holds the DPP information in bits 15 and 14. The
offset information in range 0 to 16383 is held in bits 0 to 13. Usage of such
generated pointers for addressing implies that the associated DPP’s are correctly
initialized. If this is not the case, addresses which relate to a wrong pages may be
generated, depending on the current content of the DPP in use.
NOTE
When using the special form ‘DPPn:POF symbol’, the POF operator must be
used, otherwise the DPP selection bits are not merged into the page offset.
62 Chapter 3. Assembler Directives
Pointers are memory units which contain complete physical addresses of variables
or labels. The meaning of the above directives is as follows:
Examples:
LOC OBJ LINE SOURCE
3
14
15 END
NAME
Syntax: NAME module-name
The NAME directive is used to identify the current module with a module-name.
The linker/locator L166 requires the name of each input module to be different.
The module name may be any identifier including reserved words of the assembler
A166. If the NAME directive is missing, the module name will be set to the name
of the input file without path specification and file name extension. The input file
name C:\C166\LIB\STARTUP.A66 will lead to the module name STARTUP.
Example:
NAME PARSER_MODULE
END
Syntax: END
The END directive marks the end of the input file to the assembler and is always
required. If END is missing, an error occurs. Lines of text beyond END will be
ignored by the assembler, but not by the macro processor contained within A166.
Example:
NAME X_MODULE
END ;end of input file
64 Chapter 3. Assembler Directives
3
166/167 Assembler and Utilities 65
Using the controls described in this part, you can specify which operations are
performed by A166. For example, you can direct A166 to generate a listing file,
produce cross reference information, and control the amount of information
included in the object file. You can also conditionally assemble sections of code
using the conditional assembly controls.
Running A166
The A166 assembler is invoked by typing A166 at the DOS prompt. The
command line must contain the name of an 166/167 assembly source file to be
assembled as well as any command line controls that are required. The format for 4
the A166 command line is:
where
sourcefile is the name of the source program you want to assemble. A166
assembler
controls are used to direct the operation of the assembler. Refer to
“Assembler Controls” on page 67 for more information.
The following command line example invokes A166 and specifies the source file
SAMPLE.A66 and uses the controls DEBUG, XREF, and PAGEWIDTH.
A166 SAMPLE.A66 DEBUG XREF PAGEWIDTH(132)
Command Files
Command files are ASCII text files that contain information that you would
normally type on the DOS invocation line. Command files can include the name
of the source file to assemble as well as any assembler controls.
A166 allows you to specify a command file on the DOS invocation line using an at
sign (@).
Example
A166 @CMDFIL
The contents of the file CMDFIL will be interpreted as one long input command
line.
DOS ERRORLEVEL
4 After assembly, the number of errors and warnings detected is output to the
screen. A166 then sets the DOS ERRORLEVEL to indicate the status of the
assembly. Values are listed in the following table:
Errorlevel Meaning
0 No Errors Or Warnings
1 Warnings Only
2 Errors And Possibly Also Warnings
3 Fatal Errors
You can access the ERRORLEVEL variable in DOS batch files for conditional
inquiries in order to terminate the batch processing when an error occurs. Refer to
your DOS User’s Guide for more information about ERRORLEVEL or batch
files.
166/167 Assembler and Utilities 67
Output Files
A166 generates a number of output files during assembly. By default, each of
these shares the same basename as the source file. However, each has a different
file extension. The following table lists the files and gives a brief description of
each.
Assembler Controls 4
A166 provides a number of controls that you can use to direct the operation of the
assembler. Controls are composed of one or more letters or digits and, unless
otherwise indicated, can be specified after the filename on the invocation line or in
a control line within the source file. Control lines are prefixed by the dollar sign
($).
Example
A166 TESTFILE.A66 DEBUG XREF
or
$MPL
$DEBUG
$XREF
or
$MPL DEBUG XREF
In the above example, MPL, DEBUG, and XREF are all control commands and
TESTFILE.A66 is the source file that will be assembled.
A166 has two classes of controls: primary and general. The primary controls are
set in the invocation line or the primary control lines and remain in effect
68 Chapter 4. Invocation and Controls
throughout the assembly. For this reason, primary controls may be used only in
the invocation line or in the control line at the beginning of the program. Only
other control lines (that do not contain the INCLUDE control) may precede a line
containing a primary control. The INCLUDE control terminates of primary
controls.
If a primary control is specified in the invocation line and in the primary control
lines, the first time counts. This enables the programmer to override primary
controls via the invocation line.
The general controls are used to control the immediate action of the assembler.
Typically their status is set and modified during the assembly. Control lines
containing only general controls may be placed anywhere in your source code.
The table below lists all of the controls, their abbreviations, their default values,
and a brief description of each.
4 Name / Abbreviation
ABSOLUTE, AB
Meaning
Checks the module against relocatable references.
DATE(date) / DA Places a date string in header (9 characters maximum).
CASE Enable case sensitive mode for symbol names.
COND, CO / NOCOND, NOCO Enable or disable skipped sections to appear in the listing file.
DEBUG / DB Outputs debug symbol information to object file.
EJECT / EJ ‡ Continue listing on next page.
ERRORPRINT[(file)] / EP Designates a file to receive error messages in addition to the listing.
EXPDECNUM . EDN Set the output format of the macro processor function %EVAL to
decimal format.
GEN / GE ‡ Generates a full listing of macro expansions in the listing file.
NOGEN / NOGE ‡ List only the original source text in listing file.
INCLUDE(file) / IC ‡ Designates a file to be included as part of the program.
INCDIR / ID Define up to five additional paths to be searched when a file is
included via $INCLUDE (file).
LINK ‡ Place Linker/Locator controls in the Assembler source code.
LIST, NOLIST / LI, NOLI ‡ Print or do not print the assembler source in the listing file.
NOAMAKE Disable AMAKE information.
NOLINES Do not generate LINE number information.
NOMACRO / NOMR Disable Standard Macros
MOD166 / M166 Disable the additional 167 instructions.
NOMOD166 / NOM166 Do not recognize the predefined special function registers.
MOD167 / M167 Enable the additional 167 instructions.
NOOBLECT / NOOJ Designates that no object file will be created.
NOSYMBOLS / NOSB No symbol table is listed.
166/167 Assembler and Utilities 69
ABSOLUTE
Name: ABSOLUTE
Control-type: Primary
Arguments: None
Default: None
Example:
$ABSOLUTE
A166 SAMPLE.A66 ABSOLUTE
166/167 Assembler and Utilities 71
CASE / NOCASE
Name: CASE, NOCASE
Arguments: None
Default: NOCASE
Example:
$CASE
A166 SAMPLE.A66 CASE
72 Chapter 4. Invocation and Controls
COND / NOCOND
Name: COND/NOCOND
Abbreviation: None
Arguments: None
Default: COND
Examples:
$ COND
$ NOCOND
166/167 Assembler and Utilities 73
DATE
Name: DATE
Abbreviation: DA
Definition: the assembler takes the character specified string and places it
in the header of every page of the program listing. A fatal
error occurs if the string contains more than 9 characters.
Example:
$ DATE (05/09/92)
4
$ DA ('09-05-92')
A166 SAMPLE.A66 DATE (05/09/92)
74 Chapter 4. Invocation and Controls
DEBUG / NODEBUG
Name: DEBUG, NODEBUG
Arguments: None
Default: NODEBUG
Example:
$ DEBUG
A166 SAMPLE.A66 DEBUG
166/167 Assembler and Utilities 75
EJECT
Name: EJECT
Abbreviation: EJ
Arguments: None
Default: None
Definition: EJECT inserts a form feed into the listing file and generates a
header at the top of the next page. The control is ignored if
NOLIST or NOPRINT is in effect.
Example:
$ EJECT
4
76 Chapter 4. Invocation and Controls
ERRORPRINT / NOERRORPRINT
Name: ERRORPRINT, NOERRORPRINT
Default: NOERRORPRINT
Example:
$ ERRORPRINT (SAMPLE.ERR)
$ NOEP
A166 SAMPLE.A66 EP
166/167 Assembler and Utilities 77
EXPDECNUM
Name: EXPDECNUM
Abbreviation: EDN
Arguments: None
Example:
$ EXPDECNUM
4
A166 SETUP.A66 EXPDECNUM
78 Chapter 4. Invocation and Controls
Arguments: None
Default: NOGEN
Example:
$ NOGEN
$ GENONLY
A166 SAMPLE.A66 GEN
166/167 Assembler and Utilities 79
INCDIR
Name: INCDIR
Abbreviation: ID
Default: None
Definition: With INCDIR, you can supply one or more paths to search
for when a $INCLUDE (file) directive processed.
Example:
$ INCDIR (C:\C166\ASM)
A166 STARTUP.A66 INCDIR (C:\C166\ASM,C:\C166\MYINC)
80 Chapter 4. Invocation and Controls
INCLUDE
Name: INCLUDE
Abbreviation: IC
Default: None
Definition: INCLUDE inserts the content of the specified file into the
program immediately following the control line. INCLUDE
files may be nested. The maximum number of nesting is nine.
Example:
$ INCLUDE (REG167.INC)
166/167 Assembler and Utilities 81
LIST / NOLIST
Name: LIST, NOLIST
Arguments: None
Default: LIST
Example:
LIST and NOLIST are overridden by the NOPRINT control.
4
$ NOLIST
$ LIST
A166 SAMPLE.A66 NOLIST
82 Chapter 4. Invocation and Controls
MACRO / NOMACRO
Name: MACRO/NOMACRO
Abbreviation: None
Arguments: None
Default: MACRO
4 Examples:
$ MACRO
$ NOMACRO
166/167 Assembler and Utilities 83
MOD166 / NOMOD166
Name: MOD166, NOMOD16
Arguments: None
Default: MOD166
$ NOMOD166
$ INCLUDE (REG167.DEF)
Example:
$ NOMOD166
84 Chapter 4. Invocation and Controls
MOD167
Name: MOD167
Abbreviation: M167
Arguments: None
Default: MOD166
Example:
$ MOD167
$ INCLUDE (REG167.INC)
166/167 Assembler and Utilities 85
OBJECT / NOOBJECT
Name: OBJECT, NOOBJECT
Example:
NOOBJECT option disables the generation of an object file.
4
$ OBJECT (C:\SAMPLE.OBJ)
$ NOOJ
$ OJ (C:\SAMP.DIR\SAMPLE.OBJ)
A166 SAMPLE.A166 OBJECT (C:\OBJS\XSAMPLE.OBJ)
86 Chapter 4. Invocation and Controls
PAGELENGTH
Name: PAGELENGTH
Abbreviation: PL
Default: PAGELENGTH(69)
4 Example:
$ PAGELENGTH (132)
$ PL (75)
A166 SAMPLE.A66 PAGELENGTH (120)
166/167 Assembler and Utilities 87
PAGEWIDTH
Name: PAGEWIDTH
Abbreviation: PW
Example:
$ PW (79)
4
A166 SAMPLE.A66 PW (78)
88 Chapter 4. Invocation and Controls
PAGING / NOPAGING
Name: PAGING, NOPAGING
Arguments: None
Default: PAGING
4 Example:
PAGELENGTH directive.
$ NOPAGING
A166 SAMPLE.A66 NOPA
166/167 Assembler and Utilities 89
PRINT / NOPRINT
Name: PRINT, NOPRINT
REGUSE
Name: REGUSE
Abbreviation: RU
Default: None
The assembler does not check the actual registers used within
the procedure. It is up to you to specify the correct set of
registers, otherwise runtime problems may occur due to
overwritten register values.
NOTE
The PROC identifier should exactly match the identifier
used in the PROC definition if $CASE is used. This means,
spelling as well as lower and upper case letters should
match. If $CASE is not used, then the PROC identifier
should be written using upper case letters.
Example:
$ REGUSE p100 (R1-R2, R8, MDC, DPP3)
PUBLIC p100
166/167 Assembler and Utilities 91
ASSUME DPP3:SYSTEM
C100 SECTION CODE
C100 ENDS
END
4
92 Chapter 4. Invocation and Controls
SAVE / RESTORE
Name: SAVE/RESTORE
Abbreviation: SA/RS
Arguments: None
Default: None
4 Examples:
$ SAVE NOLIST
$ INCLUDE (REG167.INC)
$ RESTORE
166/167 Assembler and Utilities 93
SEGMENTED / NONSEGMENTED
Name: SEGMENTED, NONSEGMENTED
Arguments: None
Default: NONSEGMENTED
Examples:
$ SEGMENTED
$ SG
A166 SAMPLE.A66 SEGMENTED
94 Chapter 4. Invocation and Controls
SYMBOLS / NOSYMBOLS
Name: SYMBOLS/NOSYMBOLS
Abbreviation: SB/NOSB
Arguments: None
Default: SYMBOLS
4 Example:
$ SYMBOLS
$ NOSB
A166 SAMPLE.A66 NOSYMBOLS
166/167 Assembler and Utilities 95
TABS
Name: TABS
Abbreviation: TA
Default: TABS(8)
Example:
$ TABS (4)
A166 SAMPLE.A66 TABS (4)
4
96 Chapter 4. Invocation and Controls
TITLE
Name: TITLE
Abbreviation: TT
Definition: TITLE defines a title string that is printed in the page header
of the listing. If the TITLE control is omitted then the name
of the input file without path and extension is used for the title
4 Example:
string.
TYPE / NOTYPE
Name: TYPE / NOTYPE
Arguments: None
Default: TYPE
Definition: The TYPE directive directs A166 to put type information into
the object file. NOTYPE avoids type information in the
object file. All the symbols from the object file will be
Example:
typeless.
4
$ NOTYPE
$ A166 SETUP.A66 NOTYPE
98 Chapter 4. Invocation and Controls
USEDEXTONLY
Name: USEDEXTONLY
Abbreviation: UEO
Arguments: None
4 Example:
$ USEDEXTONLY
$ A166 SETUP.A66 USEDEXTONLY
166/167 Assembler and Utilities 99
XREF / NOXREF
Name: XREF, NOXREF
Abbreviation: XR/NOXR
Arguments: None
Default: NOXREF
Definition: XREF indicates that a cross reference table which marks the
use of symbols, is added to the symbol table. The cross
reference lists the line numbers of lines with a reference to the
symbol. A hash mark (#) following the line number indicates
that the symbol is defined in this line. The NOPRINT control
4
overrides XREF.
Example:
$ XREF
100 Chapter 4. Invocation and Controls
Text blocks to be conditionally assembled are enclosed by IF, ELSEIF, ELSE and
ENDIF.
The SET and RESET directives may be used in the invocation line of the
assembler. The remaining instructions for conditional assembly are only allowed
within the source file and cannot be part of the assembler invocation line.
Control Meaning
IF Translate block if condition is true
ELSE Translate block if the condition of a previous IF is false.
ELSEIF Translate block if condition is true and a previous IF or ELSEIF is false.
ENDIF Marks end of a block.
RESET Set symbols checked by IF or ELSEIF to false.
SET Set symbols checked by IF or ELSEIF to true or to a specified value.
166/167 Assembler and Utilities 101
SET / RESET
Name: SET/RESET
Abbreviation: none
Default: None
Examples:
$ SET (TEST, ITERATION = 3)
$ RESET (TEST, INTERATION, DEBUG_VAR)
102 Chapter 4. Invocation and Controls
IF
Name: IF
Abbreviation: none
Default: None
Examples:
$ IF (DEBUG_VAR = 3)
Version_3: MOV R8,#TABLE_3
<other text lines>
$ ENDIF
166/167 Assembler and Utilities 103
ELSEIF
Name: ELSEIF
Default: None
Example:
$ IF (SWITCH = 1)
<line(s)
$ ELSEIF (SWITCH =
<line(s)
$ ELSEIF (SWITCH =
of text>
2)
of text>
3)
4
<line(s) of text>
$ ENDIF
104 Chapter 4. Invocation and Controls
ELSE
Name: ELSE
Arguments: None
Default: None
Example:
$ IF (DEBUG) ; is true, when DEBUG != 0
4 <line(s) of text>
$ ELSEIF (TEST)
$ ELSE
<line(s) of text>
<line(s) of text>
$ ENDIF
166/167 Assembler and Utilities 105
ENDIF
Name: ENDIF
Arguments: None
Default: None
Example: 4
$ IF (TEST)
<line(s) of text>
$ ENDIF
106 Chapter 4. Invocation and Controls
4
166/167 Assembler and Utilities 107
Introduction
The Macro Processing Language (MPL) of A166 is a string replacement facility.
It permits you to write repeatedly used sections of code once and then insert that
code at several places in your program. Perhaps MPL’s most valuable capability
is conditional assembly-with all microprocessors, compact configuration
dependent code is very important to good program design. Conditional assembly of
sections of code can help to achieve the most compact code possible.
Overview
The macro processor views the source file in different terms than the assembler: to
the assembler, the source file is a series of lines--control lines, and directive lines.
To the macro processor, the source file is a long string of characters.
All macro processing of the source file is performed before your code is
assembled. Because of this independent processing of macros and assembly of
code, we must differentiate between macro-time and assembly-time. At macro-
time, assembly language symbols and labels are unknown. SET and EQU
5
symbols, and the location counter are also not known. Similarly, at assembly-time,
no information about macros is known.
The macro processor scans the source file looking for macro calls. A macro call is
a request to the processor to replace the macro name of a built-in or user-defined
macro by some replacement text.
DEFINE is the most important macro processor function. Each of the symbols in
the syntax above (macro name, parameter-list, and macro-body) are described in
the following.
macro name
The macro name defines the name used when the macro is called.
macro body
The ‘%’ is the metacharacter that signals a macro call. The ‘*’ is the literal
5 character. The use of the literal character is described later of this chapter.
The macro-body is usually the replacement text of the macro call. However, the
macro-body may contain calls to other macros. If so, the replacement text is
actually the fully expanded macro-body, including the calls to other macros. When
you define a macro using the syntax shown above, macro calls contained in the
body of the macro are not expanded, until you call the macro.
The syntax of DEFINE requires that left and right parentheses surround the
macro-body. For this reason, you must have balanced parenthesis within the
macro-body (each left parenthesis must have a succeeding right parenthesis, and
each right parenthesis must have a preceding left parenthesis). We call character
strings that meet these requirements balanced-text.
166/167 Assembler and Utilities 109
To call a macro, use the metacharacter followed by the macro name for the macro.
(The literal character is not needed when you call a user-defined macro.) The
macro processor will remove the call and insert the replacement text of the call. If
the macro- body contains any call to other macros, they will be replaced with their
replacement text.
The term parameter refers to both the formal parameters that are specified when
the macro is defined, and the actual parameters or arguments that are replaced
when the macro is called.
The example below shows the definition of a macro with three dummy parameters
- SOURCE, DESTINATION, and COUNT. The macro will produce code to copy
any number of bytes from one part of memory to another.
%*DEFINE (BMOVE (src, dst, cnt)) LOCAL lab (
MOV R2,#%cnt
110 Chapter 5. The Macro Processor
MOV R1,#%src
MOV R0,#%dst
%lab: MOVB [R0+],[R1]
ADD R1,#1
CMPD1 R2,#0
JMP CC_NZ, %lab
)
To call the above macro, you must use the metacharacter followed by the macro’s
name similar to simple macros without parameters. However, a list of the actual
parameters must follow. The actual parameters must be surrounded in the macro
definition. The actual parameters must be balanced-text and may optionally
contain calls to other macros. A simple call to the macro defined above might be
(look at line 11):
DOS MACRO ASSEMBLER A166 V3.0
OBJECT MODULE PLACED IN X.OBJ
ASSEMBLER INVOKED BY: D:\A166\A166.EXE X.A66 GENONLY
LOC OBJ LINE SOURCE
5 11
12
13
14
; invoke macro 'BMOVE' with 3 actual parameters:
;%BMOVE (array1, array2,10)
MOV R2,#10
15 MOV R1,#array1
16 MOV R0,# array2
17 LAB0: MOVB [R0+],[R1]
18 ADD R1,#1
19 CMPD1 R2,#0
20 JMP CC_NZ,LAB0
The macro BMOVE is called in line 12 with three actual parameters. Lines 14 to
20 shows the macro expansion, which is the return value of the macro call. This
text will be assembled.
166/167 Assembler and Utilities 111
The example will produce assembly errors because no section directives are
included in the source file. The purpose here is to show macro processing, not the
assembler semantics.
The solution to this problem are local symbols. Local symbols are generated by
the macro processor as ‘local_symbol_nnn’, where local_symbol is the name of
the local symbol and nnn is some number. Each time the macro is called, the
number will be automatically incremented, the resulting names will be unique on
each macro call.
The macro processor increments a counter each time your program calls a macro
that uses the LOCAL construct. The counter is incremented once for each symbol
in the LOCAL list. Symbols in the LOCAL list, when used in the macro-body,
receive a one to five digit suffix that is the decimal value of the counter. The first
time you call a macro that uses the LOCAL construct, the suffix is ‘0’.
5
The syntax for the LOCAL construct in the DEFINE functions is shown below
(this is finally the complete syntax for the macro processor function DEFINE):
%*DEFINE (macro-name (parameter-list)) [LOCAL local-list] (macro-body)
We have already seen one of these macro processor functions, DEFINE. DEFINE
creates user defined macros. Macro processor functions are already defined when
the macro processor is started.
Comment Function
The macro processing language can be very subtle, and the operation of macros
written in a straightforward manner may not be immediately obvious. Therefore,
it is often necessary to comment macro definitions. The comment function has the
following syntax:
%‘text’
%‘text end-of-line
The comment function always evaluates to the null string. Two terminating
characters are recognized, the apostrophe and the end-of-line character. The
second form allows to spread macro definitions over several lines, while avoiding
unwanted end-of-lines in the return value. In either form of the comment function,
the text or comment is not evaluated for macro calls.
5 Examples:
%'this is macro comment.' ; this is an assembler comment.
Escape Function
Sometimes it is required to prevent the macro processor from processing macro
text. Two macro processor functions perform this operation:
escape function
166/167 Assembler and Utilities 113
bracket function
The escape function interrupts scanning of macro text. The syntax of the escape
function is:
%n text-n-characters-long
Examples:
10%1% OF 10 = 1; expands to: 10% OF 10 = 1;
ASM%0166 expands to: ASM166
Bracket Function
The other macro processor function that inhibits the processing of macro text is
the bracket function. The syntax of the bracket function is:
%(balanced-text)
The bracket function disables all macro processing of the text contained within the
parentheses. However, the escape function, the comment function, and parameter
5
substitution are still recognized.
Since there is no restriction for the length of the text within the bracket function, it
is usually easier to use than the escape function.
Examples:
ASM%(166) evaluates to: ASM166
%(1,2,3,4,5) evaluates to: 1,2,3,4,5
The macro above will add word definitions to the source file. It uses two
parameters: one for the word expression list and one for the label name. Without
the bracket function it would not be possible to pass more than one expression in
the list, since the first comma would be interpreted as the delimiter separating the
actual parameters to the macro. The bracket function used in the macro call
prevents the expression list (120, 121, 122, 123, -1) from being evaluated as
separate parameters.
METACHAR Function
The macro processor function METACHAR allows the programmer to change the
character that will be recognized by the macro processor as the metacharacter.
The use of this function requires extreme care.
The first character of the balanced text is taken to be the new value of the
metachar. The characters @, (, ), *, blank, tab, and identifier-characters are not
allowed to be the metacharacter.
5 Example:
%METACHAR (!) ; change metacharacter to '!'
!(1,2,3,4) ; bracket function invoked with !
The text of the numeric expression will be expanded in the ordinary manner of
evaluating an argument to a macro function.
166/167 Assembler and Utilities 115
♦ Parenthesized Expressions
♦ HIGH, LOW
♦ *, /, MOD, SHL, SHR
♦ EQ, LT, LE, GT, GE, NE
♦ NOT
♦ AND, OR, XOR
The arithmetic is done using signed 16-bit integers. The result of the relational
operators is either 0 (FALSE) or 1 (TRUE).
Numbers:
Numbers can be specified in hexadecimal (base 16), decimal (base 10), octal (base
8) and binary (base 2). A number without an explicit base is interpreted as
decimal, this being the default representation. The first character of a number must
always be a digit between 0 and 9. Hexadecimal numbers which do not have a 5
digit as the first character must have a 0 placed in front of them.
Dollar ($) signs can be placed within the numbers to make them more readable.
However a $ sign is not allowed to be the first or last character of a number and
will not be interpreted.
Hexadecimal numbers may be also entered using the convention from the C
language:
116 Chapter 5. The Macro Processor
0xFE02 0x1234
0X5566 0x0A
Character Strings
The macro processor allows the use of ASCII characters strings in expressions.
An expression is permitted to have a string consisting of one or two characters
enclosed in single quote characters (’).
The macro processor cannot access the assembler’s symbol table. The values of
labels, SET and EQU symbols are not known during macro processing. But, the
programmer can define macro-time symbols with the macro processor function
‘SET’.
5 SET Function
The macro processor function SET permits you to define macro-time symbols.
SET takes two arguments: a valid identifier, and a numeric expression.
The SET function affects the macro processor symbol table only. Symbols
defined by SET can be redefined with a second SET function call, or defined as a
macro with DEFINE.
The SET symbol may be used in the expression that defines its own value:
Source text:
%SET (CNT, 10) %' define variable CNT'
%SET (OFS, 20) %' define variable OFS'
EVAL Function
The macro processor function EVAL accepts an expression as an argument and
5
returns the decimal character representation of its result.
The expression arguments must be a legal expression with already defined macro
identifiers, if any.
Examples:
Source text:
%SET (CNT, 10) %' define variable CNT'
%SET (OFS, 20) %' define variable OFS'
%LTS (arg1,arg2) True if first argument has a lower value than second
5 argument
%LES (arg1,arg2) True if first argument has a lower value than second
argument or if both arguments are identical
Examples:
%EQS (A166, A166) 0 (FALSE), the space after the comma is part
of the second argument
Typically, you will use either the relational operators (EQ, NE, LE, LT, GT, or
GE) or the string comparison functions (EQS, NES, LES, LTS, GTS, or GES) to
specify a logical value.
IF Function
The IF macro processor function evaluates a logical expression, and based on that
expression, expands or skips its text arguments. The syntax of the macro
processor function IF is:
%IF (expression) THEN (balanced-text1) [ ELSE (balanced-text2)] FI
5
IF first evaluates the expression, if it is TRUE, then balanced-text1 is expanded; if
it is FALSE and the optional ELSE clause is included, then balanced-text2 is
expanded. If it is FALSE and the ELSE clause is not included, the IF call returns
a null string. FI must be included to terminate the call.
IF calls can be nested; when they are, the ELSE clause refers to the most recent IF
call that is still open (not terminated by FI). FI terminates the most recent IF call
that is still open.
Example:
Source text:
%*DEFINE (ADDSUB (op,p1,p2)) (
%IF (%EQS (%op,ADD)) THEN (
ADD %p1,%p2
) ELSE (%IF (%EQS (%op,SUB)) THEN (
SUB %p1,%p2
) FI
) FI
)
120 Chapter 5. The Macro Processor
WHILE Function
Often you may wish to perform macro operations until a certain condition is met.
The macro processor function WHILE provides this facility.
5 Since the macro continues processing until expression evaluates to FALSE, the
balanced-text should modify the expression, or the WHILE may never terminate.
A call to the macro processor function EXIT will always terminate a WHILE
function. EXIT is described later.
Example:
Source text:
%SET (count, 5) %'initialize count to 5'
%WHILE (%count GT 0)
( ADD R15,R15 %SET (count, %count - 1)
)
REPEAT Function
The macro processor function REPEAT expands its balanced-text a specified
number of times. The syntax for the macro processor function REPEAT is:
%REPEAT (expression) (balanced-test)
REPEAT uses the expression for a numerical value that specifies the number of
times the balanced-text will be expanded. The expression is evaluated once when
the macro is first called, then the specified number of iterations is performed.
Examples:
Source text:
%REPEAT (5)
( -enter any key to shut down-
)
Example:
Source text:
%SET (count, 0)
%WHILE (1)
122 Chapter 5. The Macro Processor
LEN Function
The macro processor function LEN returns the length of the character string
argument in hexadecimal: The character string is limited to 256 characters.
5 The syntax for the macro processor function LEN is:
%LEN (balanced-text)
Examples:
Source text:
%LEN (A166) %' len = 4'
%LEN (A166,A166) %' comma counts also'
%LEN ()
%LEN (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
%DEFINE (TEXT) (QUEEN)
%DEFINE (LENGTH) (%LEN (%TEXT))
LENGTH OF '%TEXT' = %LENGTH.
SUBSTR Function
The macro processor function SUBSTR returns a substring of the given text
argument. The function takes three arguments: a character string to be divided and
two numeric arguments.
If expression1 is zero or greater than the length of the argument string, then
SUBSTR returns the null string. The index of the first character of the balanced
text is one.
Examples:
Source text: 5
%DEFINE (STRING) (abcdefgh)
%SUBSTR (%string, 1, 2)
%SUBSTR (%(1,2,3,4,5), 3, 20)
MATCH Function
The macro processor function MATCH searches a character string for a delimiter
character, and assigns the sub-strings on either side of the delimiter to the
identifiers.
Identifier1 and identifier2 must be valid macro identifiers. Delimiter is the first
character to follow identifier1. Typically, a space or comma is used, but any
character that is not a macro identifier character may be used. Balanced-text is the
text searched by the MATCH function. It may contain macro calls.
MATCH searches the balanced-text string for the specified delimiter. When the
delimiter is found, then all characters to the left are assigned to identifier1 and all
characters to the right are assigned to identifier2. If the delimiter is not found, the
entire balanced-text string is assigned to identifier1 and the null string is assigned
to identifier2.
Example:
Source text:
%DEFINE (text) (-1,-2,-3,-4,-5)
%MATCH (next,list) (%text)
%WHILE (%LEN (%next) NE 0)
( MOV R8,#%next
MOV [R1+],R8 %MATCH
(next,list)(%list)
)
5 MOV
MOV
MOV
R8,#-2
[R1+],R8
R8,#-3
MOV [R1+],R8
MOV R8,#-4
MOV [R1+],R8
MOV R8,#-5
MOV [R1+],R8
%OUT (balanced-text)
166/167 Assembler and Utilities 125
Examples:
Source text:
%OUT (enter baud rate)
%set (BAUD_RATE,%in)
BAUD_RATE = %BAUD_RATE
The macro call must have a call pattern which corresponds to the macro define
pattern. Regardless of the type of delimiter used to define a macro, once it has
been defined, only delimiters used in the definition can be used in the macro call.
Macros defined with parentheses and commas require parentheses and commas in
the macro call. Macros defined with spaces or any other delimiter require that
delimiter when called.
The define pattern may have three kinds of delimiters: implied blank delimiters,
identifier delimiters and literal delimiters.
126 Chapter 5. The Macro Processor
Literal Delimiters
The delimiters used in user-defined macros (parentheses and commas) are literal
delimiters. A literal delimiter can be any character except the metacharacter.
When you define a macro using a literal delimiter, you must use exactly that
delimiter when you call the macro. If the specified delimiter is not used as it
appears in the definition, a macro error occurs.
When defining a macro, the delimiter string must be literalized, if the delimiter
meets any of the following conditions:
Use the escape function (%n) or the bracket function (%()) to literalize the
delimiter string.
In the next two examples, delimiters that could be id delimiters have been defined
as literal delimiter (the differences are noted):
Blank Delimiters
Blank delimiters are the easiest to use. Blank delimiter is one or more spaces, tabs
or new lines (a carriage-return/linefeed pair) in any order. To define a macro that
uses the blank delimiter, simply place one or more spaces, tabs, or new lines
surrounding the parameter list.
When the macro defined with the blank delimiter is called, each delimiter will
match a series of spaces, tabs, or new lines. Each parameter in the call begins with
the first non-blank character, and ends when a blank character is found.
Identifier Delimiters 5
Identifier delimiters are legal macro identifiers designated as delimiters. To define
a macro that uses an identifier delimiter, you must prefix the delimiter with the @
symbol. You must separate the identifier delimiter from the macro identifiers
(formal parameters or macro name) by a blank character.
When the literal character (*) is placed in a DEFINE function, the macro
processor shifts to literal mode while expanding the macro. The effect is similar to
surrounding the entire call with the bracket function. Parameters to the literalized
call are expanded, the escape, comment, and bracket functions are also expanded,
but no further processing is performed. If there are any calls to other macros, they
are not expanded.
If there are no parameters in the macro being defined, the DEFINE function can be
called without literal character. If the macro uses parameters, the macro processor
will attempt to evaluate the formal parameters in the macro-body as parameterless
5 macro calls.
The following example illustrates the difference between defining a macro in literal
mode and normal mode:
%SET (TOM, 1)
%*DEFINE (AB) (%EVAL (%TOM))
%DEFINE (CD) (%EVAL (%TOM))
When AB and CD are defined, TOM is equal to 1. The macro body of AB has
not been evaluated due to the literal character, but the macro body of CD has been
completely evaluated, since the literal character is not used in the definition.
Changing the value of TOM has no effect on CD, but it changes the value of AB:
%SET (TOM,2) -> null string
%AB -> 2
%CD -> 1
%*CD -> 1
%*AB -> %EVAL (%TOM)
166/167 Assembler and Utilities 129
MACRO Errors
The macro processor will output error messages, if errors occur in the macro
processing phase. The errors are displayed like other assembly errors in the listing
file which is generated by the assembler anyway. The following describes the
error messages generated by the macro processor.
86
The macro definition has not been completely processed due to premature end of input file.
FUNCTION 'MATCH': ILLEGAL CALL PATTERN
The built-in function MATCH was called with an illegal call pattern. The call pattern must
5
consist of some formal name followed by a delimiter specification and another formal name.
87 FUNCTION 'EXIT' IN BAD CONTEXT
The built-in function EXIT is allowed only in WHILE and REPEAT constructs.
88 ILLEGAL METACHARACTER '<character>'
The first character of the balanced text argument to METACHAR is taken to be the new
value of the meta character. The characters @, (, ), *, blank, tab, and identifier-characters
are not allowed to be the meta character.
89 CALL PATTERN - DELIMITER '<delimiter>' NOT FOUND
The call pattern of some macro does not conform to the define pattern of that macro. The
delimiters of the macro call should be checked for conformance.
90 CALL TO UNDEFINED MACRO '<name>'
The macro call specifies the name of an undefined macro.
91 INVALID MPL COMMAND '%<character>'
The character following the meta character does not form a valid macro processor language
command.
92 INVALID DIGIT '<character>' IN NUMBER
A number of an expression contains an invalid digit.
93 UNCLOSED STRING OR CHARACTER CONSTANT
94 INVALID STRING OR CHARACTER CONSTANT
The string representing a number in an expression is invalid. The string must be either one
or two characters long. A character constant must not be longer than one character. Strings
or character constants must be enclosed by single or double quotes.
130 Chapter 5. The Macro Processor
5
166/167 Assembler and Utilities 131
Fatal Errors:
Fatal errors are for example errors encountered on the invocation of the assembler.
These errors cause a message to be issued at the console. The assembler run is
then terminated immediately.
Non-Fatal Errors:
Non-fatal errors are syntax or semantic errors in the source file. An error message
is issued in the listing file. The assembler continues assembling the source file.
Fatal Errors
Fatal errors usually occur in the invocation line. Another cause can be that the
nesting of input files is greater than the maximum allowed. In this case a message
having one of the following formats is printed at the screen:
A166 FATAL ERROR -
ACTION: <current action>
FILE: <filename in which the error occurs>
ERROR: <error message with description>
A166 TERMINATED.
FILE is the file that could not be opened. The message ‘FILE’ is output if the
error occurred due to a file.
6
ELSEIF, ELSE, ENDIF and EJECT.
EXPECTED DELIMITER ‘(’ AFTER CONTROL
The argument of an option must be enclosed by a left parenthesis.
EXPECTED DELIMITER ‘)’ AFTER ARGUMENT
The argument of an option must be enclosed by a right parenthesis.
UNKNOWN CONTROL
The control directive is unknown and therefore illegal.
BAD NUMERIC CONSTANT
The numerical argument to an option contains illegal characters. Numerical
parameters can be specified in decimal or hexadecimal and must start with a
number between 0 and 9. Hexadecimal numbers are specified by a trailing
‘H’, e.g. VAR1=0FFFEH, VAR2=55H).
166/167 Assembler and Utilities 133
Non-Fatal Errors
Non-fatal errors are encountered within the source code. They are usually syntax
errors, for example undefined symbols are used or the arguments of a particular
166/167 machine instruction are illegal. The A166 assembler prints the errors in
the listing file as follows:
DOS MACRO ASSEMBLER A166 V3.0
OBJECT MODULE PLACED IN X.OBJ
ASSEMBLER INVOKED BY: D:\A166\A166.EXE X.A66
6 Most of the errors are indicated by an up arrow character to the first incorrect
character encountered. It is also possible that the position indicated is due to a
previous error, because a previous error has given the following arguments a
different meaning.
If a source line contains more errors then the position indications are displayed in
subsequent lines. With more than five errors in a row, the first five errors are
displayed as usual. Additionally the following message may appears:
*** MORE ERRORS DETECTED, NOT REPORTED.
166/167 Assembler and Utilities 135
10
SEGMENTED, and NONSEGMENTED.
MISPLACED CONDITIONAL CONTROL
6
The given control directive (ELSE, ELSEIF, ENDIF) is encountered in illegal context. The
directives ELSEIF, ELSE and ENDIF must be preceded by an IF directive.
11 BAD CONDITIONAL EXPRESSION
The expression to the IF or ELSEIF directive is incorrect. These expressions must be
absolute and may not contain relocatable symbols. When using $IF and $ELSEIF, only the
$SET- and $RESET symbols can be accessed.
12 UNBALANCED IF-ENDIF-CONTROLS
Each IF-Block must be terminated with an ENDIF directive. This is also true on nested IF
blocks since the assembler looks on these directives, even if they are skipped.
13 SAVE STACK UNDERFLOW
A $RESTORE directive is valid only if a previous $SAVE directive has been performed.
14 SAVE STACK OVERFLOW
The SAVE directive me be nested up to a maximum level of 9.
136 Chapter 6. Error Messages
The absolute addresses for sections may not be greater than the valid address space from
the 166/167 (256K or 0 to 3FFFFH)
20 NON NULL ARGUMENT EXPECTED
A control directive of a control line (introduced by $) expected some argument. The argument
was missing.
21 '(' EXPECTED
An opening parentheses was expected by context, but something other has been found.
22 ')' EXPECTED
A closing parentheses was expected by context, but something other has been found.
23 IDENTIFIER EXPECTED
An identifier was expected by context, but something other has been found.
24 DIVISION BY ZERO ERROR
A division by zero was attempted while calculating an expression. The expression is
6 25
incorrect.
SYMBOL REDEFINITION
An attempt was made to redefine an existing symbol. The definition was ignored.
26 MORE THAN 10 NESTED SECTIONS, SECTION IGNORED
Sections may be nested up to a maximum level of 10. In case of deeper nesting, the sections
are ignored.
27 MISPLACED DIRECTIVE
The ENDS directive was out of context. ENDS is allowed to close a previous opened section
only.
28 'SECTION NAME' EXPECTED
The argument to the ENDS directive must be the name of the section previously opened.
Note that sections must be closed inside out, that means, the last recent opened section
must be closed first.
6 77
An attempt was made to write to location is marked read only. An example to this is a store
to the special-function-register ZEROS, which is a read only register.
MISSING 'DPP' INFORMATION
An operand of some instruction is not addressable. This occurs if in segmented mode a
variable is accessed which has no corresponding data page register (DPP). Use the
ASSUME directive to give the assembler a hint about which DPP will hold the base of the
section which the variable is member of.
78 'FAR RETURN' IN NON FAR PROCEDURE
A return instruction of type 'FAR' has been coded into a procedure of type 'NEAR'. This may
cause runtime stack problems. Use the software instruction RET in order to get a return of
appropriate type.
79 'NEAR RETURN' IN NON NEAR PROCEDURE
A return instruction of type 'NEAR' has been coded into a procedure of type 'FAR'. or in an
interrupt procedure (TASK) This may cause runtime stack problems. Use the software
instruction RET in order to get a return of appropriate type.
80 'INTERRUPT RETURN' IN NON INTERRUPT PROCEDURE
A return instruction of type RETI has been coded into a non interrupt procedure. This may
cause runtime stack problems and interrupt problems. Use the software instruction RET in
order to get a return of appropriate type.
166/167 Assembler and Utilities 141
6
144 Chapter 6. Error Messages
6
166/167 Assembler and Utilities 145
Implementation limits.
The 166/167 instruction set implemented in the A166 Assembler.
Reserved words and predefined system names.
Implementation Limits
Fixed internal limits are minimal. Most of the internal data structures are limited
by available memory only. The fixed limits (some introduced by the underlying
DOS) are listed below:
Parameter Value
Level Of Invocation File Nesting 9
Length Of An Identifier 80 Characters
Maximum Length Of A Line 510 Characters
Number Of Section Definitions Limited By Available Memory
Number Of Group Definitions Limited By Available Memory
Maximum Section Nesting 10
Maximum Number Of Symbols 6000 Per Module
Arithmetic Instructions
Byte/Word Add ADDB ADDW
Byte/Word Add With Carry ADDC BADDC
Byte/Word Sub SUBB SUBW
Byte/Word Sub With Carry SUBCB SUBCW
Word Mul Signed/Unsigned (16x16) MUL MULU
Word Div Signed/Unsigned (16/16) DIV DIVU
32/16 Bit Signed/Unsigned Div DIVL DIVLU
Byte/Word 1’s Complement CPLB CPLW
Byte/Word 2’s Complement NEGB NEGW
Move Instructions
Byte/Word Data Move MOVB MOVW
Byte Load & Zero Extend To Word MOVBZ
Byte Load & Sign Extend To Word MOVBS
Logical Instructions
Byte/Word Bitwise AND ANDB ANDW
Byte/Word Bitwise XOR XORB XORW
Byte/Word Bitwise OR ORB ORW
7
Return Instructions
Return From Near Procedure RET
Return From Far Procedure RETS
Return From Interrupt Procedure RETI
Pop Register & Return From Procedure RETP
148 Chapter 7. Implementation Specifics
Miscellaneous Instructions
Determine The Number Of Shifts Required To Normalize A
Word PRIOR
No Operation (Two Byte Instruction) NOP
Begin Extend Page Sequence (167) EXTP
Begin Extend Segment Sequence (167) EXTS
Begin Extended Register Sequence (167) EXTR
7 CPL
NEG
CPLW, CPLB
NEGW, NEGB
Word, Byte
Word, Byte
SUB SUBW, SUBB Word, Byte
SUBC SUBCW, SUBCB Word, Byte
AND ANDW, ANDB, BAND Word, Byte, Bit
CMP CMPW, CMPB, BCMP Word, Byte, Bit
MOV MOVW, MOVB, BMOV Word, Byte, Bit
OR ORW, ORB, BOR Word, Byte, Bit
XOR XORW, XORB, BXOR Word, Byte, Bit
CALL CALLA Absolute
166/167 Assembler and Utilities 149
7
166/167 Assembler and Utilities 151
7
152 Chapter 7. Implementation Specifics
7
166/167 Assembler and Utilities 153
Links 166 object modules generated by the A166 assembler or the C166
compiler,
Links object files that are stored in library files generated with LIB166,
Builds real-time applications using the RTX 166 Real-Time Executive,
Refer to the following figure for an overview of the development process and the
files accepted by 166 Utilities and 166 tool chain.
Object Files
from Keil RTX-166
Real-Time 166 Library
A166 or
OS Files
C166
LIB166 L166
Library Manager Linker/Locater
MAP
File
166 Library Absolute
Object
File
File
HEX
File
8
PROM Programmer
154 Chapter 8. L166 Linker/Locator
Programs you create using the A166 assembler and the C166 C compiler must be
linked using the L166 linker/locator. You cannot execute or simulate programs
that are not linked, even if they consist of only one source module.
The L166 linker/locator links one or more object modules together and resolves
references from one to the other. This lets you create a large program that is
spread over a number of source and object modules. The L166 linker/locator
provides the following functions:
All of these operations are described in detail in the remaining sections of this
chapter.
8 “L166 Overview” on page 155 provides you with a summary of the features and
capabilities of the L166 linker/locator. This chapter introduces the concepts of
what a linker is and does.
166/167 Assembler and Utilities 155
“Linking Programs with L166” on page 161 describes how to invoke the linker
from the command line. The command-line arguments are discussed, and
examples are provided.
“Definition of the Physical Memory Layout” on page 203 explains the assignment
of the C166 class and section names to physical 166/167 memory.
“Error Messages” on page 210 lists the errors that you may encounter when you
use the L166 linker/locator.
L166 Overview
The L166 linker/locator takes the object files and library files you specify and
generates an absolute object file and a map file. The absolute object file contains
complete type and debug information for HLL debuggers and emulators. The map
file contains text information about the link process.
Absolute object files may be converted into Intel HEX files by the OH166
object-HEX converter. Refer to “Appendix B. OH166 Object-Hex Converter” on
page 239 for more information.
For library files a module list can be stated. In this case, the specified modules
from the library are always linked to the application program independent of
unresolved external symbols.
Sections
Programs comprise pieces called sections, which are the basic memory units for
the link/locate process. Sections are usually related to the hardware configuration;
therefore the portions of programs that are to be kept in ROM are in separate
sections from the portions that will be kept in RAM or bit memory. The A166
Assembler allows the programmer to name the sections of the program being
developed. The C166 compiler generates predefined section names.
L166 combines all sections with the same complete (section, class and tgroup)
name and same combine type (PUBLIC, COMMON, STACK, …) from all input
modules. The way in which sections are combined depends on the section
alignment and the combine type.
8 Section Alignment
A section can have one of the following alignment attributes.
Any alignment attribute except BYTE and BIT can result in a gap between
combined sections. For example, when two DWORD-aligned sections are
combined, there will be a gap, when the first section length is not a multiple of 4.
Combining Sections
Sections with the combine types PUBLIC and GLOBAL are combined end to end.
There may be a gap between the sections if the alignment requires it. The relative
addresses in the sections are adjusted for the new longer section.
Sections with the combine type COMMON are overlaid with their low addresses
at a common address. The length of the combined memory section is the length of
the largest partial section that was combined.
To make sure that sections are combined correctly, you should always give them
the same section and class name in each module.
Classes
8
A class is a collection of sections. When sections are defined in A166, a class
name can be specified. The sections generated by C166 have predefined class
158 Chapter 8. L166 Linker/Locator
names. Any number of sections can be given the same class name. The same class
name can be used in different modules.
Class names give a section a second means for locating. In a typical program with
several modules that are to be combined, the sections containing executable code
which is near addressed the class name NCODE can be given in each module.
All sections with the same class name are located together in the same memory
address space of the output module. This class collection can be overwritten by
specifying the location of sections with the L166 control directive SECTIONS.
Groups
A group is also a collection of sections. Groups define addressing range
limitations in 166/167 object modules. The 166/167 knows two different groups:
For allocation sequence of the physical 166/167 memory, the section type, the
alignment type and the entry of the SECTIONS, CLASSES or GROUPS directive
in L166 invocation are considered. L166 allocates the physical 166/167 memory
in following sequence:
1. Interrupt vectors.
2. Absolute registerbanks.
3. Absolute sections (specifies with the at attribute).
4. Sections specified in the l166 sections directive.
5. Other registerbanks.
6. Bit-addressable data sections.
7. Bit sections.
8. Classes whose range is smaller than a data page (16 kb).
9. Groups specified with the l166 groups directive.
10. Groups containing an absolute section.
11. Other groups.
12. Sections with a class name.
13. Other sections.
L166 processes modules with public and external references. During the L166
run, a table of all public and external references is build. External references are
8
resolved with public references, if the symbol name and symbol representation
corresponds. An error occurs if the symbol representation do not correspond, or if
no public symbol is found for the external symbol reference. Absolute addresses of
160 Chapter 8. L166 Linker/Locator
the public symbols are calculated after the sections are located to the physical
166/167 memory.
After allocation of the physical 166/167 memory and the processing of external
and public symbols is completed, all relocatable and external addresses are
calculated. At the same time the symbol information (if available) in the absolute
object file is altered to reflect the new values. This is required to allow symbolic
program debugging with dScope or emulators.
The filenames and control directives of the L166 invocation command line.
File and module names of all processed modules.
A list of all TGROUPS contained in the program (if available).
A list of all interrupt procedures with interrupt vector and interrupt name.
A table of memory allocation (MEMORY MAP) which contains start address,
stop address and size of the sections, section type, alignment, tgroup index,
group index, combine type, class name and section name. This table may be
suppressed by the NOMAP control directive.
The group list displays all group names with group type, classes and sections
8 assigned to this group. The group list may be suppressed by the NOMAP
control directive.
A table of all public symbols contained in the program. This table displays
the symbol value, symbol name, symbol representation, tgroup index, class
name and section name which is assigned to that symbol.
166/167 Assembler and Utilities 161
or
162 Chapter 8. L166 Linker/Locator
L166 @commandfile
where:
inputlist is a list of the object files, separated by commas, for the
linker/locator to include in the final absolute object module or
banked object module . The files named in the inputlist can
contain both absolute and relocatable program modules which are
combined to form the final absolute object module. Additionally,
you may force modules from library files to be included by
specifying their names in parentheses immediately following the
library file name.
outputfile is the name of the absolute object file that the linker/locator
creates. If no outputfile is specified on the command line, the
first filename in the input list is used. The basename of the
outputfile is used as base for the .M66 linker MAP file.
directives are commands and parameters that control the operation of the
L166 linker/locator.
commandfile is the name of a command input file that may contain an
inputlist, outputfile, and directives.
filename (modulename , … ) , …
where
filename is the name of an object file created by the C166 compiler or the
A166 assembler or a library file created by the LIB166 library
manager. The filename must be specified with its file
extension. Object files use the extension .OBJ. Library files use
the extension .LIB.
modulename is the name of an object module in the library file. The
modulename may only be used after the name of a library file.
The modulenames must be specified in parentheses after the
Command Files
In addition to using the ampersand character, you may specify all command-line
arguments for the L166 linker/locator in a command file. This has the same
format as a normal command line and may be produced by a text editor. The
L166 linker/locator interprets the first filename preceded by an at sign (‘@’) as a
command file.
Command-Line Examples
The following examples are proper command lines for the L166 linker/locator.
L166 C:\MYDIR\PROG.OBJ TO C:\MYDIR\PROG.ABS
In this example unresolved external symbols are resolved with the public symbols
of the library file UTILITY.LIB. The necessary modules of the library are linked
automatically. Modules with no references are not processed. 8
L166 PROG1.OBJ, PROG2.OBJ, UTILITY.LIB (IN, OUT)
164 Chapter 8. L166 Linker/Locator
Contrary to the preceding examples the modules IN and OUT from the library file
UTILITY.LIB are linked in any case.
Output File
The output file is the name of the file to which the absolute object file is written.
If no output file is entered, L166 generates the name of the output file from the
first input file without the extension. An error message occurs if the first input file
contains no extension, as would occur in this case:
L166 PROG1
In the previous case the name of the output file is identical with that of the input
file, and this is an error. But by entering:
L166 PROG1 TO PROG1.ABS
The output file PROG1.ABS is used and an error does not occur.
DOS Errorlevel
After linking, the L166 linker/locator sets the DOS ERRORLEVEL to indicate the
status of the linking process. Values are listed in the following table.
Errorlevel Meaning
0 No Errors Or Warnings
1 Warnings Only
2 Errors And Possibly Also Warnings
3 Fatal Errors
You can access the ERRORLEVEL variable in DOS batch files. Refer to your
DOS User’s Guide for more information about ERRORLEVEL or batch files.
Command-Line Directives
Command-line directives may be entered after the output file specification.
Multiple directives must be separated by at least one space character (‘ ’). Each
directive may be entered only once on the command line. If a directive is entered
twice, the L166 linker/locator reports an error.
The following table lists all L166 linker/locator directives along with their
abbreviations and brief descriptions.
The following table describes the terms used to define the L166 command line
directives:
Term Definition
name Names may be up to 40 characters long and must start with a letter ('A' - 'Z') or
with a '?', '_' mark or a '@' sign. The further characters may contain numbers ('0' -
'9'). Names are used as module or section, class or group names.
symbolname A name interpreted as symbol name.
modulename A name interpreted as module name.
sectionname A name interpreted as section name.
classname A name interpreted as class name.
groupname A name interpreted as group name.
filename A filename in the general DOS form:
[drive:][directory\]file[.ext]
where:
drive: is a reference to a disk drive.
directory\ is a DOS subdirectory. This entry may be repeated.
file is the name of the file (max. 8 characters).
.ext is the extension of the filename.
value A numeric value given in decimal, hex, bit or octal notation.
Examples: 1011B, 2048D (or only 2048), 0D5FFH, 0x12FFF.
8 address
In addition L166 supports bit values in the form:
value.bitno whereby bitno is a number in the range 0-15.
A value interpreted as address.
166/167 Assembler and Utilities 167
Term Definition
range An address range in the form:
start_address [- end_address]
The start_address is the first address specified by the range.
The end_address is optional an specifies the last address with is included in the
address range.
8
168 Chapter 8. L166 Linker/Locator
ASSIGN
Syntax: ASSIGN (symbolname (value) [, …])
Abbreviation: AS
NOTE
Public symbols defined with the ASSIGN control directive
exists only at locate time and cannot be accessed in dScope
or emulators.
8
166/167 Assembler and Utilities 169
CLASSES
Syntax: CLASSES (classname [(range [, range ])] [, …])
Abbreviation: CL
8
170 Chapter 8. L166 Linker/Locator
DPPUSE
Syntax: DPPUSE (dppnr = NDATA (range),
dppnr = NCONST (range))
Abbreviation: DU
Description: DPPUSE allows you to re-assign the DPP registers for the
C166 groups NDATA and NCONST. With DPPUSE you
can extend the DATA and NCONST groups to a total of
64KB. This allows fast variable access with 16-bit
addresses. Refer also to “Definition of the Physical Memory
Layout” on page 203. The arguments for the DPPUSE
directive are described below:
In this example you are using DPP0, DPP1, and DPP2 for
accessing the NDATA group. DPP0 is loaded with the value
8 pointing to address 20000H. DPP1 is loaded with the value
9 pointing to the address 24000H. DPP2 is loaded with the
value 10 pointing to address 28000H. With this DPP values
you can access the address range 20000H - 2BFFFH with
short (16-bit) addresses rather than using a far or huge
address. For the NCONST group the DPP3 register is used.
8 For efficient access to 166/167 SFR registers of the 166/167
this register must be loaded with 3. This allows to access the
range 0C000H - 0FFFFH.
166/167 Assembler and Utilities 171
NOTES
The DPP3 register must contain always the value 3.
Whenever you are using the DPP3 register for the NDATA
or NCONST group the address range must fit into PAGE 3
of the 166/167 address space. (Address range 0C000H -
0FFFFH).
RESTRICTIONS:
If you are using DPP0 for accessing NDATA or NCONST
groups, you need to select the MOD167 directive for
accessing far/huge/xhuge objects. In the 166 mode it is not
possible to use far/huge/xhuge addressing, since the DPP0
value is overwritten.
GROUPS
Syntax: GROUPS (groupname [(address)] [, …])
Abbreviation: GR
8
166/167 Assembler and Utilities 173
INTNO
Syntax: INTNO (interruptsymbol (trapnumber) [, …])
Abbreviation: IN
This example defines the trap number 0x20 for the following
interrupt procedure declaration in a C source file:
void intrpt (void) interrupt TIMER0 { ...
8
174 Chapter 8. L166 Linker/Locator
IXREF
Syntax: IXREF [ ( NOGENERATED, NOLIBRARIES ) ]
Abbreviation: IX
8
166/167 Assembler and Utilities 175
LINKONLY
Syntax: LINKONLY
Abbreviation: LO
8
176 Chapter 8. L166 Linker/Locator
NAME
Syntax: NAME (modulename)
Abbreviation: NA
8
166/167 Assembler and Utilities 177
NOAMAKE
Abbreviation: None
Arguments: None
8
178 Chapter 8. L166 Linker/Locator
NOCASE
Syntax: NOCASE
Abbreviation: NOCA
8
166/167 Assembler and Utilities 179
NOCOMMENTS
Syntax: NOCOMMENTS
Abbreviation: NOCM
8
180 Chapter 8. L166 Linker/Locator
NODEFAULTLIBRARY
Syntax: NODEFAULTLIBRARY
Abbreviation: NLIB
NOINIT
Syntax: NOINIT
Abbreviation: NOIN
8
182 Chapter 8. L166 Linker/Locator
NOLINES
Syntax: NOLINES
Abbreviation: NOLI
8
166/167 Assembler and Utilities 183
NOMAP
Syntax: NOMAP
Abbreviation: NOMA
Description: NOMAP removes the memory map and the group list from
the listing file. The memory map contains information about
the physical 166/167 memory layout and displays the address
assignment of program sections.
L166 file1.obj NOMAP
Example:
8
184 Chapter 8. L166 Linker/Locator
NOPUBLICS
Syntax: NOPUBLICS
Abbreviation: NOPU
8
166/167 Assembler and Utilities 185
NOTYPE
Syntax: NOTYPE
Abbreviation: NOTY
8
186 Chapter 8. L166 Linker/Locator
NOVECTAB
Syntax: NOVECTAB
Abbreviation: NOVT
8
166/167 Assembler and Utilities 187
OBJECTCONTROLS
Syntax: OBJECTCONTROLS ( subcontrol [, …])
Abbreviation: OC
With this L166 invocation only line numbers and local debug
symbols are removed from the output file.
8
188 Chapter 8. L166 Linker/Locator
PAGELENGTH
Syntax: PAGELENGTH (number)
Abbreviation: PL
In this example the page length for the listing file is set to 55
lines per page.
8
166/167 Assembler and Utilities 189
PAGEWIDTH
Syntax: PAGEWIDTH (number)
Abbreviation: PW
8
190 Chapter 8. L166 Linker/Locator
PRINT
Syntax: PRINT (filename)
Abbreviation: PR
8
166/167 Assembler and Utilities 191
PRINTCONTROLS
Syntax: PRINTCONTROLS ( subcontrol [, …])
Abbreviation: PC
With this L166 invocation only line numbers and local debug
symbols are removed from the listing file.
8
192 Chapter 8. L166 Linker/Locator
PUBLICSONLY
Syntax: PUBLICSONLY (inputfile)
Abbreviation: PO
8
166/167 Assembler and Utilities 193
PURGE
Syntax: PURGE
Abbreviation: PU
8
194 Chapter 8. L166 Linker/Locator
REGBANK
Abbreviation: RB
8
166/167 Assembler and Utilities 195
REGFILE
Abbreviation: RF
Description: The REGFILE directive lets you specify the name of the
register usage file generated by the L166 linker/locator. The
information in this file is used by the C166 compiler when
generating code for each function invocation. The C166
compiler uses the register usage information generated by the
linker to optimize the use of registers when passing values to
and returning values from external functions. This directive
facilitates global register optimization.
L166 MYPROG.OBJ,A.OBJ,B.OBJ REGFILE(PROG.REG)
Example:
8
196 Chapter 8. L166 Linker/Locator
RESERVE
Syntax: RESERVE (startaddress - endaddress [, …] )
Abbreviation: RE
8
166/167 Assembler and Utilities 197
RTX166
Abbreviation: None
Arguments: None
8
198 Chapter 8. L166 Linker/Locator
RTX166TINY
Abbreviation: None
Arguments: None
8
166/167 Assembler and Utilities 199
SECSIZE
Syntax: SECSIZE (sectionname[%classname] (size))
Abbreviation: SS
The value size specifies the change of the section size. There
are three ways of specifying this value:
8
200 Chapter 8. L166 Linker/Locator
SECTIONS
Syntax: SECTIONS (sectionname[%classname] [(addr)] [, …])
Abbreviation: SE
The user has the choice to define the start address of one or
all sections within the location parameter. If an address is
defined the section is located at that memory address. A
warning message is displayed if this section overlaps with
other sections.
In this example the section with the name ‘?PR?ABC’ and the
class name ‘NCODE’ is located to address 0x12000.
L166 abc.obj SECTIONS (?PR?ABC%NCODE (0x12000), &
?CO?ABC%NCONST))
VECTAB
Abbreviation: VT
8
202 Chapter 8. L166 Linker/Locator
WARNINGLEVEL
Abbreviation: WL
8
166/167 Assembler and Utilities 203
Before the program is assigned to physical memory devices, the structure of the
166/167 must be defined. Unless you are using the DPPUSE directive, it should
be noted that a near address data area must reside in one data page (16 KB
block); a near address code are must reside in one code segment (64 KB block).
The on-chip RAM (address range 0FA00H-0FFFFH) of the 166 should not be
used for program code or constant values.
Example 1:
The following example assumes the following memory areas. Because of the
hardware structure of an 166 system, the address 0 must be occupied by a ROM.
We are also using the SMALL memory model in this example; therefore the
complete code is located into the NCODE class.
To specify this memory layout L166 should be invoked with the following
CLASSES control directive. The example assumes that the program uses the
SMALL memory model and that the memory space far is not used. The sections
?C_INITSEC and ?C_MEMCLRSEC must be placed anywhere in the ROM
space. This must be specified in a separate SECTIONS directive.
L166 <input_files> .
CLASSES (ICODE (0 - 0x7FFF),
NCONST (0x4000 - 0x7FFF),
NDATA (0x8000 - 0xBFFF), NDATA0 (0x8000 - 0xBFFF),
NCODE (0x10000 - 0x1FFFF))
SECTIONS (?C_INITSEC (0x400), ?C_MEMCLRSEC)
8
Example 2:
In addition to the example above, the next system contains an second RAM area,
which should be used for far/huge/xhuge addressed data variables. This example
204 Chapter 8. L166 Linker/Locator
is using the LARGE memory model; the code is placed in the FCODE class by the
C166 compiler.
Example 3:
The following example assumes a system with battery back-up RAM (NVRAM).
If the size of the NVRAM is not critical, it should be also used for initialized near
addressed data objects. C166 provide with the #pragma NOINIT an easy way to
prevent certain objects from zero initialization as required for systems with
NVRAM.
8
166/167 Assembler and Utilities 205
NOTE
The classname specified in the CLASSES directive overwrite the default settings
of this control. Other default settings for example for IDATA, BIT or SDATA
classes are still valid and are not changed as long as not other address range is
given. Therefore, only those class names are entered where the default address
range does not fit to the memory layout used in the actual 166/167 hardware.
It is also not required to specify a range for CLASS which you are not using in
your application. For example, if you are not using xhuge objects you need not
to specify ranges for the XDATA, XDATA0 and XCONST class.
Advanced Techniques
The following example shows the memory definition for a very complex system
with the C167CR device. The C166 HLARGE memory model is used for this
application. We are using both huge and xhuge variables, but no far objects in
this application. The additional on-chip XBUS RAM of the C167CR is used for
sdata variables.
The DPPUSE directive is used to define a 48KB NDATA area and a 8KB
NCONST area in page 3 of the memory. The on-chip RAM is accessed with idata
variables. The C167CR CAN Module is access with the CAN167.H definition 8
file.
206 Chapter 8. L166 Linker/Locator
The following figure shows the memory layout of this C167CR system.
0x4BFFF
48 KB near data space DPP2 = 0x48000
DPP1 = 0x44000
DPP0 = 0x40000
This example uses 256KB
ROM space for far code
and constants starting @
0.
0x10000
0xFDFF
Internal RAM
0xF600
0xEFFF
CAN Module
0xE7FF
On-chip sdata XRAM
0xE000
NCONST space
DPP3 = 0xC000
256 KB ROM area 0 ..
0x3FFFF
0
To specify the memory layout for this example, the L166 linker is invoked with
the following control directives.
L166 <input_files> .
DPPUSE (3 = NCONST (0xC000 - 0xDFFF), 0 = NDATA (0x40000 - 0x4BFFF)
SECTIONS (?C_INITSEC (0x10000), ?C_MEMCLRSEC)
RESERVE (0xE7FF - 0xEFFF) /* for CAN Module */
CLASSES (ICODE (0 - 0xDFFF),
FCODE (0 - 0xDFFF, 0x10000 - 0x3FFFF)
HCONST (0x10000 - 0x3FFFF), XCONST (0x10000 - 0x3FFFF),
HDATA (0x4C000 - 0x7FFFF), HDATA0 (0x4c000 - 0x7FFFF),
XDATA (0x4C000 - 0x2FFFF), XDATA0 (0x4C000 - 0x7FFFF),
SDATA (0xE000 - 0xE7FF), IDATA (0xF800 - 0xFDFF))
8
166/167 Assembler and Utilities 207
TGROUPS at L166 level are like using blocks on C source level. TGROUPS
perform a block structure for PUBLIC symbols, sections and groups on
linker/locator level. This concept is similar to the isolation of automatic symbols in
a C source.
Example:
where 8
taskname is a TGROUP identifier used in dScope or emulators.
inputlist is a list of object file names as described in section “Linking
Programs with L166” on page 161.
208 Chapter 8. L166 Linker/Locator
PUBLIC symbols which should be accessed from all TGROUPS must be defined
as GLOBAL symbol (only possible with A166). A second way is to state the
module containing the PUBLIC symbol outside of the TGROUP braces.
Example:
L166 { module1.obj }, { module2.obj }, printf.obj
In this example the PUBLIC symbols contained in the file ‘printf.obj’ can be
accessed from object files of both TGROUPS ‘module1.obj’ and ‘module2.obj’.
TGROUPS isolate symbols, sections, interrupt names and group names from other
modules. Therefore in is required that the L166 controls ASSIGN, GROUPS,
INTNO, SECSIZE and SECTIONS can be applied also to the same section name
in different TGROUPS. This controls can be stated inside the TGROUP braces
(‘{’ and ‘}’) and refer in this case only to sections defined inside this TGROUP.
LOC166 @DEMO.ILO
166/167 Assembler and Utilities 209
Content of DEMO.ILO:
TASK INTNO intno_tsk1 = 22H MOD_TSK1
ADDRESSES (GROUPS (ram_grp_0(200H))
TASK INTNO intno_tsk2 = 23H MOD_TSK2
ADDRESSES (GROUPS (ram_grp_3 (3C000H))
CLASSES ('rom_tsk1' (10000H - 1FFFFH),
'rom_tsk2' (20000H - 2FFFFH))
Content of DEMO.L66:
{ MOD_TSK1.OBJ, MODA_TSK1.OBJ, MODA_TSK1.OBJ
INTNO (intno_tsk1 (22H)) GROUPS (ram_grp_0 (200H)) },
{ MOD_TSK2.OBJ, MODA_TSK2.OBJ, MODA_TSK2.OBJ
INTNO (intno_tsk2 (23H)) GROUPS (ram_grp_3 (3C000H)) }
CLASSES (rom_tsk1 (10000H - 1FFFFH),
rom_tsk2 (20000H - 2FFFFH))
TGROUPS are implemented for compatibility to Siemens tools and should only be
used when required. Currently not all emulators support TGROUPS. Therefore
debugging can become complex if TGROUPS are used in a 166/167 program.
Contact your emulator vendor for more information about debugging 166/167
programs with TGROUPS.
8
210 Chapter 8. L166 Linker/Locator
Error Messages
L166 error messages describe warnings, non fatal errors and fatal errors. A
warning is a message that may or may not have been intended by the user. In this
case the listing file can be very useful. Warnings and errors do not abort the
Linker/Locator operation. However an error may result in an output module that
cannot be used. A fatal error aborts the L166 operation.
Error messages are displayed in the listing file and on the screen.
This section lists all L166 Linker/Locator error messages, together with their
causes and any recovery actions.
Warnings
Warning Warning Message and Description
1 UNRESOLVED EXTERNAL SYMBOLS DURING LINK PROCESS
SYMBOL: external-name
MODULE: filename (modulename)
The specified external symbol, requested in the specified module, has no
corresponding PUBLIC symbol in any of the input files. If you are using the
LINKONLY directive, this symbols can be resolved in a sub-sequent link/locate run.
3 ASSIGNED ADDRESS NOT COMPATIBLE WITH ALIGNMENT
SECTION: section-name
CLASS: class-name
The address specified for the section is not compatible with the alignment of the
section declaration.
4 MEMORY SPACE OVERLAP
FROM: byte.bit address
TO: byte.bit address
The specified memory area is occupied by more than one section or is reserved by the
RESERVE directive of L166. Please verify the memory MAP of the 166/167 program.
5 SECTION LOCATED OUTSIDE CLASS AREA
SECTION: section-name
CLASS: class-name
The specified section is not located within the class address range specified for the
class name.
7 MODULE NAME NOT UNIQUE
MODULE: filename (modulename)
8 8
The specified module name is used for more than one module. The specified module
name is not processed.
MODULE NAME EXPLICITLY REQUESTED FROM ANOTHER FILE
MODULE: filename (modulename)
The specified module name is requested in the invocation line of another file that has
not yet been processed. The specified module name is not processed.
166/167 Assembler and Utilities 211
Fatal Errors
Error Error Message and Description
201 INVALID COMMAND LINE SYNTAX
partial command line
A syntax error is detected in the command line. The command line is displayed up to
and including the point of error.
202 INVALID COMMAND LINE, TOKEN TOO LONG
partial command line
The command line contains a token that is too long. The command line is displayed
up to and including the point of error.
203 EXPECTED ITEM MISSING
partial command line
An expected item is missing in the command line. The command line is displayed up
to and including the point of error.
204 INVALID KEYWORD
partial command line
The invocation line contains an invalid keyword. The command line is displayed up to
and including the point of error.
205 CONSTANT TOO LARGE
partial command line
A constant in the invocation line is larger than 0FFFFH. The command line is
displayed up to and including the point of error.
206 INVALID CONSTANT
partial command line
A constant in the invocation line is invalid (example a hexadecimal number with a
leading letter). The command line is displayed up to and including the point of error.
207 INVALID NAME
partial command line
A module, section, class or group name is invalid. The command line is displayed up
208
to and including the point of error.
INVALID FILENAME
partial command line
8
A filename is invalid. The command line is displayed up to and including the point of
error.
216 Chapter 8. L166 Linker/Locator
8 FILE: filename
The specified input module is invalid. This error could be the result of an assembler
error.
221 MODULE SPECIFIED MORE THAN ONCE
partial command line
The invocation line contains the specified module more than once. The command line
is displayed up to and including the point of error.
166/167 Assembler and Utilities 217
Exception Messages
With some L166 error messages the exact reason of the error is additionally
displayed with the EXCEPTION message. The EXCEPTION messages refer to
the cause of the errors, recognized by the operating system. These possible L166
EXCEPTION messages are listed below:
8
166/167 Assembler and Utilities 219
Application Example
This section describes a short 166/167 program, developed with C166 Compiler,
A166 Assembler and L166 Linker/Locator. With this program the principle of
modular program development and use of the L166 is explained.
The program, that should only indicate the possible techniques of program
development, calculates the sum of two input numbers (which are read with the
library function ‘getchar’) and displays the result via the C function ‘printf’. It
consists of three modules which should be translated by using the following
invocations:
C166 CSAMPLE1.C DEBUG
C166 CSAMPLE2.C DEBUG
A166 CSAMPLE3.A66 DEBUG
The parameter DEBUG allows the complete symbol information from parts of the
program, to be included in the object file. Additionally the files are processed by
the L166 Linker/Locator. The invocation for the Linker/Locator is:
L166 @CSAMPLE.L66
The L166 input line is read from the file CSAMPLE.L66. The content of this file
is:
CSAMPLE1.OBJ, CSAMPLE2.OBJ, CSAMPLE3.OBJ
CLASSES (NCODE (1000H - 3FFFH))
RESERVE (8H - 0BH, 088H - 08BH, 0B8H - 0BBH)
IXREF
The executable 166 program is stored with in the file CSAMPLE1. This file may
be immediately loaded and processed by dScope and/or after transfer with OH166
burned into an EPROM.
The directive CLASSES directs the program code to the address range
1000H-3FFFH. The RESERVE directive reserves the interrupt vectors required
by Monitor-166.
The directive IXREF generates a symbol cross reference report of all public and
external symbols in the listing file of the Linker/Locator (SAMPLE1.M66).
The following displays the listing files of the C166 Compiler and of the L166
8
Linker/Locator.
220 Chapter 8. L166 Linker/Locator
This sample program can also be generated by using the BATCH file
CSAMPLE.BAT.
CSAMPLE1.C
C166 COMPILER V1.00, CSAMPLE1 06/05/92 14:05:15 PAGE 1
CSAMPLE2.C
C166 COMPILER V1.00, CSAMPLE2 06/05/92 14:05:17 PAGE 1
CSAMPLE3.A66
A166 MACRO ASSEMBLER CSAMPLE3 06/05/92 14:05:20 PAGE 1
8 S0RIC. . . .
S0TIC. . . .
serinit. . .
.
.
.
.
.
.
.
.
.
WORD
WORD
NEAR
FF6EH
FF6CH
0000H
A
A
R
SFR
SFR
PUB SEC=?PR?SERINIT
START STOP LENGHT TYPE ALIGN TGR GRP COMB CLASS SECTION NAME
==============================================================================
=
00000H 00003H 00004H --- --- --- --- --- * INTVECTOR TABLE *
00004H 00005H 00002H CONST WORD --- --- GLOB --- ?C_INITSEC
00008H 0000AH 00003H --- --- --- --- --- * RESERVED MEMORY *
0000BH 0005CH 00052H DATA BYTE --- 2 PUBL NCONST ?NC?CSAMPLE1
0005DH 0007AH 0001EH DATA BYTE --- 2 PUBL NCONST ?NC?CSAMPLE2
0007CH 00086H 0000BH DATA WORD --- 2 PRIV NCONST ?NC?PRINTF
00088H 0008AH 00003H --- --- --- --- --- * RESERVED MEMORY *
0008CH 00091H 00006H CONST WORD --- --- PRIV --- ?C_CLRMEMSEC
000B8H 000BAH 00003H --- --- --- --- --- * RESERVED MEMORY *
000BCH 00185H 000CAH CODE WORD
01000H 0104DH 0004EH CODE WORD
0104EH 01107H 000BAH CODE WORD
01108H 014D1H 003CAH CODE WORD
--- --- PRIV ICODE ?C_STARTUP_CODE
--- 1 PUBL NCODE ?PR?CSAMPLE1
--- 1 PUBL NCODE ?PR?CSAMPLE2
--- 1 PRIV NCODE ?PR?printf
8
014D2H 01501H 00030H CODE WORD --- 1 PUBL NCODE ?PR?GETCHAR
01502H 01533H 00032H CODE WORD --- 1 PRIV NCODE ?PR?putchar
01534H 01543H 00010H CODE WORD --- 1 PUBL NCODE ?PR?GETKEY
01544H 0155BH 00018H CODE WORD --- --- PRIV NCODE ?PR?SERINIT
04000H 04FFFH 01000H DATA WORD --- 3 PRIV NDATA ?C_USERSTACK
224 Chapter 8. L166 Linker/Locator
8 R15.00
---
01000H
01002H
SYMBOL
BLOCKEND
LINE
LINE
BIT
LVL=1
---
---
---
---
---
---
---
---
---
---
operation
#10
#14
01006H LINE --- --- --- #16
0100EH LINE --- --- --- #18
0100EH LINE --- --- --- #19
01014H LINE --- --- --- #20
0101AH LINE --- --- --- #21
166/167 Assembler and Utilities 225
: : : : : :
8
166/167 Assembler and Utilities 227
8
166/167 Assembler and Utilities 229
The LIB166 library manager lets you create library files, add object modules,
remove object modules, and list library file contents. The LIB166 library manager
can be controlled interactively or from the command line.
Using LIB166
To invoke the LIB166 library manager from the DOS prompt, type LIB166 along
with an optional library manager command. The command line must be entered
according to the following format:
LIB166 command
where command may be a single library manager command. To enter more than
one command, append the ampersand character (‘&’) to the end of the LIB166
library manager command line.
Interactive Mode
If no command is entered on the command line, or if the ampersand character is
included at the end of the line, the LIB166 library manager enters interactive
mode. The LIB166 library manager displays an asterisk character (‘*’) to signal
that it is in interactive mode and is waiting for input.
Any of the LIB166 library manager commands may be entered on the command
line or after the * prompt when in interactive mode.
Command Summary
A The following table lists the commands that are available for the LIB166 library
manager. All of these commands are described in detail in the sections that follow.
Creating a Library
The CREATE command directs the LIB166 library manager to create a new,
empty library file. The CREATE command may be entered on the command line,
A
or at the * prompt in interactive mode, and must have the following format:
CREATE libfile
where libfile is the name of the library file to create. The name of the library file
must include the file extension. Usually, .LIB is the extension that is used for
library files.
Example:
LIB166 CREATE MYFILE.LIB
* CREATE FASTMATH.LIB
232 Appendix A. LIB166 Library Manager
where
filename is the name of an object file or library file. You may specify
several files for each ADD command. Each file must be
separated by a comma.
modulename is the name of a module in a library file. If you do not want to
add the entire contents of a library, you may select the modules
that you want to add. Module names are specified immediately
following the filename, must be enclosed in parentheses, and
must be separated by commas.
libfile is the name of an existing library file. The specified object
modules are added to this library.
The ADD command may be entered on the command line or after the * prompt in
interactive mode as shown in the following example.
LIB166 ADD MOD1.OBJ, UTIL.LIB(FPMUL, FPDIV) TO NEW.LIB
where
libfile is the name of an existing library file. The specified object
modules are removed from this library.
modulename is the name of a module in the library file that you want to
remove. Module names are entered in parentheses and are
separated by commas.
The DELETE command may be entered on the command line or after the *
prompt in interactive mode as shown in the following example.
LIB166 DELETE NEW.LIB (MODUL1)
where
libfile is the library file from which a module list is generated.
listfile is the file where listing information is written. If no listfile is
specified, the listing information is displayed on the screen.
PUBLICS specifies that public symbols are included in the listing.
Normally, only module names are listed.
Example:
*LIST UNI.LIB TO UNI.LST <cr>
Help Information
The HELP command directs the LIB166 library manager to display the available
library manager commands. This command may be entered on the command line
A
or at the * prompt in interactive mode. The LIB166 library manager responds
with the following text:
ADD {file[(module[,...])]} [,...] TO library_file
CREATE library_file
DELETE library_file(module[,...])
EXIT
HELP
LIST library_file [TO file] [PUBLICS]
236 Appendix A. LIB166 Library Manager
Fatal Errors
Fatal errors cause immediate termination of the LIB166 library manager. These
errors normally occur as the result of a corrupt library or object file, or as a result
of a specification problem involving library or object files.
Errors
The following errors cause immediate termination of the LIB166 library manager.
These errors usually involve invalid command line syntax or I/O errors. A
Error Error Message and Description
201 INVALID COMMAND LINE SYNTAX
A syntax error was detected in the command. The command line is displayed up to
and including the point of error.
202 INVALID COMMAND LINE, TOKEN TOO LONG
The command line contains a token that is too long for the LIB166 library manager to
process.
203 EXPECTED ITEM MISSING
The command line is incomplete. An expected item is missing.
205 FILE ALREADY EXISTS
FILE: filename
The filename that was specified already exists. This error is usually generated when
attempting to create a library file that already exists. Erase the file or use a different
filename.
208 MISSING OR INVALID FILENAME
A filename is missing or invalid.
209 UNRECOGNIZED COMMAND
A command is unrecognized by the LIB166 library manager. Make sure you correctly
specified the command name.
210 I/O ERROR ON INPUT FILE:
system error message
FILE: filename
An I/O error was detected when accessing one of the input files. A detailed error
description of the EXCEPTION messages is described in chapter 1.
211 I/O ERROR ON LIBRARY FILE:
system error message
FILE: filename
An I/O error was detected when accessing a library file. A detailed error description of
the EXCEPTION messages is described in chapter 1.
212 I/O ERROR ON LISTING FILE:
system error message
FILE: filename
An I/O error was detected when accessing a listing file. A detailed error description of
the EXCEPTION messages is described in chapter 1.
213 I/O ERROR ON TEMPORARY FILE:
system error message
FILE: filename
An I/O error was detected when a temporary file was being accessed. A detailed error
description of the EXCEPTION messages is described in chapter 1.
220 INVALID INPUT MODULE
FILE: filename
The specified input module is invalid. This error could be the result of an assembler
error or could indicate that the input object file is corrupt.
238 Appendix A. LIB166 Library Manager
A 223
FILE: filename
The filename specified was included on the command line more than once.
CANNOT FIND MODULE
MODULE: filename (modulename)
The modulename specified on the command line was not located in the object or
library file.
224 ATTEMPT TO ADD DUPLICATE MODULE
MODULE: filename (modulename)
The specified modulename already exists in the library file and cannot be added.
225 ATTEMPT TO ADD DUPLICATE PUBLIC SYMBOL
MODULE: filename (modulename)
PUBLIC: symbolname
The specified public symbolname in modulename already exists in the library file and
cannot be added.
166/167 Assembler and Utilities 239
where:
abs_file is the name of the absolute object file that the L166 linker/locator
generated.
H167 specifies Intel HEX-386 format for the Intel HEX file. The
default format of OH166 is Intel HEX-86 format.
RANGE specifies the address range of data in the abs_file to convert
and store in the HEX file. The default range is 0-0xFFFFFF.
start is the starting address of the address range. This address must be
entered in C hexadecimal notation, for example: 0x10000.
end is the end address of the address range. This address must be
entered in C hexadecimal notation, for example: 0x1FFFF.
OFFSET specifies an offset which is added to the address stored in the
abs_file.
FLASH The HEX file is sorted in ascending order. Unused bytes in the
RANGE are filled with the fill_byte specified with the
FLASH directive. The sorted HEX file can be downloaded to
166/167 flash devices.
240 Appendix B. OH166 Object-Hex Converter
:llaaaattdd...cc
Each group of letters corresponds to a different field, and each letter represents a
single hexadecimal digit. Each field is composed of at least two hexadecimal
digits—which make up a byte—as described below:
00 data record
01 end-of-file record
02 8086 segment address record
04 extended linear address record.
dd is a data field that represents one byte of data. A record may
have multiple data bytes. The number of data bytes in the record
must match the number specified by the ll field.
cc is the checksum field that represents the checksum of the record.
The checksum is calculated by summing the values of all
242 Appendix B. OH166 Object-Hex Converter
hexadecimal digit pairs in the record modulo 256 and taking the
two’s complement.
Data Record
The Intel HEX file is made up of any number of data records that are terminated
with a carriage return and a linefeed. Data records appear as follows:
B :10246200464C5549442050524F46494C4500464C33
where:
10 is the number of data bytes in the record.
2462 is the address where the data are to be located in memory.
00 is the record type 00 (a data record).
464C...464C is the data.
33 is the checksum of the record.
where:
00 is the number of data bytes in the record.
0000 is the address where the data are to be located in memory. The
address in end-of-file records is meaningless and is ignored. An
address of 0000h is typical.
01 is the record type 01 (an end-of-file record).
FF is the checksum of the record and is calculated as
01h + NOT(00h + 00h + 00h + 01h).
166/167 Assembler and Utilities 243
where:
02 is the number of data bytes in the record.
0000 is always 0 in a extended 8086 segment record.
04 is the record type 04 (an extended linear address record).
00FF is the high word of the address offset (0x00FF0000).
FB is the checksum of the record.
244 Appendix B. OH166 Object-Hex Converter
B :10C22000F04EF05FF06CF07DCA0050C2F086F097DF
:10C23000F04AF054BCF5204830592D02E018BB03F9
:020000020000FC
:04000000FA00000200
:00000001FF
166/167 Assembler and Utilities 245
Introduction
Many microcontroller applications require simultaneous execution of several jobs
(tasks). RTX166 Tiny offers a flexible method to allocate the available processor
time to several tasks and can be implemented on all 166/167 derivatives.
A standard C program starts its execution with the function main. This main
function is usually an endless loop in an 166/167 application.
246 Appendix C. RTX166 TINY
main () {
while (1) {
counter++;
}
}
job0 () _task_ 0 {
job1 () _task_ 1 {
while (1) { /* Endless loop */
counter1++; /* Increment counter 1 */
}
}
RTX166 starts the program with task 0 (assigned to job0). The function
os_create_task marks task 1 (assigned to job1) as ready for execution. These two
functions are simple count loops. After the timeout period has been completed,
RTX166 interrupts job0 and begins execution of job1. This function even reaches
the timeout and the system continues with job0.
166/167 Assembler and Utilities 247
The os_wait function provides a more efficient way to allocate the available
processor time to several tasks. os_wait interrupts the execution of the current
task and waits for the specified event. During the time in which a task waits for
an event, other tasks can be executed.
int counter0;
int counter1;
job0 () _task_ 0 {
os_create_task (1);
while (1) {
counter0++; /* Increment counter 0 */
os_wait (K_TMO, 3, 0); /* Wait 3 timer ticks */
}
}
job1 () _task_ 1 {
while (1) {
counter1++; /* Increment counter 1 */
os_wait (K_TMO, 5, 0); /* Wait 5 timer ticks */
}
}
This program is similar to the previous example with the exception that job0 is
interrupted with os_wait after counter0 has been incremented. RTX166 waits
three timer ticks until job0 is ready for execution again. During this time, job1 is
executed. This function also calls os_wait with a timeout of 5 ticks. The result:
counter0 is incremented every three ticks and counter1 is incremented every five
timer ticks.
248 Appendix C. RTX166 TINY
int counter0;
int counter1;
job0 () _task_ 0 {
C os_create_task (1);
while (1) {
if (++counter0 == 0) { /* On counter 0 overflow */
os_send_signal (1); /* Send signal to task 1 */
}
}
}
job1 () _task_ 1 {
while (1) {
os_wait (K_SIG, 0, 0); /* Wait for signal; no timeout */
counter1++; /* Increment counter 1 */
}
}
In this example, task 1 waits for a signal from task 0 and therefore processes the
overflow from counter0.
The full version of RTX166 provides preemptive task switching. This feature is
not included in RTX166 Tiny. It is explained here to provide a complete overview
of multitasking concepts.
In the previous example, task 1 is not immediately started after a signal has
arrived, but only after a timeout occurs for task 0. If task 1 is defined with a
higher priority than task 0, by means of preemptive task switching, task 1 is
started immediately after the signal has arrived. The priority is specified in the
task definition (priority 0 is the default value).
166/167 Assembler and Utilities 249
Generation Example:
C166 EXAMPLE1.C
L166 EXAMPLE1.OBJ RTX166TINY
C
250 Appendix C. RTX166 TINY
Function Meaning
isr_send_signal Send a signal to a task (call from interrupt).
os_clear_signal Delete a sent signal.
os_create_task Move a task to execution queue.
os_delay_task Wait for timeout.
os_delete_task Remove a task from execution queue.
os_running_task_id Return task ID of currently running task.
os_send_signal Send a signal to a task (call from tasks).
os_wait Wait for event.
os_wait_signal Wait for signal.
166/167 Assembler and Utilities 251
Max. 256 tasks with task priority 0-127 can be defined and active.
Preemptive and round-robin task switching (timeout can be configured).
Wait function allows (all events can be combined):
Wait for timeout.
Wait for interrupt.
Wait for signal from task or interrupt. C
Wait for message from task or interrupt.
Wait for token (semaphore).
Memory/hardware requirement:
CODE memory: 6-35 KBytes (scaleable).
DATA memory: 2-3 KBytes.
Task switching time: < 400 states.
Semaphores: Max. 256 semaphores.
Mailbox system: 256 mailboxes (up to 16KB message size).
CAN Interface: comes with CAN driver for C167C.
Function Meaning
isr_clear_signal Clear a signal to a task (called from interrupt functions).
isr_get_token Receive a token from a semaphore (called from interrupt).
isr_recv_message Receive a message from a mailbox (called from interrupt).
isr_reset_mailbox Delete a messages in a mailbox (called from interrupt).
isr_send_message Send a message to a mailbox (called from interrupt).
isr_send_signal Send a signal to a task (called from interrupt functions).
isr_send_token Send a token to a semaphore (called from interrupt).
isr_urgent_message Send an ‘urgent’ message to a mailbox (called from intrpt).
252 Appendix C. RTX166 TINY
Function Meaning
os_attach_interrupt Assign task to interrupt source.
os_change_prio Change priority of running task.
os_check_mailbox Check free space for messages in a mailbox
os_check_pool Check free space in a memory pool.
os_check_timeout Check if timeout period is over.
os_clear_signal Clear a sent signal.
os_create_mailbox Create a mailbox
os_create_pool Define a memory pool.
os_create_semaphore Create and initialize a semaphore.
os_create_task Move a task to the execution queue (tasks becomes ready).
os_delay_task Wait for a specified number of ticks (timeout).
C os_delete_mailbox
os_delete_semaphore
Delete a mailbox
Delete a semaphore.
os_delete_task Delete a task from the execution queue.
os_detach_interrupt Remove interrupt source assignment.
os_disable_isr Disable 166/167 hardware interrupts.
os_enable_isr Enable 166/167 hardware interrupts.
os_free_block Free a block from a memory pool.
os_get_block Get a block from a memory pool.
os_pass_task Suspend task (perform a task switch).
os_reset_mailbox Delete all messages in a mailbox.
os_running_task_id Return task ID of current running task.
os_running_task_prio Return task priority of current running task.
os_send_message Send a message to a mailbox.
os_send_signal Send a signal to a task (called from tasks).
os_send_token Send a token to a semaphore.
os_set_error_handler Define an alternative error handler function.
os_set_slice Define RTX clock frequency (ticks).
os_set_timeout Set a timeout period.
os_start_system Initialize and start RTX166.
os_urgent_message Send an ‘urgent’ message to a mailbox.
os_wait Generic RTX166 wait function.
os_wait_interrupt Wait for an interrupt.
os_wait_message Wait for a message in a mailbox.
os_wait_signal Wait for a signal.
os_wait_token Wait for a token from a semaphore.
166/167 Assembler and Utilities 253
Software Requirements
The following software products are required to operate RTX166 Tiny:
File RTX166T.H must be stored in directory C166\INC; the path for the C166
C
INCLUDE files must be set.
Task Management
Each RTX166 Tiny task is in one of the following task states.
State Description
DELETED Tasks which are not started are in the DELETED state.
READY Tasks which are waiting for execution are in the READY
state. After the currently running task has finished
processing, RTX166 Tiny starts the next task in the
READY state.
RUNNING The task currently being executed is in the RUNNING
state. Only one task is in the RUNNING state at a time.
TIMEOUT Tasks which were interrupted by a round-robin timeout
are in the TIMEOUT state. This state is equivalent to
READY; however, a round-robin task switch is marked
due to internal operating procedures.
WAITING Tasks which are waiting for an event are in the WAITING
state. If the event occurs which the task is waiting for,
this task then enters the READY state.
A task may be waiting for one or more of the following types of events.
254 Appendix C. RTX166 TINY
Event Description
INTERVAL Timeout interval which is started by the os_wait function.
A wait time is also specified in this case in timer ticks. In
comparison to a timeout, the timer is not reset, however;
the event “interval” therefore functions with a constant
running timer. An interval can be used if the task is to be
executed in synchronous intervals (i.e., in the case of a
clock)).
SIGNAL Bit for task communication. A signal can be set or
cleared. The os_wait function can wait for a signal.
TIMEOUT Time interval which is started by the os_wait function.
The duration of the timeout is specified in timer ticks.
RTX166 resets a timer internally. After completion of the
timer ticks, the task is ready for execution (READY)
again.
C
Task Switching
The system section of RTX166 Tiny which assigns the processor a task is called
the scheduler. The scheduler of RTX166 Tiny functions according to the
following rules:
The RTX166 Tiny scheduler continuously checks all tasks. The first available
task in the READY or TIMEOUT state is started.
Example:
Task 1 and task 6 have the state “READY”. Task 3 is in the “RUNNING” state.
If task 3 is interrupted, task 6 is executed next, since RTX166 Tiny begins the
search for executable tasks beginning with task 4.
166/167 Assembler and Utilities 255
Task Declaration
C166 contains an extended function declaration for defining tasks. A task for
RTX166 Tiny is declared as follows:
void function (void) _task_ <task_id>
Example:
void example_1 (void) _task_ 8
Interrupt Handling
RTX166 Tiny can operate parallel with interrupt functions. In the case of
RTX166, the interrupts of the 80C166 derivative can also be managed by the real-
time operating system. This is not possible with RTX166 Tiny.
Similar to other 166/167 applications, the interrupt source must be enabled in the
control register in order to trigger an interrupt. RTX166 Tiny does not contain any
management for interrupts; for this reason, the interrupt enable is sufficient to
NOTE
RTX166 Tiny already uses Timer 0 and enables the Timer 0 interrupt with
ILVL = 1 and GLVL = 0. Therefore, no other interrupt source should use this
interrupt and group level. Disabling the Timer 0 interrupt or the all interrupts
(via IEN) is not permitted in RTX166 Tiny.
Functional description
Declaration in C166 (as contained in RTX166T.H)
Parameter explanation
Return value explanation C
Call example
Cross reference to other calls
Name Assignment
The prefix of the system function name describes its application:
System functions whose name starts with “os_” may be used exclusively by
tasks.
System functions whose name starts with “isr_” may be used exclusively by
C166 interrupt procedures.
Return Values
Most system functions return a status as a function result. The status indicates
whether the function is executed successfully.
The description of the system functions explains the status information and its
meaning. Zero is returned in most cases if the function executed successfully.
Include Files
The declaration of the RTX166 Tiny system functions and all constant
declarations are contained in the h-file RTX166T.H. This h-file must be specified
258 Appendix C. RTX166 TINY
C
166/167 Assembler and Utilities 259
Function Overview
Task Management:
os_create_task (task_id)
os_delete_task (task_id)
os_running_task_id ()
Signal Functions:
os_send_signal (task_id)
os_clear_signal (task_id)
isr_send_signal (task_id)
C
Wait Functions:
os_delay_task (timeout)
os_wait (event_selector, timeout, 0)
os_wait_signal ()
260 Appendix C. RTX166 TINY
os_clear_signal
The os_clear_signal function clears the signal flag of a specified task. This
function can be used to ensure defined start conditions of a task.
Parameter: task_id is the number of the task for which the signal flag is
to be cleared.
C See also:
-1: The specified task does not exist.
Example:
void xyz_task (void) _task_ 8 {
/* task code */
}
166/167 Assembler and Utilities 261
os_create_task
The os_create_task function starts a function defined with the C166 attribute
_task_ as an RTX166 Tiny task function. The task is marked as ready for
execution (READY). The task is executed according to the rules described for
task switching.
Example:
void count_task (void) _task_ 2 {
/* task code */
}
a
if (os_create_task (2)) {
/* error handling */
}
/* task code */
}
262 Appendix C. RTX166 TINY
os_delay_task
The os_delay_task function is a shorthand of the os_wait function where the
event specification is fixed to timeout (K_TMO). During the time in which a task
is waiting for the timeout, other tasks can be executed. If the time period is over,
the calling task gets the state ready for execution.
Example:
void first_task (void) _task_ 0 {
/* task code */
/* task code */
}
166/167 Assembler and Utilities 263
os_delete_task
The os_delete_task function stops a task and sets the task to state “DELETED”.
The task is deleted from the list of the executable tasks.
NOTE
If a task deletes itself, a task switching subsequently is
executed.
Example:
void first_task (void) _task_ 0 {
/* task code */
os_running_task_id
Returns the Task_ID of the currently running task and the number which was used
in the task declaration. Using this system function, a C166 function can, for
example, determine the task from which it was called.
Parameter: ---
Return value: 0-31; the task_ID of the task currently being executed by the
processor is returned.
Example:
void xyz_task (void) _task_ 3 {
unsigned char task_id;
/* task code */
}
166/167 Assembler and Utilities 265
os_send_signal / isr_send_signal
Sends a signal to another task. If this task is already waiting for a signal, this
causes it to be ready for execution again. Otherwise, the signal is stored in the
signal flag of the addressed task. If the signal flag of a task is already set when
the os_wait function is called, the task is immediately continued when
event_selector = K_SIG is given.
Return value:
sent.
NOTE
The function os_send_signal may only be called from task
functions. The function isr_send_signal may only be called
from interrupt procedures.
Examples:
void xyz_task (void) _task_ 8 {
/* task code */
}
266 Appendix C. RTX166 TINY
os_wait
The os_wait function can be used to wait for one or more of the following events:
an interval, a timeout, or a signal from another task or interrupt. During the time
in which a task is waiting for an event, other tasks can be executed. If one of the
specified events occurs, the task that invoked the os_wait function gets the state
ready for execution.
Example:
void count_task (void) _task_ 2 {
case SIG_EVENT:
/* If a signal occurs, this part of the program is
executed. */
break;
}
default:
/* error handling */
C
}
}
268 Appendix C. RTX166 TINY
os_wait_signal
The os_wait_signal function is a shorthand of the os_wait function where the
event specification is fixed to a signal (K_SIG). During the time where a task is
waiting for a signal, other tasks can be executed. If the signal is sent by another
task or an interrupt routine with os_send_signal or isr_send_signal, the calling
task gets the state ready for execution.
Parameter: none
C Return value:
See also:
SIG_EVENT: A signal was received.
Example:
void task_xyz (void) _task_ 5 {
/* task code */
/* task code */
}
166/167 Assembler and Utilities 269
Configuration
The configuration file CONF_TNY.A66 can be used to adapt RTX166 Tiny to
application-specific requirements. If you want to use a different CPU timer for
RTX166 you can change the timer in the CPUTIMER.INC file and recreate the
RTX166 Tiny Libraries using the GENRTX batch file. All the RTX166 Tiny
files can be found in the directory RTX_TINY.
INT_CLOCK defines the interval for the system clock. The system clock of
RTX166 Tiny generates an interrupt in this interval. The
defined number specifies the value “timer ticks” in 166 CPU
cycles. Timer ticks = 2500 is the default value. Values
250-65535 are allowed for INT_CLOCK.
TIMESHARING defines the timeout for the round-robin task switching. The
value indicates the number of timer ticks which a task is
allocated by the CPU. After completion of the timer ticks, a
timeout occurs and subsequently a round-robin switching. If
the value 0 is defined for TIMESHARING, the round-robin
task switching is disabled. Default value is 5. Values
1-65535 are allowed for TIMESHARING. Zero disables the
round-robin task switching.
CPUTIMER.INC
The file CPUTIMER.INC contains a SET TIMER_NUMBER statement which
defines the CPU timer used by RTX166 Tiny. You can select the CPU timer 0-6
in this file. Note that some 166/167 derivatives do not have the Timer 0 which is
270 Appendix C. RTX166 TINY
use by default from RTX166 Tiny. Refer to the 166/167 hardware manual for the
description of the hardware timers.
If you have modified the TIMER_NUMBER value you must generate a new
version of the RTX166 Tiny libraries using the GENRTX.BAT file provided in
the RTX_TINY directory.
Stack Management
RTX166 Tiny reserves for each task an own system and user stack area. Due to
the design of RTX166 Tiny the complete stack (user and system) can be located to
C the on-chip memory of the 166/167. To allocate the maximum available memory
as stack area the stack of other (not running) tasks is moved in such a way that the
entire free memory can be used as stack area by the current running task. The
following figures illustrate the stack assignment of the individual tasks.
Stack Area
for Task 2
Stack Area
for Task 1
The figure illustrates that RTX166 Tiny reserves always the entire free memory as
a stack area for the currently running task. The memory used for the stack begins
with USRSTKBOT (for user stack) or SYSSTKBOT (for system stack). The end
of the memory area is market as USRSTKTOP (for user stack) or as
SYSSTKTOP (for system stack).
166/167 Assembler and Utilities 271
System Debugging
A RTX166 Tiny application can be tested using the dScope source-level debugger.
A debug function is available to display the system state of RTX166 Tiny. The
use of this debug function is subsequently explained.
The debug function is defined in dScope with and include file. The RTX166 Tiny
application must be loaded prior to defining this debug function.
Example:
>DS166
*LOAD TRAFFIC /* The RTX166 Tiny application program */
*INCLUDE DBG_TINY.INC /* The include file with the Debug Function */
Click Toolbox button <Task State>
272 Appendix C. RTX166 TINY
TaskID Indicates the number which was used in the task definition.
Wait for Event Indicates which events the task is currently waiting for.
Timer the number of timer ticks which are to succeed until a timeout
occurs.
USRSP start address (stack top) of the local task stack (user stack).
SYSSP Indicates the start address (stack top) of the local task stack
(system stack).
166/167 Assembler and Utilities 273
Application Examples
RTX_EX1.C
1
2
/*********************************************************************/
/* */
C
3 /* RTX_EX1.C: The first RTX166 Program */
4 /* */
5 /*********************************************************************/
6
7 #pragma CODE DEBUG
8
9 #include <rtx166t.h> /* RTX166 tiny functions & defines */
10
11 int counter0; /* counter for task 0 */
12 int counter1; /* counter for task 1 */
13 int counter2; /* counter for task 2 */
14
15 /*********************************************************************/
16 /* Task 0 'job0': RTX166 tiny starts execution with task 0 */
17 /*********************************************************************/
18 job0 () _task_ 0 {
19 1 os_create_task (1); /* start task 1 */
20 1 os_create_task (2); /* start task 2 */
21 1
22 1 while (1) { /* endless loop */
23 2 counter0++; /* increment counter 0 */
24 2 }
25 1 }
26
27 /************************************************************************/
28 /* Task 1 'job1': RTX166 tiny starts this task with os_create_task (1) */
29 /************************************************************************/
30 job1 () _task_ 1 {
31 1 while (1) { /* endless loop */
32 2 counter1++; /* increment counter 1 */
33 2 }
34 1 }
35
36 /*************************************************************************/
37 /* Task 2 'job2': RTX166 tiny starts this task with os_create_task (2) */
38 /*************************************************************************/
39 job2 () _task_ 2 {
40 1 while (1) { /* endless loop */
41 2 counter2++; /* increment counter 2 */
42 2 }
43 1 }
274 Appendix C. RTX166 TINY
Running RTX_EX1
You can generate the application also under µVision with the RTX_EX1.PRJ
project file. Within µVision you can test the application using dScope. Select
from the Run menu dScope Debugger…
We have included a dScope init file (DSCOPE.INI) which loads the application
program and a test function for RTX166 tiny.
The result of the program is simple: counter0, counter1 and counter2 are
incremented quasi-parallel. In the EXE window each task switch is reported.
RTX_EX2.C
1 /*********************************************************************/
2 /* */
3 /* RTX_EX2.C: A RTX166 Application */
4 /* */
5 /*********************************************************************/
6
7
8
9
#pragma CODE DEBUG
Running RTX_EX2
You can generate the application also under µVision with the RTX_EX2.PRJ
project file. Within µVision you can test the application using dScope. Select
from the Run menu dScope Debugger…
We have included a dScope init file (DSCOPE.INI) which loads the application
program and a test function for RTX166 tiny.
To control the clock time and the time interval we have implemented a command
processor which operates via the serial interface. The following commands are
supported:
Start Set the start time in 24-hour format. The traffic light operates
when the clock time is between start time and end time.
Example: S 7:15:00 <cr>
The whole application is coded in three modules which are described below:
GETLINE.C This module is the command line editor of the traffic light
controller.
C TRAFFIC.C This module contains the traffic light controller and is divided
into the following tasks:
Translation
CD \C166\EXAMPLES\TRAFFIC
We have also included the project file TRAFFIC.PRJ for µVision with translates
and links the whole application. Within µVision you can test the application using
dScope. Select from the Run menu dScope Debugger…
We have included a dScope init file (DSCOPE.INI) which loads the application
C
program and a test function for RTX166 tiny.
TRAFFIC.C
stmt level source
1 /*********************************************************************/
2 /* */
3 /* TRAFFIC.C: Traffic Light Controller using the C166 COMPILER */
4 /* */
5 /*********************************************************************/
6
7 #pragma CODE DEBUG
8
9 const char menu[] =
10 "\n"
11 "+**** TRAFFIC LIGHT CONTROLLER using C166 and RTX166 tiny ***+\n"
12 "| This program is a simple Traffic Light Controller. Between |\n"
13 "| start time and end time the system controls a traffic light |\n"
14 "| with pedestrian self-service. Outside of this time range |\n"
15 "| the yellow caution lamp is blinking. |\n"
16 "+ command -+ syntax -----+ function --------------------------+\n"
17 "| Display | D | display times |\n"
18 "| Time | T hh:mm:ss | set clock time |\n"
19 "| Start | S hh:mm:ss | set start time |\n"
20 "| End | E hh:mm:ss | set end time |\n"
21 "+----------+-------------+------------------------------------+\n";
22
23
24 #include <reg166.h> /* special function registers 80C166 */
25 #include <rtx166t.h> /* RTX166 tiny functions & defines */
26 #include <stdio.h> /* standard I/O .h-file */
27 #include <ctype.h> /* character functions */
28 #include <string.h> /* string and memory functions */
29
30 extern getline (char *, char); /* external function: input line */
31 extern serial_init (); /* external function: init serial UART */
32
280 Appendix C. RTX166 TINY
C
53 sbit green = P2^11; /* I/O Pin: green lamp output */
54 sbit stop = P2^2; /* I/O Pin: stop lamp output */
55 sbit walk = P2^8; /* I/O Pin: walk lamp output */
56 sbit key = P3^0; /* I/O Pin: self-service key input */
57
58 char inline[16]; /* storage for command input line */
59
60
61 /*********************************************************************/
62 /* Task 0 'init': Initialize */
63 /*********************************************************************/
64 init () _task_ INIT { /* program execution starts here */
65 1 DP2 = 0xFFFF; /* data direction register */
66 1 serial_init (); /* initialize the serial interface */
67 1 os_create_task (CLOCK); /* start clock task */
68 1 os_create_task (COMMAND); /* start command task */
69 1 os_create_task (LIGHTS); /* start lights task */
70 1 os_create_task (KEYREAD); /* start keyread task */
71 1 os_delete_task (INIT); /* stop init task (no longer needed) */
72 1 }
73
74
75 bit display_time = 0; /* flag: signal cmd state display_time */
76
77 /*********************************************************************/
78 /* Task 2 'clock' */
79 /*********************************************************************/
80 clock () _task_ CLOCK {
81 1 while (1) { /* clock is an endless loop */
82 2 if (++ctime.sec == 60) { /* calculate the second */
83 3 ctime.sec = 0;
84 3 if (++ctime.min == 60) { /* calculate the minute */
85 4 ctime.min = 0;
86 4 if (++ctime.hour == 24) { /* calculate the hour */
87 5 ctime.hour = 0;
88 5 }
89 4 }
90 3 }
91 2 if (display_time) { /* if command_status == display_time */
92 3 os_send_signal (COMMAND); /*signal to task command:time changed*/
93 3 }
94 2 os_wait (K_IVL, 1000, 0); /* wait interval: 1 second */
95 2 }
96 1 }
97
98
99 struct time rtime; /* temporary storage for entry time */
100
101 /*********************************************************************/
102 /* readtime: convert line input to time values & store in rtime */
166/167 Assembler and Utilities 281
103 /*********************************************************************/
104 bit readtime (char *buffer) {
105 1 unsigned char args; /* number of arguments */
106 1
107 1 rtime.sec = 0; /* preset second */
108 1 args = sscanf (buffer, "%hd:%hd:%hd", /* scan input line for */
109 1 &rtime.hour, /* hour, minute and second */
110 1 &rtime.min,
111 1 &rtime.sec);
112 1
113 1 if (rtime.hour > 23 || rtime.min > 59 || /*check for valid inputs*/
114 1 rtime.sec > 59 || args < 2 || args == EOF) {
115 2 printf ("\n*** ERROR: INVALID TIME FORMAT\n");
116 2 return (0);
117 2 }
118 1 return (1);
119 1 }
120
121
122
C
123 #define ESC 0x1B /* ESCAPE character code */
124
125 bit escape; /* flag: mark ESCAPE character entered */
126
127 /*********************************************************************/
128 /* Task 6 'get_escape': check if ESC (escape character) was entered */
129 /*********************************************************************/
130 get_escape () _task_ GET_ESC {
131 1 while (1) { /* endless loop */
132 2 if (_getkey () == ESC) escape = 1; /* set flag if ESC entered */
133 2 if (escape) { /* if escape flag send signal */
134 3 os_send_signal (COMMAND); /* to task 'command' */
135 3 }
136 2 }
137 1 }
138
139
140 /*********************************************************************/
141 /* Task 1 'command': command processor */
142 /*********************************************************************/
143 command () _task_ COMMAND {
144 1 unsigned char i;
145 1
146 1 printf (menu); /* display command menu */
147 1 while (1) { /* endless loop */
148 2 printf ("\nCommand: "); /* display prompt */
149 2 getline (&inline, sizeof (inline)); /* get command line input */
150 2
151 2 for (i = 0; inline[i] != 0; i++) { /* convert to uppercase */
152 3 inline[i] = toupper(inline[i]);
153 3 }
154 2
155 2 for (i = 0; inline[i] == ' '; i++); /* skip blanks */
156 2
157 2 switch (inline[i]) { /* proceed to command function */
158 3 case 'D': /* Display Time Command */
159 3 printf ("Start Time: %02d:%02d:%02d "
160 3 "End Time: %02d:%02d:%02d\n",
161 3 start.hour, start.min, start.sec,
162 3 end.hour, end.min, end.sec);
163 3 printf (" type ESC to abort\r");
164 3
165 3 os_create_task (GET_ESC); /* ESC check in display loop */
166 3 escape = 0; /* clear escape flag */
167 3 display_time = 1; /* set display time flag */
168 3 os_clear_signal (COMMAND); /* clear pending signals */
169 3
170 3 while (!escape) { /* while no ESC entered */
171 4 printf ("Clock Time: %02d:%02d:%02d\r", /* display time */
172 4 ctime.hour, ctime.min, ctime.sec);
282 Appendix C. RTX166 TINY
C
193 4 end.sec = rtime.sec;
194 4 }
195 3 break;
196 3
197 3 case 'S': /* Set Start Time Command */
198 3 if (readtime (&inline[i+1])) { /* read time input and */
199 4 start.hour = rtime.hour; /* store in 'start' */
200 4 start.min = rtime.min;
201 4 start.sec = rtime.sec;
202 4 }
203 3 break;
204 3
205 3 default: /* Error Handling */
206 3 printf (menu); /* display command menu */
207 3 break;
208 3 }
209 2 }
210 1 }
211
212
213 /*********************************************************************/
214 /* signalon: check if clock time is between start and end */
215 /*********************************************************************/
216 bit signalon () {
217 1 if (memcmp (&start, &end, sizeof (struct time)) < 0) {
218 2 if (memcmp (&start, &ctime, sizeof (struct time)) < 0 &&
219 2 memcmp (&ctime, &end, sizeof (struct time)) < 0) return (1);
220 2 }
221 1
222 1 else {
223 2 if (memcmp (&end, &ctime, sizeof (start)) > 0 &&
224 2 memcmp (&ctime, &start, sizeof (start)) > 0) return (1);
225 2 }
226 1 return (0); /* signal off, blinking on */
227 1 }
228
229
230 /*********************************************************************/
231 /* Task 3 'blinking':runs if current time is outside start & end time*/
232 /*********************************************************************/
233 blinking () _task_ BLINKING { /* blink yellow light */
234 1 red = 0; /* all lights off */
235 1 yellow = 0;
236 1 green = 0;
237 1 stop = 0;
238 1 walk = 0;
239 1
240 1 while (1) { /* endless loop */
241 2 yellow = 1; /* yellow light on */
242 2 os_wait (K_TMO, 300, 0); /* wait for timeout: 300 ticks */
166/167 Assembler and Utilities 283
C
263 2 os_wait (K_TMO, 500, 0); /* wait for timeout: 500 ticks */
264 2 if (!signalon ()) { /* if traffic signal time over */
265 3 os_create_task (BLINKING); /* start blinking */
266 3 os_delete_task (LIGHTS); /* stop lights */
267 3 }
268 2 yellow = 1;
269 2 os_wait (K_TMO, 500, 0); /* wait for timeout: 500 ticks */
270 2 red = 0; /* green light for cars */
271 2 yellow = 0;
272 2 green = 1;
273 2 os_clear_signal (LIGHTS);
274 2 os_wait (K_TMO, 500, 0); /* wait for timeout: 500 ticks */
275 2 os_wait (K_TMO + K_SIG, 7500, 0); /* wait for timeout & signal */
276 2 yellow = 1;
277 2 green = 0;
278 2 os_wait (K_TMO, 500, 0); /* wait for timeout: 500 ticks */
279 2 red = 1; /* red light for cars */
280 2 yellow = 0;
281 2 os_wait (K_TMO, 500, 0); /* wait for timeout: 500 ticks */
282 2 stop = 0; /* green light for walkers */
283 2 walk = 1;
284 2 os_wait (K_TMO, 2500, 0); /* wait for timeout: 2500 ticks*/
285 2 stop = 1; /* red light for walkers */
286 2 walk = 0;
287 2 }
288 1 }
289
290
291 /*********************************************************************/
292 /* Task 5 'keyread': process key stroke from pedestrian push button */
293 /*********************************************************************/
294 keyread () _task_ KEYREAD {
295 1 while (1) { /* endless loop */
296 2 if (key) { /* if key pressed */
297 3 os_send_signal (LIGHTS); /* send signal to task lights */
298 3 }
299 2 os_wait (K_TMO, 20, 0); /* wait for timeout: 20 ticks */
300 2 }
301 1 }
284 Appendix C. RTX166 TINY
SERIAL.C
stmt level source
1 /*********************************************************************/
2 /* */
3 /* SERIAL.C: Interrupt Controlled Serial Interface for RTX166 tiny */
4 /* */
5 /*********************************************************************/
6
7 #pragma CODE DEBUG
8
9 #include <reg166.h> /* special function register 80C166 */
10 #include <rtx166t.h> /* RTX166 tiny functions & defines */
11 #include <intrins.h> /* C166 intrinsic functions */
12
13 #define OLEN 8 /* size of serial transmission buffer */
14 unsigned char ostart; /* transmission buffer start index */
15 unsigned char oend; /* transmission buffer end index */
C 16
17
18
19
char
int
#define ILEN
outbuf[OLEN];
otask = -1;
8
/*
/*
/*
storage for transmission buffer
task number of output task
*/
20 unsigned char istart; /* receiving buffer start index */
21 unsigned char iend; /* receiving buffer end index */
22 char inbuf[ILEN]; /* storage for receiving buffer */
23 int itask = -1; /* task number of output task */
24
25 #define CTRL_Q 0x11 /* Control+Q character code */
26 #define CTRL_S 0x13 /* Control+S character code */
27
28 bit sendfull; /* flag: marks transmit buffer full */
29 bit sendactive; /* flag: marks transmitter active */
30 bit sendstop; /* flag: marks XOFF character */
31
32 /*********************************************************************/
33 /* putbuf: write a character to SBUF or transmission buffer */
34 /*********************************************************************/
35 void putbuf (char c) {
36 1 if (!sendfull) { /* transmit only if buffer not full */
37 2 if (!sendactive && !sendstop) { /* if transmitter not active: */
38 3 sendactive = 1; /* transfer the first character direct */
39 3 S0TBUF = c; /* to S0TBUF to start transmission */
40 3 }
41 2 else { /* otherwize: */
42 3 outbuf[oend++ & (OLEN-1)] = c; /* transfer char to transmission
buffer */
43 3 if (((oend ^ ostart) & (OLEN-1)) == 0) sendfull = 1;
44 3 } /* set flag if buffer is full */
45 2 }
46 1 }
47
48
49 /*********************************************************************/
50 /* putchar: interrupt controlled putchar function */
51 /*********************************************************************/
52 int putchar (char c) {
53 1 if (c == '\n') { /* expand new line character: */
54 2 while (sendfull) { /* wait for transmission buffer empty */
55 3 otask = os_running_task_id (); /* set output task number */
56 3 os_wait (K_SIG, 0, 0); /* RTX166 call: wait for signal */
57 3 otask = -1; /* clear output task number */
58 3 }
59 2 putbuf (0x0D); /* send CR before LF for <new line> */
60 2 }
61 1 while (sendfull) { /* wait for transmission buffer empty */
62 2 otask = os_running_task_id (); /* set output task number */
63 2 os_wait (K_SIG, 0, 0); /* RTX166 call: wait for signal */
64 2 otask = -1; /* clear output task number */
166/167 Assembler and Utilities 285
65 2 }
66 1 putbuf (c); /* send character */
67 1 return (c); /* return character: ANSI requirement */
68 1 }
69
70
71 /*********************************************************************/
72 /* _getkey: interrupt controlled _getkey */
73 /*********************************************************************/
74 char _getkey (void) {
75 1 while (iend == istart) {
76 2 itask = os_running_task_id (); /* set input task number */
77 2 os_wait (K_SIG, 0, 0); /* RTX166 call: wait for signal */
78 2 itask = -1; /* clear input task number */
79 2 }
80 1 return (inbuf[istart++ & (ILEN-1)]);
81 1 }
82
83
84 /*********************************************************************/
C
85 /* serial_receive: serial receive interrupt */
86 /*********************************************************************/
87 void serial_receive (void) interrupt SERIAL_RECEIVE0 = 0x2B using S_RBANK {
88 1 unsigned char c;
89 1
90 1 c = S0RBUF; /* read character */
91 1 switch (c) { /* process character */
92 2 case CTRL_S:
93 2 sendstop = 1; /* if Control+S stop transmission */
94 2 break;
95 2
96 2 case CTRL_Q:
97 2 if (_testclear_ (sendstop)) {/*if Control+Q start transmission */
98 3 S0TIR = 1; /* by setting the interrupt request bit */
99 3 }
100 2 break;
101 2
102 2 default: /* read all other characters into inbuf */
103 2 if (istart + ILEN != iend) {
104 3 inbuf[iend++ & (ILEN-1)] = c;
105 3 }
106 2 /* if task waiting: signal ready */
107 2 if (itask != -1) isr_send_signal (itask);
108 2 break;
109 2 }
110 1 }
111
112
113 /*********************************************************************/
114 /* serial_transmit: serial transmitter interrupt */
115 /*********************************************************************/
116 void serial_transmit (void) interrupt STRANS0 = 0x2A using S_RBANK {
117 1 if (ostart != oend) { /* if characters in buffer and */
118 2 if (!sendstop) { /* if not Control+S received */
119 3 S0TBUF = outbuf[ostart++ & (OLEN-1)]; /* transmit character */
120 3 sendfull = 0; /* clear 'sendfull' flag */
121 3 /* if task waiting: signal ready */
122 3 if (otask != -1) isr_send_signal (otask);
123 3 }
124 2 }
125 1 else sendactive = 0; /* if all transmitted clear 'sendactive' */
126 1 }
127
128 /*********************************************************************/
129 /* serial_init: initialize serial interface */
130 /*********************************************************************/
131 void serial_init (void) {
132 1 P3 |= 0x0400; /* set PORT 3.10 output latch (TXD) */
133 1 DP3 |= 0x0400; /* set PORT 3.10 direction control (TXD output) */
134 1 DP3 &= 0xF7FF; /* reset PORT 3.11 direction control (RXD input) */
286 Appendix C. RTX166 TINY
GETLINE.C
stmt level source
1 /*********************************************************************/
2 /* */
3 /* GETLINE.C: Line Edited Character Input */
4 /* */
5 /*********************************************************************/
6
7 #include <stdio.h>
C 8
9
10
11
#define
#define
#define
CNTLQ
CNTLS
DEL
0x11
0x13
0x7F
12 #define BACKSPACE 0x08
13 #define CR 0x0D
14 #define LF 0x0A
15
16 /***************/
17 /* Line Editor */
18 /***************/
19 void getline (char *line, unsigned char n) {
20 1 unsigned char cnt = 0;
21 1 char c;
22 1
23 1 do {
24 2 if ((c = _getkey ()) == CR) c = LF; /* read character */
25 2 if (c == BACKSPACE || c == DEL) { /* process backspace */
26 3 if (cnt != 0) {
27 4 cnt--; /* decrement count */
28 4 line--; /* and line pointer */
29 4 putchar (0x08); /* echo backspace */
30 4 putchar (' ');
31 4 putchar (0x08);
32 4 }
33 3 }
34 2 else if (c != CNTLQ && c != CNTLS) { /* ignore Control S/Q */
35 3 putchar (*line = c); /* echo and store character */
36 3 line++; /* increment line pointer */
37 3 cnt++; /* and count */
38 3 }
39 2 } while (cnt < n - 1 && c != LF); /* check limit and line feed */
40 1 *line = 0; /* mark end of string */
41 1 }
166/167 Assembler and Utilities 287
C
166/167 Assembler and Utilities 289
Appendix D. Monitor-166
Monitor-166 operates on a 166/167 microcomputer board and performs the
communication with the PC system via the serial interface. The Monitor-166 can
be operated with dScope using the MON166.DLL. For the DOS environment you
can use the program MON166.EXE which supports the following commands:
Serial interface.
Software trap used for breakpoints (usually NMI trap).
Additional 10 words stack space in the user program to be tested.
256 bytes external data memory (ram).
290 Appendix D. Monitor-166
NOTE
Before you operate Monitor-166 with the dScope MON166.DLL you should
check if the MON166.EXE program works with your target board. MON166 is
easy to operate and you can check if your target board works with Monitor-166.
where:
MON166 is the program name.
parameter is one or more of the following:
COM1: use serial interface COM1: (default). Abbreviation: 1.
COM2: use serial interface COM2:. Abbreviation: 2.
COM3: use serial interface COM3:. Abbreviation: 3.
COM4: use serial interface COM4:. Abbreviation: 4.
INT14 the serial interface is called through the BIOS software interrupt
14H. No hardware interrupt is performed. The abbreviation of
INT14 is I.
All MON166 invocation parameters can also be specified in the DOS environment
variable MON166=, which can be defined with the DOS SET command. If no
parameters are stated in the invocation line, MON166 automatically operates with
the parameters of this system variable. MON166 outputs the following message if
the parameters of the system variable “MON166=” are used:
ENVIRONMENT STRING: MON166=<parameters>
Examples:
MON166
MON166 COM2: INT14
MON166 2
MON166 BAUDRATE (1200)
SET MON166=COM2: BAUDRATE (4800)
MON166
MON166 checks at start-up time if the Monitor-166 is active on the target board.
If this is the case, MON166 switches to the Monitor Mode and the commands
described under “MON166.EXE Commands” on page 295 can be entered.
Otherwise, it is assumed that a user program is already running on the board. In
this case, the Terminal Mode is started which allows data input or output via the
serial interface.
292 Appendix D. Monitor-166
25-pin Connector
Signal Name Pin Description
RxD 3 receive data
TxD 2 transmit data
Gnd 7 signal ground
9-pin Connector
Signal Name Pin Description
RxD 2 receive data
TxD 3 transmit data
Gnd 5 signal ground
In addition to the above pins, connect pin 7 to pin 8 and pin 1 to pin 4 and pin 6.
166/167 Assembler and Utilities 295
MON166.EXE Commands
MON166 requires parameters always in hexadecimal form (allowed characters
0-9, A-F). If more than one parameter is required by a command the parameters
can be separated by blank (‘ ’) or comma (‘,’).
Example:
#FILL 2000, 4000, 0 <cr>
or
In the command description and in the help menu of the Monitor-166 the following
terms are used:
Term Meaning
address The memory address value can be between 0 and 3FFFFH
bp
breakadd
number of a break point. The bp can be between 0 and 0FH.
temporary break point (address) in the code memory. The temporary break point is
D
only valid for the current active Go command.
count specifies the number of instructions executed by a Trace or Procedure-Step
command. The count can be between 0 and FFFF.
range Two address values which are interpreted as address range. The range includes
the first and the last specified address. The two numbers are separated with blank
(' ') or comma (','). Example: 1F,29 or 1F 29 specifies the range from 1FH up to
and including 29H.
value The content of a memory location. The values allowed depend on the specified
data type.
Byte:0 . . 0FF
Word:0 . . 0FFFF
Double-Word:0-0FFFFFFFF:
After the entry of the key F1 or ALT+1 MON166 response with the question
EXIT MON166 (y or [n])
MON166 is terminated if ‘y’ or ‘Y’ is pressed, otherwise the EXIT command will
be ignored.
296 Appendix D. Monitor-166
After the entry of the key F2 or ALT+2 MON166 response with the question:
Input File:
The user can enter a file name. The content of this file is interpreted as MON166
command input. If the file transfer should be stopped, the user can enter the key
Ctrl+C during the running file transfer.
Example:
Input File: INIT.CMD <cr>
After the entry of the key F3 or ALT+3 MON166 response with the question:
D Output File:
The user can enter a file name. Each character which is displayed on the screen
will be copied into this file.
Example:
Output File: DEBUG.PRN <cr>
The Screen Output is copied additionally into the file DEBUG.PRN. If the
protocol function should be stopped the user enters the key F3 or ALT+3. The
program MON166 displays the question:
Quit output to file (y or [n])?
The answer ‘y’ or ‘Y’ terminates the protocol function. Otherwise the file
protocol is continued.
is displayed. The answer ‘y’ or ‘Y’ deletes this file and creates a new file with this
name. Otherwise the function F3 is aborted.
166/167 Assembler and Utilities 297
Help Commands
Syntax Meaning
HELP list a brief description of all MON166 commands
Comments (‘;’)
Syntax Meaning
; comment insert line of comment
Comments can be inserted with a semi-colon. MON166 ignores any text after the
semi-colon. This is useful when a session is switched to a protocol file.
Example: D
#; this is a comment
Syntax Meaning
EXIT Exit MON166 and return to DOS
298 Appendix D. Monitor-166
Syntax Meaning
DB[startaddr [,endaddr]] Display memory in byte format
DW[startaddr [,endaddr]] Display memory in word format
DD[startaddr [,endaddr]] Display memory in double word format
D[startaddr [,endaddr]] Display memory in last used format
The second letter in the Display command specifies the format to be displayed. If
no start address is entered the last address used by the display command is used.
Examples:
#DB 1000,2000 ; display bytes from 1000 to 2000
#DW ,2100 ; display words (from 2000) to 2100
#DD ; display 4 lines double words (from 2100)
Syntax Meaning
EB [address] change contents of memory in byte format
EW [address] change contents of memory in word format
ED [address] change contents of memory in double word format
The second character of the E command specifies the input format to be used. The
address parameter can be omitted. If it is omitted the last address used when the
enter command was aborted is used. The address and the current value are
displayed after the command is entered. The following options are available:
Syntax Meaning
FILL startaddr, endaddr, value fill memory range with value
The FILL command writes a constant value to the specified memory area. Do not
fill the SFR space or the DATA memory of Monitor-166.
Examples:
#FILL 0, 3FFF, 23 fill memory area from 0 to 3FFF with value 23
#FILL 0, 18000, 00 command is not allow because SFRs are cleared
Syntax Meaning
D
U [startaddr [,endaddr]] Disassemble Memory
Examples:
#U
#U 100
#U 1000, 1100
Syntax Meaning
A [address] Load 166/167 instructions into memory
Assemble allows in-line assembly language to be inserted into the memory. This
enables code patches or the test of assembler instructions without writing an
assembler source files. The instruction parameters can be absolute addresses or
symbols of the SFR register set. The address can be omitted. In this case, the
address used by a previous Assemble command will be assumed. After the
assemble instruction is entered the instruction at the current code address is
displayed.
300 Appendix D. Monitor-166
Example:
#A 4000 <cr>
04000H ADD R15,R10 MOV R15,#4000 <cr>
04004H JMPR CC_SLE,04004H JMPS 0,2000 <cr>
04008H XOR R14,#1234 NOP <cr>
0400AH BSET R15.15 <cr> ; take over instruction
0400CH BSET R15.13 MOV P0,[R15] <cr>
04010H ADD DPP3:3FFFH,9EH MOV R1,T01CON <cr>
04014H RETI . <cr> ; terminate
#
Syntax Meaning
X display register contents
X <register name> change register contents
The X command without any parameter displays the current register contents in
the following format:
R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
xxxx
SP CP CSP IP MDH MDL DPP0 DPP1 DPP2 DPP3 PSW ILVL IEN FLAGS
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xx x umezvcn
The register names used in the display are the same that can be used as symbols:
Name Definition
R0-R15 Standard register bank (work register)
SP Stack Pointer
CP Context Pointer (start address of register bank)
CSP Code Segment Pointer
IP Instruction Pointer
MDH Multiply/Divide Register High
MDL Multiply/Divide Register Low
DPP0-DPP3 Data Page Pointer
166/167 Assembler and Utilities 301
Name Definition
PSW Program status word
xx, xxxx the current contents in hexadecimal format
The current interrupt level (ILVL), the interrupt enable flag (IEN) and the flags
are part of the Processor Status Word (PSW). Flags are displayed by a letter
corresponding to their name: Usr0, Mulip, End of table, Zero, oVerflow, Carry,
Negative. When this letter is displayed in uppercase the bit is set.
R0-R15, SP, CP, CSP, IP, MDH, MDL, DPP0-DPP3 and PSW can be used as
register names in conjunction with the X command. Also the SFR register set can
be used. The current register content is displayed and a new value can be assigned
to the register.
Examples:
#X DPP0
0FE00: 0000H 02 <cr>
#X SP
0FE12: FC00H
#X T0REL
FC10 <cr> D
0FE54: 0000H 0100 <cr>
302 Appendix D. Monitor-166
Breakpoint Commands
Sometimes it is necessary to stop the program execution to check the system and
to correct any errors. MON166 has the following break point commands:
Syntax Meaning
BS break address define break point
BreakSet sets a break point. The program (‘GO’ command) stops when the
instruction at the break point is reached. An error occurs if:
NOTE
Break addresses must be op code addresses! This means that a breakpoint must
be the address of the first op code byte of an instruction.
166/167 Assembler and Utilities 303
Examples:
#BS 8100 <cr>
#BS 39234 <cr>
Syntax Meaning
BK ALL Delete all break points
BK bp [, …] Delete specified break points
Breakpoints can be deleted using BreakKill. The ALL option deletes all defined
breakpoints. If single break points are to be deleted the breakpoint number (not
the address) must be entered. Several break points can be specified by separating
them with commas. The breakpoint number is listed with BreakList.
Examples:
#BK ALL <cr>
#BK 2 <cr>
#BK 0,2,6,9 <cr>
D
BreakList: Display Breakpoints
Syntax Meaning
BL List all break points
BreakList lists all the current breakpoints with the following components:
Break point number. Each break point is assigned a number between 0 and
15. This number is used in the BreakEnable, BreakDisable and BreakKill
command.
Break point status. A break point is either ENAbled or DISabled. A disabled
break point is not active during program execution.
Break address.
Syntax Meaning
BD ALL Disable all break points
304 Appendix D. Monitor-166
Syntax Meaning
BD bp [, …] Disable break points individually
BreakDisable disables breakpoints that are not currently required. The definitions
are not altered. The ALL option disables all defined breakpoints. Single
breakpoints can be disabled by specifying their breakpoint numbers (not
addresses). Several breakpoints can be disabled by separating the numbers with
commas. The breakpoint numbers can be listed using BreakList.
Examples:
#BD ALL
#BD 2
#BD 0,2,6,9,15
D Syntax
BE ALL
Meaning
enable all break points
BE bp [, …] enable named break points
Examples:
#BE ALL
#BE 2
#BE 0,2,6,9
166/167 Assembler and Utilities 305
Test Commands
The commands for user program execution and program single stepping are:
Syntax Meaning
G [startaddr [, breakaddr]] start program execution
Go starts program execution from the current program counter (CSP/IP) or from
the optional startaddr. The breakaddr is also optional. If the break address is not
specified, program execution stops at a breakpoint defined with BreakSet. If no
break points are defined program execution has to be stopped by a hardware reset. D
The breakaddr defines a temporary breakpoint and not a permanent breakpoint.
Examples:
#G <cr>
#G8100 <cr>
#G,8200 <cr>
#G8000,8010 <cr>
Syntax Meaning
T [count] start single step execution
Trace starts program execution in single step mode. The count of steps can be
between 1 and FFFF. 1 step is assumed if no count is specified. Breakpoints do
not affect program execution in single step mode. Trace can be stopped by
entering Ctrl+C. You can single step only program parts which reside in RAM.
306 Appendix D. Monitor-166
Examples:
#T <cr> execute a single step.
#T5 <cr> execute five steps.
Syntax Meaning
Procedure starts program execution like Trace in single step mode. The
difference is, that a subroutine (CALL instruction) executes as one single step.
The count of steps can be between 1 and FFFF. 1 step is assumed if no count is
specified. Breakpoints do not affect program execution while in procedure single
step mode. The P command can be stopped by entering Ctrl+C.
Examples:
#P <cr> execute one step.
#P8 <cr> execute eight steps.
166/167 Assembler and Utilities 307
Syntax Meaning
LOAD filename load the content of the file into 166/167 memory
Load a program in Intel HEX-86 or OMF-166 object format. The correct format
is automatically detected. The data is transferred to the 166/167 target memory.
Example:
#LOAD TESTPROG <cr>
#LOAD MYPROG.H86 <cr>
load an object program
load an Intel HEX-86 program
D
SAVE: Save Program in Intel HEX-86 Format
Syntax Meaning
SAVE filename, startaddr, endaddr The address range is stored in Intel HEX format in the
file.
Save is the opposite of Load. The memory address range specified is stored as an
Intel HEX-86 file. The data are transferred from the target board to the PC.
Example:
#SAVE MYPROG.H86 8000, 83FF <cr>
308 Appendix D. Monitor-166
D CC10IC
CC11
CC11IC
0FF8CH
0FE96H
0FF8EH
CCM2
CCM3
CP
0FF56H
0FF58H
0FE10H
PECC6
PECC7
PSW
0FECCH
0FECEH
0FF10H
T2IC
T3
T3CON
0FF60H
0FE42H
0FF42H
CC12 0FE98H CRIC 0FF6AH S0BG 0FEB4H T3IC 0FF62H
CC12IC 0FF90H CSP 0FE08H S0CON 0FFB0H T4 0FE44H
CC13 0FE9AH DP0 0FF02H S0EIC 0FF70H T4CON 0FF44H
CC13IC 0FF92H DP1 0FF06H S0RBUF 0FEB2H T4IC 0FF64H
CC14 0FE9CH DP2 0FFC2H S0RIC 0FF6EH T5 0FE46H
CC14IC 0FF94H DP3 0FFC6H S0TBUF 0FEB0H T5CON 0FF46H
CC15 0FE9EH DP4 0FF0AH S0TIC 0FF6CH T5IC 0FF66H
CC15IC 0FF96H DPP0 0FE00H S1BG 0FEBCH T6 0FE48H
CC1IC 0FF7AH DPP1 0FE02H S1CON 0FFB8H T6CON 0FF48H
CC2 0FE84H DPP2 0FE04H S1EIC 0FF76H T6IC 0FF68H
CC2IC 0FF7CH DPP3 0FE06H S1RBUF 0FEBAH TFR 0FFACH
CC3 0FE86H MDC 0FF0EH S1RIC 0FF74H WDT 0FEAEH
CC3IC 0FF7EH MDH 0FE0CH S1TBUF 0FEB8H WDTCON 0FFAEH
CC4 0FE88H MDL 0FE0EH S1TIC 0FF72H ZEROS 0FF1CH
CC4IC 0FF80H ONES 0FF1EH SP 0FE12H
CC5 0FE8AH P0 0FF00H STKOV 0FE14H
166/167 Assembler and Utilities 309
Note: COM3 or COM4 must be operated with the setting NOINT or INT14
since no standard hardware interrupts exist for these serial interfaces.
NOTE
Before you operate Monitor-166 with the dScope MON166.DLL you should
check if the MON166.EXE program works with your target board.
D MON166.EXE is easy to operate and you can check failures of the target board
or the Monitor-166 installation.
Port: selects the serial PC interface which is used for communication with the
target system. A new setting becomes active only when you press the Apply
button.
Baudrate: allows the selection of the baudrate. A new setting becomes active
only when you press the Apply button.
Peripheral DLL: the selected DLL file is automatically loaded with the
MON166.DLL. Since the MON166.DLL only provides the basic
communication functions to the target system it needs an additional DLL to
support derivative specific peripheral dialogs. A new selection will only take
effect the next time MON166.DLL is loaded.
Cache Enable: to speed up the screen output, a data cache is implemented.
This cache memory is only updated when a Single-Step or Go is executed. If
you want to view the actual value of port pins, timers or memory mapped
external peripherals you can switch these options off. For performance
reasons you should enable the cache. The check box SFR enables or disables
the cache memory in the area 0F000H-0FFFFH. The check box other
memory enables or disables the cache memory of the complete 16 MByte area
except the above mentioned SFR area.
D
Use serial interrupt: when this option is enabled, Monitor-166 allows to
terminate a running application program with the Ctrl+C or ESC key. To
support this interrupt feature, the serial interface is not longer available for the
user program. In addition, it is not allowed to reset the global Interrupt
Enable Flag IE (bit in PSW) in your application. A high to low transition at
the NMI# pin also terminates a running application program.
Breakpoint Options
Monitor-166 itself handles the breakpoints. When a access or conditional
breakpoint is set, the application is executed in single steps and not in real time.
Single step execution is at least 1000 times slower.
314 Appendix D. Monitor-166
Example:
L166 MYPROG.OBJ RESERVE (8H - 0BH, 0ACH - 0AFH, 0B8H - 0BBH)
Monitor-166 Configuration
The Monitor-166 software can be adapted to different hardware configurations
using the INSTALL batch utility. Parameters for INSTALL are listed below:
INSTALL CpuType SerialType datastart codestart [PROMCHECK | BOOTSTRAP]
The default baudrate is 9600 bps at 20 MHz CPU clock. The baudrate can be
changed by modifying the reload value of the serial baudrate generator in the
INSTxxxx.A66 file. Please refer to the README.TXT file in the MON166
directory for a detailed description of various board configurations and further
notes.
SerialType specifies the serial interface to be used by Monitor-166:
serialtype := 0 using serial interface 0
166/167 Assembler and Utilities 315
The default baudrate is set to 9600 bps at 20 Mhz CPU clock. The baudrate
can be changed by modifying the reload value of the serial baudrate generator
in the INSTxxxx.A66 file. Please see the notes in the README.TXT file in
the MON166 directory for using the simulated serial interface.
datastart is used to specify the page number of the data memory area which
the Monitor-166 uses for internal management (length = 512 bytes).
codestart is used to specify the page number of the code memory area used by
the Monitor-166 program (about 5 KByte).
If PROMCHECK is specified, Monitor-166 checks after reset whether a
PROM or a RAM is present at address 0. If a PROM was found, its program
is automatically started at address 0. Otherwise, Monitor-166 takes control
over the board. This option cannot be used when Monitor-166 is installed at
code address 0!
If BOOTSTRAP is specified, the Monitor-166 is generated for using the built D
in bootstrap loader of a 166/167/165. In this case, the file BOOT and
MONITOR will be generated instead of an HEX file. These two files are
copied to the BIN directory automatically in order to use them with MON166,
dScope. With this option it is not allowed to use SerialType = 1 or 2.
Example:
INSTALL KEI7 0 3E9 3EB BOOTSTRAP
The resulting files (MONITOR and BOOT) are automatically copied into the BIN
directory to be used by MON166 or dScope. No HEX file will be generated.
316 Appendix D. Monitor-166
D
166/167 Assembler and Utilities 317
Appendix E.
AMAKE Project Management Utility
This chapter describes the functions and operation of the AMAKE automatic
make utility. AMAKE generates the project dependency list directly form the
object files. AMAKE requires no user created make input file. It automatically
logs all information about the project generation.
Using AMAKE
The Keil C166 toolset saves the file dependencies of a project in the object files.
AMAKE uses this information for project management. Project management with
AMAKE requires that you initially create the project manually, compiling and
assembling all source files and linking all object files. Then, once the project has
been created, you may use AMAKE to update your target whenever you change a
C module, assembly source file, or header or include file. AMAKE uses the file
dependency list stored in the object file and re-translates only those files which
where modified.
AMAKE consists of the batch file AMAKE.BAT and the executable program
AMK.EXE. AMAKE.BAT activates AMK.EXE which in turn verifies the file
dependencies and creates the batch file AUTOMAKE.BAT. AUTOMAKE.BAT
contains the command lines required to rebuild the project. AMAKE.BAT starts
AUTOMAKE.BAT which re-creates the project.
318 Appendix E. AMAKE Project Management Utility
This command translates the source file HELLO.C and generates the output file
HELLO.OBJ. HELLO.OBJ is the input file for AMAKE. It contains the
following additional information:
The command line used to create the object file, in this case:
C166 HELLO.C CODE DEBUG SMALL REGFILE(HELLO.REG)
Time and date stamps of all files used to generate HELLO.OBJ. This
includes the source file HELLO.C and all include files used within HELLO.C.
The register usage of public functions in HELLO.C.
The known or assumed register usage of the external functions. The register
usage of an external function is known to the compiler if the file project.REG
lists this function name along with the register usage. The file project.REG is
created by the linker/locator. The register usage is used to perform
application wide register optimization.
E Once the object file has been created, the recreation of HELLO.OBJ can be
performed by the following command:
AMAKE HELLO.OBJ
If AMAKE does not detect changes to any of the source or include files which
were used to generate HELLO.OBJ, AUTOMAKE.BAT is not created. A file
modification is detected if one of the following conditions are met:
If the source file contains syntax errors, the compiler does not create an object file.
In this case, the AUTOMAKE.BAT file can be used to recreate the object file.
166/167 Assembler and Utilities 319
To create the project, compile the source files with the following three commands:
C166 MEASURE.C CODE DEBUG REGFILE (MEASURE.REG)
C166 MCOMMAND.C CODE DEBUG REGFILE (MEASURE.REG)
C166 GETLINE.C CODE DEBUG REGFILE (MEASURE.REG)
Next, link the resulting object files to create the linker output file MEASURE,
which contains the executable code. A command file named MEASURE.LIN is
used for linker input and contains the object file list and the linker control
directives.
MEASURE.OBJ, MCOMMAND.OBJ, GETLINE.OBJ
RESERVE (8H-0BH, 88H-8BH, 0ACH-0AFH, 0B8H-0BBH)
IXREF REGFILE (MEASURE.REG)
AMAKE generates only those commands which are required to update the linker
output file. If just the source file MEASURE.C is modified, only the C compiler
invocation for this source file and the linker invocation are created by AMAKE.
passes to optimize the register usage of an project. If the register usage is too
optimistic further re-translations can occur.
E COMPONENTS:
-----------
RECREATION COMMANDS:
--------------------
With AMAKE you can also create a batch file for the initial project generation.
Such batch files are useful when just the source code of a project is available.
Example for the creation of a batch file for complete project generation:
AMAKE MEASURE RECREATE CMDFILE (MEASURE.BAT)
322 Appendix E. AMAKE Project Management Utility
The template files contains section entries for each tool used in the AMAKE
process. A section entry is followed by commands which are copied to the batch
file after a translation command:
From the template file the section [start] is searched for and if found, the
commands belonging to the start section are copied to the batch file.
The command line of the object file to be retranslated is copied to the batch
file. Example: C166 MEASURE.C CODE DEBUG
The translator name (C166 in our example) is searched for a section entry in
the template file. A section entry has the format [translator name], for
example [C166]. If the translator section entry is found, the commands
E belonging to that section are copied to the batch file. In our example, these
are the command lines
@ECHO OFF
IF ERRORLEVEL 1 GOTO EXIT
@ECHO ON
The previous two steps are repeated for each object file to be rebuilt.
From the template file, the section [exit] is searched for and if found the
commands belonging to the exit section are copied to the batch file. The exit
section will be executed if creation of the project fails for some reason.
.
[start] The 'start' section.
@echo on
The template file enables the user to fine tune exit status analysis after a
translation command. If warnings in compilations are tolerated while creating the
project, the appropriate ‘IF ERRORLEVEL 1’ command would have to be
changed to ‘IF ERRORLEVEL 2’ to continue project creation on warnings, but
not on errors. The command belonging to the [L166] section checks for errorlevel
2, since a warning is created when using the incremental linking feature of L166
due to probably undefined external references.
The template file may be modified by the user to suit the specific requirements.
E
Removing AMAKE Information
AMAKE can be used to purge the project information from a object file. This is
achieved by specifying the PURGE control. Stripped files may be required by
third party tools such as emulators or PROM programmers. These tools will
eventually not process the special project information records used by AMAKE.
A stripped file cannot be used as input file for AMAKE.
AMAKE creates a new file which contains all records except the project
information records. In the following example, AMAKE creates the stripped file
MEASURE.O from the project file MEASURE. AMAKE Invocation:
AMAKE MEASURE PURGE
AMAKE uses the extension .O as default. The PURGE control may have an
additional argument which specifies the name of the stripped file:
AMAKE MEASURE PURGE (MEASURE.PRG)
AMAKE Invocation
You invoke AMAKE by entering AMAKE at the DOS command line. The general
command format is:
where:
inputfile is the name of a object file to be re-created.
controls one or more AMAKE control parameters.
The following table lists the AMAKE controls along with abbreviations and
E descriptions.
Invocation Examples E
Following are a few examples for AMAKE command lines:
In this example, the object file MEASURE is processed and the log output is
directed to the file MS.LOG.
In this example, the stripped object file MEASURE.PRG is created from the
object file MEASURE, which is left unchanged.
In this example, the object file MEASURE is processed and the log output is
directed to the file MEASURE.LOG. The pagewidth used in the log file is 80
characters.
326 Appendix E. AMAKE Project Management Utility
In this example, AMAKE generates the batch file GENALL.BAT from the object
file MEASURE which can be used for initial project creation.
AMAKE FATAL-ERROR:
LINE: <bad command line>
ERROR: <error message>
AMAKE ABORTED.
Fatal Errors
BAD OR CORRUPTED INPUTFILE
The AMAKE input file is a corrupted object file. Check the versions of your
tools to make sure they are the latest revision. Refer to “Using AMAKE” on
E page 317 for more information on required software versions.
CAN’T CREATE FILE
AMAKE cannot create an output file. This may be caused by an invalid file
name argument (invalid file name or directory name).
CAN’T OPEN FILE
The command line specifies a non existing file.
CONFLICTING CONTROL
The invocation line contains a control which contradicts with other controls,
for example LOG and NOLOG may not be specified together. The command
line is displayed up to and including the point of error.
*** ERROR IN OBJECT FILE ‘filename’:
NO AMAKE-INFORMATION AVAILABLE
AMAKE ABORTED.
AMAKE was given a object file which does not contain project information.
FILE WRITE ERROR ON <file name>
The file cannot be written to. This may be caused by insufficient disk space.
166/167 Assembler and Utilities 327
FILENAME SHARING
The name of an output file shares the name of an input file. This is not allowed
since the input file will be overwritten while processing it.
ILLEGAL INPUTFILE
The AMAKE input file is not a valid object file. AutoMAKE can be used to
process object files generated by Keil translators only.
INVALID DIGIT IN NUMBER
A numerical argument contains a non decimal digit.
INVOCATION LINE TOO LONG
The invocation line contains one or more tokens that are too long.
MISSING ‘(’
A control requires an additional argument enclosed in parenthesis, for example
PW(80). The open parenthesis was missing.
MISSING ‘)’
The closing parenthesis to an argument was missing.
MISSING ARGUMENT
The invocation line contains an incomplete control, for example PAGEWIDTH
without the required numerical argument.
NOT A DISK-FILE
The invocation line contains a file name which does not specify a disk file. An
input file to AMAKE must be a disk file.
E
OUT OF MEMORY
AMAKE has not enough memory to operate.
UNKNOWN CONTROL
The invocation line to AMAKE contains an unknown control. The command
line is displayed up to and including the point of error.
VALUE OUT OF RANGE
A numerical argument to a control was out of range, for example PW(500).
328 Appendix E. AMAKE Project Management Utility
E
166/167 Assembler and Utilities 329
Glossary
A166
The command used to assemble programs using the A166 Macro Assembler.
aggregate types
Arrays, structures, and unions.
argument
The value that is passed to macro or function.
arithmetic types
Data types that are integral, floating-point, or enumerations.
array
A set of elements all of the same data type.
ASCII
American Standard Code for Information Interchange. This is a set of 256
codes used by computers to represent digits, characters, punctuation, and other
special symbols. The first 128 characters are standardized. The remaining
128 are defined by the implementation.
basename
The part of the file name that excludes the drive letter, directory name, and file
extension. For example, the basename for the file C:\SAMPLE\SIO.A66 is
SIO.
batch file
A text file that contains MS-DOS commands and programs that can be invoked
from the command line.
C166
The command used to compile programs using the 166/167 Optimizing C
Cross Compiler.
code banking
See bank switching.
constant expression
Any expression that evaluates to a constant non-variable value. Constants may
include character, integer, enumeration, and floating-point constant values.
330 Glossary
declaration
A C construct that associates the attributes of a variable, type, or function with
a name.
definition
A C construct that specifies the name, formal parameters, body, and return
type of a function or that initializes and allocates storage for a variable.
directive
An instruction to the C preprocessor or a control switch to the compiler,
assembler or linker.
DPP
The Data Page Pointer registers of the 166/167 CPU. There are four DPP
registers: DPP0-DPP3 available. The DPP registers hold the most significant
for near addresses. The actual DPP register used for a near address is
specified by the bit 14 and bit 15 of the address. The physical address is
calculated using the following formula:
DSW166
The command used to load and execute the 166/167 Simulator/Debugger.
environment table
The memory area used by MS-DOS to store environment variables and their
values.
environment variable
A variable stored in the environment table. These variables provide MS-DOS
programs with information like where to find include files and library files.
escape sequence
A backslash (‘\’) character followed by a single letter or a combination of
digits that specifies a particular character value in strings and character
constants.
expression
A combination of any number of operators and operands that produces a
constant value.
function
A combination of declarations and statements that can be called by name that
perform an operation and/or return a value.
166/167 Assembler and Utilities 331
function call
An expression that invokes and possibly passes arguments to a function.
include file
A text file that is incorporated into a source file using the #include
preprocessor directive.
keyword
A reserved word with a predefined meaning for the compiler.
L166
The command used to link object files and libraries using the 166/167
Linker/Locator.
LIB166
The command used to manipulate 166/167 library files using the 166/167
Library Manager.
library
A file that stores a number of possibly related object modules. The linker can
extract modules from the library to use in building a target object file.
macro
An identifier that represents a series of keystrokes that is defined using the
#define preprocessor directive.
manifest constant
A macro that is defined to have a constant value.
memory model
Any of the models that specifies which memory areas are used for function
arguments and local variables.
newline character
The character used to mark the end of a line in a text file or the escape
sequence (‘\n’) used to represent the newline character.
null character
The ASCII character with the value 0 represented as the escape sequence
(‘\0’).
332 Glossary
null pointer
A pointer that references nothing and has an offset of 0000h. A null pointer
has the integer value 0.
object
An area of memory that can be examined. Usually used when referring to the
memory area associated with a variable or function.
object file
A file, created by the compiler, that contains the program segment information
and relocatable machine code.
OH166
The command used to convert absolute object files into other hexadecimal file
formats using the Object File Converter.
operand
A variable or constant that is used in an expression.
operator
A symbol that specifies how to manipulate the operands of an expression; e.g.,
+, -, *, /.
parameter
The value that is passed to a macro or function.
pointers
A variable that contains the address of another variable, function, or memory
area.
pragma
A statement that passes an instruction to the compiler at compile time.
relocatable
Able to be moved or relocated. Not containing absolute or fixed addresses.
RTX166 Full
An 166/167 Real-Time Executive that provides a multitasking operating
system kernel and library of routines for its use.
RTX166 Tiny
A limited version of RTX166.
scalar types
Integer, enumerated, floating-point, and pointer types.
166/167 Assembler and Utilities 333
scope
The sections or a program where an item (function or variable) can be
referenced by name. The scope of an item may be limited to file, function, or
block.
source file
A text file containing assembly program code.
stack
An area of memory, indirectly accessed by a stack pointer, that shrinks and
expands dynamically as items are pushed onto the stack and popped off of the
stack. Items in the stack are removed on a LIFO (last-in, first-out) basis.
static
A storage class that, when used with a variable declaration in a function,
causes variables to retain their value after exiting the block or function in
which they are declared.
string
An array of characters that is terminated with a null character (‘\0’).
string literal
A string of characters enclosed within double quotes (“ ”).
token
A fundamental symbol that represents a name or entity in a programming
language.
two’s complement
A binary notation that is used to represent both positive and negative numbers.
Negative values are created by complementing all bits of a positive value and
adding 1.
type
A description of the range of values associated with a variable. For example,
an int type can have any value within its specified range (-32768 to 32767).
whitespace character
Characters that are used as delimiters in C programs such as space, tab,
newline, etc.
wild card
One of the MS-DOS characters (? or *) that can be used in place of characters
in a filename.
334 Glossary
166/167 Assembler and Utilities 335
Index
ASSUME....................................38, 56
_ AT expression.................................. 35
at sign .............................................. 66
_task_ .............................................255
B
A
balanced text ...................................108
A166, defined .................................329 basename, defined...........................329
ABSOLUTE..............................70, 160 basic instructions ............................146
absolute batch file, defined............................329
Operands .................................... 19 bit section ........................................ 32
Absolute Object File........................160 bitaddressable .............................32, 33
Absolute object files ........................155 bit-addressable ................................. 62
ABSOLUTE, control........................ 70 bit-pointer ........................................ 62
Additional items, notational Bitword............................................ 21
conventions .................................... iv blank-delimiter ...............................127
Address bold capital text, use of...................... iv
Expression.................................. 60 boundary.......................................... 54
Operand ..................................... 25 braces, use of..................................... iv
aggregate types, defined ..................329
alignment......................................... 54
align-type......................................... 33
C
Allocating Memory .........................159 C166 Memory Models.....................256
Internal Data Area.....................159 C166 Run-Time Library..................256
AMAKE C166 Support..................................255
Error messages ..........................326 C166, defined..................................329
Invocation .................................324 call-pattern......................................125
Invocation examples ..................325 CASE .............................................. 71
Linker command files ................319 CASE, control.................................. 71
Projects......................................319 CGROUP ......................................... 37
Reg file......................................319 character string ...............................116
Removing AMAKE Choices, notational conventions ........ iv
Information.............................323 Classes............................................157
Template file .....................321, 322 class-name ....................................... 35
Using.........................................317 code banking, defined .....................329
AMAKE Project Management code section ..................................... 32
Utility...........................................317 Combining program modules ..........156
AMAKE.INI ...................................322 Combining Sections ........................157
Application Example ......................219 Command Files...............................163
argument, defined ...........................329 Command line ................................. 65
arithmetic types, defined .................329 Command-Line Directives ..............165
array, defined ..................................329 Command-Line Examples...............163
ASCII, defined................................329 comment .......................................... 11
Assembler Controls.......................... 67 COMMON....................................... 34
336 Index
DBIT.......................................... 59 DS ................................................... 59
DBPTR....................................... 62 DSB................................................. 59
DEFA......................................... 50 dScope ............................................312
DEFB ......................................... 50 DSPTR ............................................ 62
DEFR ......................................... 50 DSW................................................ 59
DPPTR ....................................... 62 DSW166, defined............................330
DS.............................................. 59 DW.................................................. 59
DSB ........................................... 59
DSPTR ....................................... 62 E
DSW .......................................... 59
DW ............................................ 59 EJECT ............................................. 75
END........................................... 63 EJECT, control ................................ 75
ENDP......................................... 43 ellipses, use of................................... iv
ENDS......................................... 32 ellipses, vertical, use of ..................... iv
EQU ........................................... 46 ELSE ..............................................104
EVEN......................................... 54 ELSE, control .................................104
EXTERN.................................... 55 ELSEIF...........................................103
EXTRN ...................................... 55 ELSEIF, control..............................103
GLOBAL.................................... 57 END ................................................ 63
GROUP ...................................... 37 ENDIF ............................................105
LABEL....................................... 49 ENDIF, control ...............................105
LIT............................................. 52 ENDP .............................................. 43
NAME........................................ 63 ENDS .............................................. 32
ORG........................................... 53 environment table, defined ..............330
PROC......................................... 43 environment variable, defined .........330
PUBLIC ..................................... 57 EOF record .....................................242
SECTION................................... 32 Error messages................................131
SET............................................ 47 action ........................................131
SSKDEF..................................... 42 fatal...........................................131
TYPEDEC.................................. 53 non-fatal............................131, 134
directive, defined.............................330 of L166......................................210
Directives......................................... 31 ERRORLEVEL.........................66, 164
defb ............................................ 48 ERRORPRINT................................. 76
pecdef......................................... 42 ERRORPRINT, control .................... 76
regbank ...................................... 41 escape sequence, defined .................330
regdef ......................................... 41 EVEN .............................................. 54
Directives Exception Messages ........................218
assume........................................ 22 EXPDECNUM................................. 77
Displayed text, notational EXPDECNUM, control.................... 77
conventions .................................... iv Expression ......................................114
Document Conventions ..................... iv Numbers..................................... 13
dollar sign........................................ 16 Strings........................................ 13
Numbers..................................... 13 expression, defined..........................330
double brackets, use of ...................... iv EXPRESSIONS ............................... 16
DPP, defined...................................330 EXTERN ......................................... 55
DPPTR ............................................ 62 external constant .............................. 17
external symbol................................ 56
338 Index
K RESERVE.................................196
RTX166 ....................................197
Key names, notational RTX166TINY ...........................198
conventions .................................... iv SECSIZE...................................199
keyword, defined.............................331 SECTIONS................................200
VECTAB...................................201
L WARNINGLEVEL....................202
L166 ...............................................153 L166 linker/locator .........................153
Error Messages..........................210 L166 MAP file ................................160
Exception Messages...................218 L166, defined..................................331
Fatal Errors ...............................215 label............................................11, 15
invocation with TGROUPS........207 LIB166 ...........................................229
Library Files ..............................156 ADD..........................................230
Listing File................................160 Adding Object Modules .............232
Non Fatal Errors........................212 Command line...........................229
Output File ................................164 Commands ................................230
Warning detection .....................202 CREATE...................................230
Warnings...................................210 Creating a Library .....................231
L166 Directives DELETE ...................................230
ASSIGN ....................................168 Error Messages..........................236
CLASSES..................................169 EXIT .........................................230
DPPUSE....................................170 HELP ........................................230
GROUPS ...................................172 Help Information .......................235
INTNO......................................173 Interactive mode ........................229
IXREF.......................................174 LIST..........................................230
LINKONLY ..............................175 Listing Library Contents............234
NAME.......................................176 Removing Object Modules.........233
NOAMAKE ..............................177 LIB166, defined ..............................331
NOCASE...................................178 Library Manager .............................229
NOCOMMENTS.......................179 library, defined................................331
NODEFAULTLIBRARY...........180 Linking Programs with L166 ..........161
NOINIT.....................................181 LIST ................................................ 81
NOLINES..................................182 LIST, control ................................... 81
NOMAP ....................................183 LIT .................................................. 52
NOPUBLICS.............................184 LIT Directive ..................................... 9
NOTYPE...................................185 literal mode.....................................128
NOVEVTAB.............................186 literal-character...............................109
OBJECTCONTROLS................187 literal-delimiter...............................126
PAGELENGTH.........................188 literalize..........................................128
PAGEWIDTH ...........................189 local-symbols ..................................111
PRINT.......................................190 Long Command Lines.....................163
PRINTCONTROLS...................191 LST files .......................................... 67
PUBLICSONLY........................192
PURGE .....................................193 M
REGBANK................................194 machine instruction.......................... 11
REGFILE ..................................195 Macro .............................................. 82
340 Index
SYMBOLS ...................................... 94 U
SYMBOLS, control.......................... 94
SYSSTACK..................................... 34 USEDEXTONLY ............................ 98
SYSTEM ....................................37, 39 USING............................................. 45
USRSTACK..................................... 34
T
V
TABS............................................... 95
TABS, control.................................. 95 Variables, notational
TASK .............................................. 44 conventions .................................... iv
Task Concept ..................................207 vertical bar, use of............................. iv
Task Declaration.............................255
Task Management...........................253 W
Task Switching ...............................254 Wait for Signal ...............................248
TGROUP ......................................... 35 Wait for Timeout ............................247
TGROUPS ......................................207 Warnings
using with Emulators.................209 of L166......................................210
three pass....................................24, 53 whitespace character, defined..........333
TITLE.............................................. 96 wild card, defined ...........................333
TITLE, control................................. 96 word alignment................................ 59
token, defined .................................333
two’s complement, defined..............333
TYPE............................................... 97
X
type mismatch.................................. 49 XREF............................................... 99
TYPE, control.................................. 97 XREF, control.................................. 99
type, defined ...................................333
TYPEDEC ....................................... 53