You are on page 1of 352

166/167 Assembler

and Utilities
A166 Macro Assembler
L166 Linker/Locator
LIB166 Library Manager
OH166 Object File Converter
RTX166 Tiny Real-Time Operating System
Monitor166 Target Monitor

User’s Guide 07.96


ii Keil Software

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.

Copyright © 1990-1996 Keil Elektronik GmbH., and Keil Software, Inc.


All rights reserved.

Keil C166™ and dScope™ are trademarks of Keil Elektronik GmbH.


Microsoft®, MS-DOS®, and Windows™ are trademarks or registered trademarks
of Microsoft Corporation.
IBM®, PC®, and PS/2® are registered trademarks of International Business
Machines Corporation.

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.

This user’s guide is divided into the following eight chapters:

“Chapter 1. Introduction”, describes the operation of A166, L166, LIB166 and


OH166 and explains their functions with a sample program.

“Chapter 2. Operands and Expressions”, describes the operands, address


descriptors, and the rules for arithmetic and logical expressions.

“Chapter 3. Assembler Directives”, describes the A166 Assembler directives that


define symbols and segments as well as control the memory of the 166/167 CPU.

“Chapter 4. Invocation and Controls”, describes the control instructions that


effect the operation of the A166 assembler.

“Chapter 5. The Macro Processor”, describes the function and control


instructions of the macro processor and the necessary instruction control for use.

“Chapter 6. Error Messages”, contains a list of all A166 error messages and
describes their causes and how to avoid them.

“Chapter 7. Implementation Specifics”, contains a list of reserved words,


predefined special function registers and all the 166/167 instructions.

“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:

CLS DIR L166.EXE

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:

A166 TEST.A66 PRINT †(filename)‡


{ opt1 | opt2 } Text contained within braces, separated by a vertical bar represents a group
of items from which one must be chosen. The braces enclose all of the
choices and the vertical bars separate the choices. One item in the list
must be selected.
Keys Text in this sans serif typeface represents actual keys on the keyboard. For
example, “Press Enter to continue.”
166/167 Assembler and Utilities v

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

PAGING / NOPAGING ................................................................................... 88


PRINT / NOPRINT.......................................................................................... 89
REGUSE.......................................................................................................... 90
SAVE / RESTORE .......................................................................................... 92
SEGMENTED / NONSEGMENTED............................................................... 93
SYMBOLS / NOSYMBOLS ............................................................................ 94
TABS............................................................................................................... 95
TITLE.............................................................................................................. 96
TYPE / NOTYPE............................................................................................. 97
USEDEXTONLY............................................................................................. 98
XREF / NOXREF ............................................................................................ 99
Directives for Conditional Assembly.....................................................................100
SET / RESET..................................................................................................101
IF....................................................................................................................102
ELSEIF...........................................................................................................103
ELSE ..............................................................................................................104
ENDIF ............................................................................................................105
Chapter 5. The Macro Processor ................................................................ 107
Introduction..........................................................................................................107
Overview.........................................................................................................107
Creating and Calling Macros ..........................................................................107
Creating Parameterless Macros .......................................................................108
Macros with Parameters ..................................................................................109
Local Symbols List..........................................................................................111
Macro Processor Functions ...................................................................................111
Comment Function..........................................................................................112
Escape Function ..............................................................................................112
Bracket Function.............................................................................................113
METACHAR Function ...................................................................................114
Numbers and Expressions ...............................................................................114
SET Function..................................................................................................116
EVAL Function...............................................................................................117
Logical Expressions and String Comparison ...................................................118
Conditional Macro Processing ..............................................................................119
IF Function .....................................................................................................119
WHILE Function.............................................................................................120
REPEAT Function ..........................................................................................121
EXIT Function................................................................................................121
String Manipulation Functions .............................................................................122
LEN Function .................................................................................................122
SUBSTR Function...........................................................................................123
MATCH Function ...........................................................................................123
Console I/O Functions ..........................................................................................124
Advanced Macro Processing .................................................................................125
Literal Delimiters............................................................................................126
Blank Delimiters.............................................................................................127
viii Contents

Identifier Delimiters ....................................................................................... 127


Literal and Normal Mode................................................................................ 128
MACRO Errors.................................................................................................... 129
Chapter 6. Error Messages..........................................................................131
Fatal Errors .......................................................................................................... 131
Non-Fatal Errors .................................................................................................. 134
Chapter 7. Implementation Specifics ...........................................................145
Implementation Limits ......................................................................................... 145
166/167 Instruction Set ........................................................................................ 145
Basic Instruction Set ....................................................................................... 146
Software Instruction Set.................................................................................. 148
Reserved Words in A166...................................................................................... 149
Predefined SFR and Bit Names ............................................................................ 151
Chapter 8. L166 Linker/Locator .................................................................153
L166 Overview..................................................................................................... 155
Combining program modules.......................................................................... 156
Sections .......................................................................................................... 156
Section Alignment .......................................................................................... 156
Combining Sections........................................................................................ 157
Classes............................................................................................................ 157
Groups............................................................................................................ 158
Allocating 166/167 Memory ........................................................................... 159
Producing a Listing File.................................................................................. 160
Using RTX166 and RTX166 Tiny .................................................................. 161
Linking Programs with L166................................................................................ 161
Long Command Lines .................................................................................... 163
Command Files............................................................................................... 163
Command-Line Examples............................................................................... 163
DOS Errorlevel............................................................................................... 164
Entering Names in Lower Case....................................................................... 164
Command-Line Directives .............................................................................. 165
ASSIGN ......................................................................................................... 168
CLASSES....................................................................................................... 169
DPPUSE......................................................................................................... 170
GROUPS ........................................................................................................ 172
INTNO ........................................................................................................... 173
IXREF ............................................................................................................ 174
LINKONLY ................................................................................................... 175
NAME............................................................................................................ 176
NOAMAKE.................................................................................................... 177
NOCASE........................................................................................................ 178
NOCOMMENTS............................................................................................ 179
NODEFAULTLIBRARY................................................................................ 180
NOINIT.......................................................................................................... 181
NOLINES....................................................................................................... 182
166/167 Assembler and Utilities ix

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

Intel HEX File Format.......................................................................................... 241


Record Format ................................................................................................ 241
Data Record.................................................................................................... 242
End-of-File (EOF) Record............................................................................... 242
8086 Segment Address Record........................................................................ 243
Extended Linear Address Record .................................................................... 243
Example Intel HEX File.................................................................................. 244
Appendix C. RTX166 TINY........................................................................245
Introduction ......................................................................................................... 245
Round-Robin Task Switching ......................................................................... 246
Wait for Timeout ............................................................................................ 247
Wait for Signal ............................................................................................... 248
Generating RTX166 Applications................................................................... 249
RTX166 Tiny Technical Data .............................................................................. 250
RTX166 Tiny Functions ................................................................................. 250
RTX166 Full Technical Data ............................................................................... 251
RTX166 Full Functions .................................................................................. 251
Software Requirements......................................................................................... 253
Task Management................................................................................................ 253
Task Switching............................................................................................... 254
Task Declaration............................................................................................. 255
C166 Specific Support.......................................................................................... 255
Interrupt Handling .......................................................................................... 256
C166 Memory Models .................................................................................... 256
Use of the C166 Run-Time Library ................................................................. 256
RTX166 Tiny System Functions........................................................................... 257
Name Assignment .......................................................................................... 257
Return Values................................................................................................. 257
Include Files ................................................................................................... 257
Function Overview.......................................................................................... 259
os_clear_signal ............................................................................................... 260
os_create_task................................................................................................. 261
os_delay_task.................................................................................................. 262
os_delete_task................................................................................................. 263
os_running_task_id ........................................................................................ 264
os_send_signal / isr_send_signal .................................................................... 265
os_wait ........................................................................................................... 266
os_wait_signal ................................................................................................ 268
Configuration....................................................................................................... 269
CONF_TNY.A66............................................................................................ 269
CPUTIMER.INC ............................................................................................ 269
Stack Management ......................................................................................... 270
Optimizing RTX166 Tiny Applications .......................................................... 271
System Debugging .......................................................................................... 271
Application Examples .......................................................................................... 273
RTX_EX1: The first RTX166 Program.......................................................... 273
166/167 Assembler and Utilities xi

RTX_EX2: A simple RTX166 Application ....................................................275


Traffic: Pedestrian Traffic Light Controller....................................................277
Appendix D. Monitor-166............................................................................ 289
Hardware and Software Requirements ..................................................................289
MON166.EXE: DOS Monitor Driver....................................................................290
MON166.EXE Control Keys ...........................................................................292
MON166.EXE Terminal Control Codes..........................................................293
Serial Transmission Line ................................................................................294
MON166.EXE Commands..............................................................................295
Help Commands..............................................................................................297
Displaying and Changing Memory.................................................................298
Breakpoint Commands....................................................................................302
Test Commands ..............................................................................................305
Load and Save.................................................................................................307
Predefined Special Function Registers .............................................................308
MON166 Error Messages................................................................................309
MON166.DLL: dScope Monitor Driver ...............................................................312
MON166.DLL Configuration Dialog...............................................................312
Restrictions of dScope with MON166.DLL .....................................................313
Resources used by Monitor-166.......................................................................314
Monitor-166 Configuration...................................................................................314
Appendix E. AMAKE Project Management Utility.................................... 317
Using AMAKE.....................................................................................................317
Re-translating an Object File ................................................................................318
Re-creating a Linker Output File ..........................................................................319
Application-wide Register Optimization ...............................................................319
List Project Information........................................................................................320
Create a Batch File ...............................................................................................321
AMAKE Template File ........................................................................................322
Removing AMAKE Information...........................................................................323
AMAKE Invocation..............................................................................................324
Invocation Examples .......................................................................................325
AMAKE Error Messages......................................................................................326
Fatal Errors.....................................................................................................326
Glossary........................................................................................................ 329
Index ............................................................................................................. 335
xii Contents
166/167 Assembler and Utilities 1

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.

Assembly language operation codes (mnemonics) are easily remembered (MOV


for move instructions, ADD for addition, and so on). You can also symbolically
express addresses and values referenced in the operand field of instructions. Since
you assign these names, you can make them as meaningful as the mnemonics for
the instructions. For example, if your program must manipulate a date as data,
you can assign it the symbolic name DATE. If your program contains a set of
instructions used as a timing loop (a set of instructions executed repeatedly until a
specific amount of time has passed), you can name the instruction group
TIMER_LOOP.

An assembly program has three constituent parts:

„ Machine instructions
„ Assembler directives
„ Assembler controls

A machine instruction is a machine code that can be executed by the machine.


Detailed discussion of the machine instructions can be found in the hardware
2 Chapter 1. Introduction

manuals of the 166/167 microcontrollers. Appendix A provides an overview


about machine instructions.

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.

How to Develop A Program


The A166 assembler enables the user to program in a modular fashion. The
following paragraphs explain the basics of modular program development.

Advantages of Modular Programming


Many programs are too long or complex to write as a single unit. Programming
becomes much simpler when the code is divided into small functional units.
Modular programs are usually easier to code, debug, and change than monolithic
programs.

The modular approach to programming is similar to the design of hardware that


contains numerous circuits. The device or program is logically divided into “black
boxes” with specific inputs and outputs. Once the interfaces between the units
have been defined, the detailed design of each unit can proceed separately.

Efficient Program Development


Programs can be developed more quickly with the modular approach since small
subprograms are easier to understand, design, and test than large programs. With
the module inputs and outputs defined, the programmer can supply the needed
input and verify the correctness of the module by examining the output. The
separate modules are than linked and located by the linker into an absolute
executable single program module. Finally, the complete module is tested.
166/167 Assembler and Utilities 3

Multiple Use of Subprograms


Code written for one program is often useful in others. Modular programming
allows these sections to be saved for future use. Because the code is relocatable, 1
saved modules can be linked to any program which fulfills their input and output
requirements. With monolithic programming, such sections of code are buried
inside the program and are not so available for use by other programs.

Ease of Debugging and Modifying


Modular programs are generally easier to debug than monolithic programs.
Because of the well defined module interfaces of the program, problems can be
isolated to specific modules. Once the faulty module has been identified, fixing
the problem is considerably simpler. When a program must be modified, modular
programming simplifies the job. You can link new or debugged modules to an
existing program with the confidence that the rest of the program will not change.

Modular Program Development Process


This section is a brief discussion of the program development process with the
relocatable A166 assembler, L166 Linker/Locator, and the OH166 code
conversion program.

Sections, Modules, and Programs


In the initial design stages, the tasks to be performed by the program are defined,
and then partitioned into subprograms. Here are brief introductions to the kinds of
subprograms used with the A166 assembler and L166 linker/locator.

A section is a block of code or data memory. A section may be relocatable or


absolute. A relocatable section has a name, type, and other attributes. Sections
with the same name, from different modules, are considered part of the same
section and are called “partial section.” Partial sections are combined into
sections by L166. An absolute segment cannot be combined with other segments.

A module contains one or more segments or partial segments. A module has a


name assigned by the user. The module definitions determine the scope of local
symbols.
4 Chapter 1. Introduction

A program consists of a single absolute module, merging all absolute and


relocatable segments from all input modules.

1 Program Entry and Exit


After the design is completed, the source code for each module is entered into a
disk file using any text editor. When errors are detected in the development
process, the text editor may be used to make corrections in the source code.

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.

Relocation and Linkage


After assembly of all modules of the program, L166 processes the object module
files. the L166 program assigns absolute memory locations to all the relocatable
segments, combining segments with the same name and type. L166 also resolves
all references between modules. L166 outputs an absolute object module file with
the completed program, and a summary listing file showing the results of the
link/locate process.
166/167 Assembler and Utilities 5

Keeping Track of Files


It is convenient to use the extensions of filename to indicate the stage in the
process represented by the contents of each file. Thus, source code files can use 1
extensions like .SRC or .A66 (indicating that the code is for input to the A166
assembler). Object code files receive the extension .OBJ by default, or the user
can specify another extension. Executable files generally have no extension.
Listing files can use .LST, the default extension assigned by the assembler. L166
uses .M66 for the default linker map file extension.
6 Chapter 1. Introduction

Writing and Assembling Programs


1 There are several steps necessary to incorporate a 166/167 microcomputer in your
application. The following figure shows an overview of the steps involved in
creating a program for the 166 or a 167 derivative.

Assembler
Source File

A166
Macro Assembler

Listing
File
Object
Other File
Objects or
Libraries

L166
Linker/Locater

MAP
File
Absolute
Object
File

OH166 dScope-166 In-Circuit


Object Hex Converter HLL Debugger Emulator

HEX
File

PROM Programmer
166/167 Assembler and Utilities 7

If you are developing hardware for your application, consult the 166/167
hardware manuals.

Following is an example listing file generated by the assembler. 1


A166 MACRO ASSEMBLER SAMPLE 24/04/92 15:44:45 PAGE 1

DOS MACRO ASSEMBLER A166 V3.00


OBJECT MODULE PLACED IN SAMPLE.OBJ
ASSEMBLER INVOKED BY: E:A166.EXE SAMPLE.A66 SET(SMALL) XREF PW(78)
DEBUG

LOC OBJ LINE SOURCE

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

A166 MACRO ASSEMBLER SAMPLE 24/04/92 15:44:45 PAGE 2

1 XREF SYMBOL TABLE LISTING


---- ------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

?PR?SERINIT. . . . ---- ---- SECTION 12# 50


DP3. . . . . . . . WORD FFC6H A SFR 21 22
DPP3 . . . . . . . WORD FE06H A SFR 10
MODEL. . . . . . . LIT "NEAR" 6#
P3 . . . . . . . . WORD FFC4H A SFR 20
S0BG . . . . . . . WORD FEB4H A SFR 25
S0CON. . . . . . . WORD FFB0H A SFR 26
S0RIC. . . . . . . WORD FF6EH A SFR 24
S0TIC. . . . . . . WORD FF6CH A SFR 23
SERINIT. . . . . . NEAR 0000H R PUB SEC=?PR?SERINIT 9 14# 28
T2 . . . . . . . . WORD FE40H A SFR 34 46
T2CON. . . . . . . WORD FF40H A SFR 32 37 43
T3 . . . . . . . . WORD FE42H A SFR 35 45
T3CON. . . . . . . WORD FF42H A SFR 33 36 44
TIMERSTART . . . . NEAR 0018H R PUB SEC=?PR?SERINIT 9 31# 39
TIMERSTOP. . . . . NEAR 0032H R PUB SEC=?PR?SERINIT 9 42# 48

ASSEMBLY COMPLETE. 0 WARNING(S), 0 ERROR(S)

The fields in the listing file have the following meaning:

0000 AFE2 20 BSET P3.10 ; OUTPUT LATCH (TXD)

original source line

line number (issued by the assembler)

R/E indicates relocatable or external expression that must be


calculated by the Linker/Locator L166

hexadecimal form of the generated object code

state of the address counter in the current section

The symbol table at the end of the listing is as follows:


N A M E TYPE VALUE I ATTRIBUTES

?PR?SERINIT. . . . ---- ---- SECTION 12# 50


DP3. . . . . . . . WORD FFC6H A SFR 21 22
DPP3 . . . . . . . WORD FE06H A SFR 10
MODEL. . . . . . . LIT "NEAR" 6#

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

SERINIT. . . NEAR 0000H R PUB SEC=?PR?SERINIT 9 14# 28

1 relocatable

'SERINIT' was defined (and used) in line 14,


and also used in line 9 and 28. The parent
sections name is '?PR?SERINIT'

the numerical value of 'LOOP' is 0000H

'SERINIT' is a label of type 'near'

the name of the symbol is 'SERINIT'

To assemble the above module, the assembler was invoked using the following
command line:
A166 SAMPLE.A66 SET(SMALL) XREF PW(78)

The assembler output for this command line is:


DOS MACRO ASSEMBLER A166 V3.00
COPYRIGHT KEIL ELEKTRONIK GmbH 1992 - 1996

ASSEMBLY COMPLETE. 0 WARNING(S), 0 ERROR(S)

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

L166 LINKING COMPLETE, 0 WARNINGS, 0 ERRORS


166/167 Assembler and Utilities 11

Chapter 2. Operands and Expressions


Assembler Programs for the 166/167 processor family consist of lines of166/167
mnemonic instructions. A line can contain at most one machine instruction. The
general form of all instruction lines is as follows:

[label:] mnemonic[Expr.][,Expr.][,Expr.] [; comment] <eol>:


example: 2
start: MOV DPP2,#PAG D_GROUP ; initialize DPP0
MOV DPP3,#3 ; load System Page
MOV R0,R15

The use of a label is optional. Labels basically serve two purposes:

„ 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:

„ Special assembler symbols like register names.


„ Program symbols like labels, section names, group names, and external
names.
„ Direct and indirect addresses.
„ Constants.

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:

Rn,Rm direct access to the General Purpose Registers (GPR’s)


2 within the current registerbank. Each registerbank normally
contains the registers R0 to R15. Since the GPR’s are located
in on-chip RAM of the CPU, the registerbank acts like a
register window, which can be switched to another bank by
means of changing the context pointer (CP).

REG direct access to any GPR or special function register (SFR).


REG forms an 8-bit number to designate the required location
in internal memory.

BITWORD access to some word in the bit-addressable memory space.

BITADDR access to some single bit in the bit-addressable memory


space.

MEM access to any memory location.

[Rn],[Rm] indirect access to the entire memory space by the content of a


GPR.

#DATAn an immediate constant value where n = 3, 4, 8, 16.

CADDR 16-bit code address within the current 64K segment for use in
branch instructions.

REL relative offset for use in a branch instruction. The covered


range is +127 / -128 words relative to the current offset.

SEG code segment number. The 166/167 addresses up to 256K of


memory, therefore the segment numbers 0, 1, 2 and 3 exist.

#TRAP a 7-bit constant used as interrupt vector numbers.

CC_cond condition code; CC_UC for unconditionally, CC_ULE for


unsigned lower or equal condition and so on.
166/167 Assembler and Utilities 13

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.

Base Suffix Valid Characters Examples


Hexadecimal H,h 0-9, A-F, a-f 1234H 99H 123H 0A0F0H 0FFH
Decimal D,d 0-9 1234 65590D 20d 123
Octal O,o,Q,q 0-7 177O 7777o 25O 123o 177777O
Binary B,b 0-1 1111B 10011111B 101010101B
Hexadecimal numbers must be preceded with a 0, if the first digit is in range A to F.

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

Character strings can also be used outside of expressions (example: the DB


directive). The limit of two characters does not apply in this case.

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 (‘’).

‘A’ evaluates to 0041H

‘AB’ evaluates to 4142H

‘a’ evaluates to 0061H

‘ab’ evaluates to 6162H

‘’ the null string is not valid!

‘abc’ ERROR due to more than two characters

TEST: MOV RL0, # ‘A’


SUB RL0, # ‘0’

TABLE: DB ‘ENTER ANY KEY TO CONTINUE’ , 0

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

SECTION: most user defined symbols belong to some section. A section


is a segment in memory containing executable code ,
constants or variables.

SCOPE: is the visibility: local to module, global, public or external


constants and relocatable symbols.

VALUE: This is the numeric value or offset the symbol represents.

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.

Once a symbol has been defined it can be used as a numeric operand in


expressions similar to the way a numerical constant is used.

Symbol names must adhere to the following conventions:

„ maximum of 31 characters in length


„ first character must be one of ‘A’-‘Z’, ‘a’-‘z’, ‘_’, or ‘?’
„ subsequent characters must be one of ‘A’-‘Z’, ‘a’-‘z’, ‘_’, ‘?’, or ‘0’-‘9’

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.

The following are examples of the use of labels:


LABEL2: ; a comment line with a label
COPY: MOVB [R1],RL4
16 Chapter 2. Operands and Expressions

Special Assembly Symbols


Some symbols are predefined and are to be treated as reserved words. They
usually refer to names of the processor registers:

R0 - R15: general purpose registers (GPR)

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.

The following examples show the use of the $ address counter:


MSG: DB LEN, 'THIS IS A MESSAGE',0
LEN EQU $ - MSG - 1

HALT: JMP $: ; jump to 'HALT'


TABLE: DW $, $, $, $ ;

Expressions, which contain variables or labels defined in relocatable sections


cannot be evaluated at assembly time, since the final address of these symbols is
not known. The address evaluation is performed by the linker/locator L166.

Relocatable symbols are:

„ 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.

Example 1, external constants:


EXTRN XVAL : DATA4: ; an external 4-bit constant
EXTRN YVAL : DATA8: ; an external 8-bit constant

Example 2, group name using sections from example 3:


DGR DGROUP D100, D200 ; group consists of section D100 and D200
2
Example 3, section names:
D100 SECTION DATA ; relocatable data section
V1 DSW 1 ; reserve one word
V2 DSB 1 ; reserve one byte
D100 ENDS ; end of data section

D200 SECTION DATA


SBASE DW D100 ; init word with base of sect. D100
GBASE DW DGR ; init word with base of group 'DGR'
D200 ENDS

MOV R5,#DGR ; DGR is relocatable


MOV R4,#V2-V1 ; V2-V2 is absolute (2)
MOV R1,#XVAL ; use external constant (data4 short form)
MOV R3,#4 * 8 ; absolute expression

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.

Priority Operator Example Meaning


0 () (2+8)*12 Change Order Of Evaluation
1 . SYSCON.3 Bit Position Separator
2 BIT PTR BIT PTR xbit Type Override
2 BYTE PTR BYTE PTR wvar Type Override
2 WORD PTR WORD PTR bvar Type Override
2 NEAR PTR NEAR PTR flab Type Override (Near/Far)
2 FAR PTR FAR PTR nlab Type Override (Near/Far)
2 DATA3 DATA3 2 Use 3-Bit Constant (0-7)
2 DATA4 DATA4 8 Use 4-Bit Constant (0-15)
18 Chapter 2. Operands and Expressions

Priority Operator Example Meaning


2 DATA8 DATA8 25 Use 8-Bit Constant (0-255)
2 DATA16 DATA16 100 Use 16-Bit Constant (0-65535)
2 DPP0-DPP3 DPP2:var Data Page Pointer Override
2 SEG SEG var Get Segment Number (64K Segments)
2 PAG PAG var Get Page Number (16K Pages)
2 SOF SOF var Get Segment Offset Of ‘Var’

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

Addition and Subtraction


Addition and subtraction may be used on absolute and relocatable operands.
Together with the operators HIGH and LOW and the relational operators, this are
the only operators which can be used to operate on absolute and relocatable
operands, all other operators require absolute operands. The table below shows
valid operand combinations (ABS=absolute, REL=relocatable).

Syntax: operand + operand


operand - operand:
166/167 Assembler and Utilities 19

Operand ± Operand Result


ABS + ABS ABS
ABS - ABS ABS
ABS + REL REL
ABS - REL *** ERROR ***
REL + ABS REL
REL - ABS REL
REL + REL
REL - REL
*** ERROR ***
ABS
2
The operation ‘REL-REL’ is allowed for relocatable operands only when both
operands are defined in the same parent-section, external operands are not
allowed. In this case the result is absolute, because the address difference is known
at assembly time and can never change.

As a general rule, relocatable expressions must evaluate to a relocatable symbol


plus or minus an optional constant value (displacement).

Multiplication, Division, Modulo


These operators perform the usual well known operations and require absolute
operands.

Syntax: operand * operand ; multiplication


operand / operand ; division
operand MOD operand ; discard quotient, result = remainder

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.

Syntax: operand SHR operand -or- operand >> operand

2 operand SHL operand -or- operand << operand

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.

Syntax: operand EQ operand ; equal


operand == operand ; same as EQ
operand NE operand ; not equal
operand != operand ; same as NE
operand LT operand ; lower than
operand < operand ; same as LT
operand LE operand ; lower than or equal
operand <= operand ; same as LE
operand GT operand ; greater than
operand >= operand ; same as GT
operand ULT operand ; unsigned lower than
operand ULE operand ; unsigned lower than or equal
operand UGT operand ; unsigned greater than
operand UGE operand ; unsigned greater than or equal

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.

Syntax: NOT operand ; bitwise not


operand AND operand ; bitwise and
operand & operand ; same as AND
operand OR operand ; bitwise OR
operand | operand ; same as OR
166/167 Assembler and Utilities 21

operand XOR operand ; bitwise XOR


operand ^ operand ; same as XOR

HIGH and LOW


HIGH returns the high byte of its operand, LOW returns the low byte of its
operand (a 16-bit operand is assumed). The operand must be either absolute or a
constant defined as ‘ extern <e_con>:DATAn’. Relocatable operands of other 2
types are not allowed.

Syntax: HIGH operand ; HIGH 1234H --> 12H


LOW operand ; LOW 1234H --> 34H

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

BCLR BW0.3 ; valid bitaddress


BCLR BW1.15 ; external bitword in bitaddress
BCLR 0FD00H.15 ;
22 Chapter 2. Operands and Expressions

Page Override Operator


Syntax: DPPn:operand ; DPP0,DPP1,DPP2,DPP3

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

D100 SECTION DATA


V1 DSW 1
V2 DSW 1
D100 ENDS

C100 SECTION CODE


MOV DPP2,#D100 ; establish data page addressability
NOP ; pipeline delay
MOV R10,V1 ; DPP2:V1 used per ASSUME

MOV DPP1,#D100 ; set up DPP1 for later override


NOP
MOV R13,DPP1:V2 ; addressing per DPP1; undergoing ASSUME
C100 ENDS

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.

‘type’ can be one the following types:

„ 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

C100 SECTION CODE


CALL FAR PTR XPROC ; override type near by far
MOV RL0,BYTE PTR V2
MOV R15,WORD B1
MOV [R1],200 ; type of move unsure
MOV [R1],BYTE 200 ; byte move
MOV [R1],WORD 200 ; word move
C100 ENDS

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:

DATA3 3-bit: values in range 0 to 7


DATA4 4-bit: values in range 0 to 15
DATA8 8-bit: values in range 0 to 255
DATA16 16-bit: values in range 0 to 65535

When A166 encounters an immediate expression using just a constant, it must


make an assumption about the type based on the value of the constant. Assemblers
from other vendors use the DATAn operator to resolve the type in case of forward
24 Chapter 2. Operands and Expressions

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:

1 C100 SECTION CODE


2 P100 PROC NEAR
0000 E000 3 MOV R0,#SEG SYSCON ; result:0
0002 E001 R 4 MOV R1,#SEG P100 ; relocatable
0004 E022 5 MOV R2,#SEG 22000H ; result:2
6 P100 ENDP
7 C100 ENDS

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

0010 E6F20800 11 MOV R2,#PAG 22000H ; result: 8


0014 E082 12 MOV R2,#DATA4 (PAG 22000H) ; result: 8
13 P100 ENDP
14 C100 ENDS
15 END

SOF Operator

2 Syntax: SOF operand

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

Chapter 3. Assembler Directives


Assembler directives are used to control the assembly process rather than being
translated into 166/167 machine code. The A166 assembler offers various
directives, which serve the following purposes:

„ definition of SECTIONS (SECTION)


„ definition of GROUPS (GROUP)
„ DPPn-tracking (ASSUME)
„ internal resource reservation (REGDEF, SSKDEF, PECDEF)
„
„
definition of symbols (BIT, EQU, SET, LIT)
memory space reservation (DS, DSW, DSB, DBIT)
3
„ memory space initialization (DB, DW, DBPTR, DSPTR, DPPTR)
„ program linkage (EXTERN, PUBLIC, GLOBAL, NAME)
„ assembler state control (ORG, END)

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.

The 166/167 CPU addresses up to 16MB of memory. The memory map is


divided into segments of 64KB each. Accessing memory locations requires an 18-
bit physical address which is composed of the following:

CODE Address: Segment number for 166/167 (8 bits, 0 to 256),


offset (16 bits, 0 to 65535)

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.

Syntax: name SECTION sectype [align-type] [combine-type] [‘class-


name’]
data definitions or code
name ENDS

Description of fields:

name is the name of the section. The name must be an unique


identifier.

sectype is CODE, DATA or BIT.

CODE sections will be mapped to physical segments. If the


CPU operates in non-segmented mode, a total of 64KB (0 to
0FFFFH) can be addressed. In segmented mode, sections of
type CODE can be located anywhere in the 166/167 address
space.

DATA sections are mapped to physical 16KB pages. In non-


segmented mode this page will be within the first 64Kbyte
segment, otherwise a page may be located anywhere within
the 166/167 address space.

BIT sections will be mapped into the bit-addressable space


located in on-chip RAM at addresses 0FD00H to 0FDFFH.
The location counter is advanced in units of bits.
166/167 Assembler and Utilities 33

align-type The alignment type field specifies the boundaries of sections


which must be observed and handled by the linker when
combining or locating sections. The align-type must be one
of the following:

no alignment type given; the default alignment derived from


section type is used (BIT for bit-sections, WORD for code,
data and bit-addressable data sections.

BIT the section will be combined or located at a bit


boundary. This allows combination of bit sections with no
intervening gaps.

BYTE the section will be combined or located at a byte


boundary. Sections which contain word variables or code
3
may not receive byte alignment, since word accesses must be
at even addresses, otherwise an execution trap will occur
since byte alignment may lead to accesses from odd word
addresses.

WORD the section will be forced to an even address.

DWORD the section will start at an address divisible by 4


without remainder.

PAGE the section will start at a 16K page boundary.

SEGMENT the section will start at a 64K segment


boundary.

BITADDRESSABLE implies WORD alignment, sections


start on an even word address in bit-addressable RAM
contained in the CPU at address 0FD00H to 0FDFEH.

PECADDRESSABLE implies WORD alignment, sections


start at an even address in internal RAM at address 0FDE0H
to 0FDFEH.
34 Chapter 3. Assembler Directives

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:

PRIVATE or combine type omitted; the section receives


the attribute non-combinable. This is true only for sections
contained in different modules. Sections within one module
are still combined to one section.

PUBLIC all sections having the same name will be

3 combined to one section. The length of the combined section


will be the sum of the lengths of the sections being combined.

GLOBAL has the same semantic as PUBLIC, but by-passes


the TRGOUP level. TGROUPS are individual program units.
Public makes sections or symbols visible one TGROUP unit.
Global makes sections or symbols visible for the whole
application (beyond TGROUP units).

COMMON all sections having the same name with the


attribute COMMON are overlapped in memory to form one
section. All combined sections start at the same memory
address. The length of the combined section is equal to the
length of the largest section combined.

SYSSTACK all sections of the same name are combined to


one section by adding the sections. The final section will be
placed in on-chip RAM by L166 and is used for the system
stack. The system stack is accessed via the stack pointer SP
with the instructions CALL, PUSH, POP and SCXT. Due to
the limited size of the system stack, automatic variables from
C are placed on the user stack.

USRSTACK the same combination semantics are used as


with SYSSTACK. The difference is that the final section is
placed somewhere in memory and is addressed using the
DPPn:offset method. This kind of stack is normally used for
local (stack based) variables in high level languages. The
user stack can have a total length of 16K.
166/167 Assembler and Utilities 35

GLBUSRSTACK the same semantics as with USRSTACK


are used. The difference to USRSTACK is that sections are
combined on a system wide base which is beyond TGROUPS
units.

AT expression the section is placed at an absolute address


specified by expression in memory. The expression must
evaluate to a constant value with no forward references. The
details on the absolute address depend on the section-type and
align-type. A bit-addressable data section, for example, must
be placed at appropriate addresses in internal RAM. The AT
attribute implies a non-combinable section. The assembler
checks the expression for consistence with the sectype and
align-type and the CPU mode segmented or non-segmented. 3
class-name is used to specify all sections with the same class name at
link/locate level. The idea is to place this sections in general
memory areas, for example to place sections containing
constants and others containing code into PROM area. The
class name must be an unique identifier.

Example:
C100 SECTION CODE ‘INITROM’
C100 ENDS

Multiple Section Definition

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

12 ; V1 DSW 1 ; reserve one word of storage


13 ; V2 DSW 1 ; reserve one word of storage
14 ;D100 ENDS
15
16 ; the following is an error because of align-type
redefinition:
17
18 D100 SECTION DATA WORD
*** _________________________________^
*** ERROR #31, LINE #18, REDEFINITION: 'ALIGN TYPE'
0008 19 V3 DSW 1 ; reserve one word of storage
20 D100 ENDS
21
22 END

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.

Syntax: group-name CGROUP section-name [, section-name [, …]]


group-name DGROUP section-name [, section-name [, …]]

Description of fields:
3
group-name is the name of the group. The name must be an unique
identifier.

CGROUP / DGROUP specifies whether a code or data


group is to be defined. In case of code groups, only code
sections can be member of. The total size of a code group
may not exceed 64KB. A data group can have only data
sections as associated members. The total size of a data
group may exceed 16KB. The order of sections in a group
derived from the section name list is not necessarily the same
after linking and locating since the order may be changed at
link time. A group is located as one logical unit to one
physical segment or page.

section-name one or more section names, separated by comma. If one


member of a group is an absolute section, then the group
becomes absolute as well. In this case the order of the
sections highly depends on the absolute section. A data group
may contain the dummy section ‘SYSTEM’. SYSTEM
covers the internal special function register area. Since
SFR’s are not defined using ordinary section directives, the
SYSTEM section serves as a placeholder for the SFR area.
SYSTEM specifies an absolute section within page 3.
38 Chapter 3. Assembler Directives

Example of group definitions:


1 $SEGMENTED
2
3 GDATA DGROUP D100, D200
4 GCODE CGROUP C100
5 ASSUME DPP2 : GDATA
6
7 D100 SECTION DATA
0000 8 V1 DSW 1
9 D100 ENDS
10
11 D200 SECTION DATA
0000 12 V2 DSW 1
13 D200 ENDS
14
15 C100 SECTION CODE PUBLIC 'ROM1'
16 P100 PROC NEAR
0000 E6020000 R 17 MOV DPP2,#GDATA ; load group base page

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:

„ a page number of a 16KB page which is referred.


„ an 14 bit offset into the target page.

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

Syntax: ASSUME DPPn: section name


ASSUME DPPn: SYSTEM
ASSUME DPPn: group name
ASSUME DPPn: variable or label name
ASSUME DPPn: NOTHING

Description of fields:

DPPn: is one of DPP0, DPP1, DPP2 or DPP3

section-name all references to variables of the given section will use the
given data page pointer.

SYSTEM is a dummy section which encloses the special function


register (SFR) area within the internal RAM of the CPU.
3
SFR’s are normally predefined within the assembler and are
never defined using ‘normal’ sections. Since the accesses to
SFR’s also use the data page mechanism, they also require an
associated DPP for correct accesses.

Without having the SYSTEM dummy section, it would not


be possible to have one DPP representing the base of some
data section contained in internal RAM and the SFR area
(both physically located in the same page-3), since one DPP
can hold only one base at a time.

group name all references to variables of sections which are members of


the named group will use the given data page pointer.

variable or label name


the parent section of the given variable or label is derived.

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

MOV R15,DPP1 : V1; use DPP1 to access variable 'V1'

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.

Syntax: regbankname REGBANK [register range][, …]


[regbankname] REGDEF register range [, …]

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.

Syntax: PECDEF channel-range [,channel-range [, …]]

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.

Syntax: SSKDEF stack-size-number

The stack-size-number is a value in range 0 to 7. This number corresponds to the


system stack size as follows:
NUMBER SIZE STACK ADDRESS
0 256 words 0FA00H to 0FBFFH
1 128 words 0FB00H to 0FBFFH
2 64 words 0FB80H to 0FBFFH
3 32 words 0FBC0H to 0FBFFH
4 512 words 0FBFEH to 0F800H
5 Reserved, do not use this value
6 Reserved, do not use this value
7 No limited, the whole on-chip RAM can be used as stack

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,

RETS return from far procedure


3
RETI return from interrupt procedure

RET return from near procedure

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.

Syntax: name PROC [type]


name ENDP

name PROC TASK [taskname] [INTNO [intname][= intno]]


name ENDP

name PROC INTERRUPT intname = intno USING rbank


name ENDP

Description of fields:

name Is the name of the procedure.

type Specifies the type of the procedure, it may receive one of the
following values:

none specified: The type defaults to near regardless of the


selected CPU mode segmented or non-segmented.
44 Chapter 3. Assembler Directives

NEAR: Defines a type near procedure.


FAR: Defines a type far procedure.

With this information, the assembler can automatically


generate the appropriate CALL and RET instructions. Any
RET instruction within PROC and ENDP will be converted
to the correct return instruction.

TASK Defines a TGROUP with name taskname if one follows.


Otherwise an unnamed task is created. A task is a functional
unit consisting of one or more modules. The entry point to
the task unit is the task procedure, the exit point from the task

3 is a RETI instruction also contained in the task procedure. A


task can be viewed as a functional unit which is activated by
a software or hardware trap which causes an interrupt and
then a branch to the task procedure using an entry in the
interrupt vector table.

taskname the TGROUP name; defines the name of the


TGROUP represented by this interrupt procedure and must
be a unique identifier. The taskname and if specified the
intname and its value are GLOBAL symbols.

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.

INTNO The task procedure currently being defined can receive an


absolute or a symbolic interrupt number depending on what
follows INTNO.

INTERRUPT Defines an interrupt procedure which can receive an absolute


or a symbolic interrupt number depending on what follows.

intname must be a unique identifier that defines a symbolic


name for the interrupt of the task procedure currently being
defined. If no assignment of a constant value follows, then
the interrupt or vector number is relocatable and can be
supplied at link/locate time. The symbolic trap number
serves the purpose to activate tasks by means of trap
166/167 Assembler and Utilities 45

instructions, which must have a trap number as its operand.


The trap name is known automatically, system wide.

intno must be a numeric expression which evaluates to a


constant value in range 0 to 127. It represents the interrupt
number of the specified interrupt procedure. If intname is
given, then intno is assigned to intname.

USING Defines the register bank used for the interrupt procedure.

rbank must be the name of a register bank which is defined


previously with the REGBANK directive.

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:

„ A register name like R10, RL2, or RH1.


3 „ The name of a special function register.
„ A constant value.
„ An identifier.
„ An expression having a prefix (PAG,POF,SEG,SOF).

The expression must not have forward references. All identifiers used in the
expression must have been previously defined.

If an EQU symbol is to be made PUBLIC or GLOBAL, the expression must


evaluate to a constant. The public and global directives are able to export a name
and a value. They are not able to export fix-up methods such as those generated
by PAG, SOF, or names of registers.

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

1 D100 SECTION DATA


0000 2 V1 DSW 1
0002 3 V2 DSW 1
4 D100 ENDS
5
6 VAR1 EQU V1
7 X15 EQU R15
8 X3 EQU R3
9 X4 EQU SYSCON
10 XL3 EQU RL3
11 CON1 EQU 3
12
13 C100 SECTION CODE
14 P100 PROC NEAR
0000 E136 15 MOV RL3,#CON1
166/167 Assembler and Utilities 47

0002 E136 16 MOV XL3,#CON1 ; same as instr. before


0004 F6FF0000 R 17 MOV V1,R15
0008 F6FF0000 R 18 MOV VAR1,X15 ; same as instr. before
000C F6F30CFF 19 MOV X4,X3 ; syscon,R3
0010 CB00 20 RET
21 P100 ENDP
22 C100 ENDS
23 END

SYMBOL TABLE LISTING


------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

C100 . . . . . . . ---- ---- SECTION


CON1 . . . . . . . DATA3 0003H A
D100 . . . . . . . ---- ---- SECTION
P100 . . . . . . . NEAR 0000H R SEC=C100
SYSCON . . . . . . WORD FF0CH A SFR
V1 . . . . . . . . WORD 0000H R SEC=D100
V2 . .
VAR1 .
X4 . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
WORD
WORD
WORD
0002H
0000H
FF0CH
R
R
A
SEC=D100
SEC=D100
SFR
3
SET
Syntax: name SET expression

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

1 D100 SECTION DATA


0000 2 V1 DSW 1
0002 3 V2 DSW 1
4 D100 ENDS
5
6 VAR1 SET V1
7 X4 SET SYSCON
8 CON1 SET 3
9
10 C100 SECTION CODE
48 Chapter 3. Assembler Directives

11 P100 PROC NEAR


0000 F2FF0000 R 12 MOV R15,V1
0004 F2FF0000 R 13 MOV R15,VAR1 ; same as instr. before
0008 E136 14 MOV RL3,#CON1 ; CON1 = 3
15
CON1 SET CON1 + 16 ; CON1 = 19
000A E7F61300 16 MOV RL3,#CON1 ; gens long instr. form
000E CB00 17 RET
18 P100 ENDP
19 C100 ENDS
20 END

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

„ absolute addresses in range 0FD20H-0FDFEH, example: 0FD10H.7


„ system-bit, examples: DP3.13, P2.15, PSW.1. The result is an absolute bit
since SFR-names (system-names) are absolute. (The same function is
performed by the DEFB directive which is included for compatibility to other
166/167 assemblers.)
„ bits based on words contained in bit-addressable data sections. This results in
relocatable bits, if the bit-addressable data section is relocatable.

Example:
LOC OBJ LINE SOURCE

1 D100 SECTION DATA BITADDRESSABLE


0000 2 V2 DSW 1
3 D100 ENDS
4
5 BIT1 BIT V2.7 ; relocatable word base
6 BIT2 BIT V2.14 ; relocatable word base
7 BIT3 BIT DP3.13 ; absolute system bit
8 BIT4 BIT PSW.1 ; Carry
9 BIT5 BIT 0FD10H.4 ; absolute bit
10 BIT6 BIT P3.13 ; ENABLE WR/ OUTPUT
11
12 C100 SECTION CODE
13 P100 PROC NEAR
0000 7F00 R 14 BSET BIT1
0002 EF00 R 15 BSET BIT2
0004 DFE3 16 BSET BIT3
0006 1F88 17 BSET BIT4
0008 4F08 18 BSET BIT5
166/167 Assembler and Utilities 49

000A DFE2 19 BSET BIT6


000C CB00 20 RET
21 P100 ENDP
22 C100 ENDS
23 END

SYMBOL TABLE LISTING


------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

BIT1 . . . . . . . BIT 00H.7 R SEC=D100 BASE=V2


BIT2 . . . . . . . BIT 00H.14 R SEC=D100 BASE=V2
BIT3 . . . . . . . BIT E3H.13 A
BIT4 . . . . . . . BIT 88H.1 A
BIT5 . . . . . . . BIT 08H.4 A
BIT6 . . . . . . . BIT E2H.13 A
C100 . . . . . . . ---- ---- SECTION
D100 . . . . . . . ---- ---- SECTION
DP3. . . . . . . . WORD FFC6H A SFR
P100
P3 .
PSW.
V2 .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
NEAR
WORD
WORD
WORD
0000H
FFC4H
FF10H
0000H
R
A
A
R
SEC=C100
SFR
SFR
SEC=D100
3
LABEL
Syntax: name[:] LABEL [type]

A label is a symbolic name for a particular location in that section, in which it is


defined. The label name can be followed by a colon, but it is not required. The
label inherits the attributes of the parent section; a label may therefore never be
defined outside of a section.

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.

The type is optional and can be one of the following:

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

1 D100 SECTION DATA


2 XWORD LABEL WORD
0000 34 3 VB1 DB 34H
0001 12 4 VB2 DB 12H
5 D100 ENDS
6

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

DEFR / DEFA / DEFB


Syntax: name DEFR sfr-address [, attribute]
name DEFA on-chip-RAM-address [, attribute]
name DEFB bit-address [, attribute]

These directives define SFR names (DEFR), names for absolute internal RAM
addresses (DEFA) and bit-addresses (DEFB). The optional attribute can be:

R read only access allowed


W write only access allowed
RW read/write access allowed (default)
166/167 Assembler and Utilities 51

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:

„ use the primary control $NOMOD166 to eliminate predefined system names.


„ create a file which contains the system names and bits using DEFR and
DEFB.
„ use the general control $INCLUDE (filename) to include the file with the
new definitions into the assembler.

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:

DEFR the sfr-address must be an even constant value in range


0FE00H to 0FFDEH or 0F000H to 0F1DEH. This address
range specifies the Special-Function-Register area of the
166/167. The range 0F000H to 0F1DEH can only be used if
the MOD167 control directive is specified.

DEFA the on-chip-RAM-address must be an even constant value in


range 0FA00H to 0FDFEH. This address range specifies the
internal data RAM area of the 166/167 CPU.

DEFB the bit-address must be a bit address, written as


‘base.bitpos’. Base must be some bit-addressable word,
bitpos must be a constant in range 0 to 15. It is the users
responsibility to make sure, that the base address containing
some bit is really bit-addressable. Please note, that not all
SFR addresses are bit-addressable.

Examples:
LOC OBJ LINE SOURCE

1 CONFIG DEFR 0FF0CH,RW ; SysCon SFR


2 ZREG DEFR 0FF1CH,R ; Zeroes SFR, read
only
3 XFA00 DEFA 0FA00H ; RAM address 0FFA0H
4 P0P1 DEFB 0FF00H.1 ; Bit, Port0.1
5 BZ0 DEFB ZREG.0 ; Bit, Zeroes.0
6 ODDREG DEFR 0FF1DH ; ERROR: odd address
*** __________________________________________^
*** ERROR #101, LINE #6, INVALID SYSTEM ADDRESS
7 XBIT DEFB CONFIG.3
52 Chapter 3. Assembler Directives

8 P0P2 BIT P0.2


9 END

SYMBOL TABLE LISTING


------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

BZ0. . . . . . . . BIT 8EH.0 A


CONFIG . . . . . . WORD FF0CH A SFR
ODDREG . . . . . . WORD FE00H A SFR
P0 . . . . . . . . WORD FF00H A SFR
P0P1 . . . . . . . BIT 80H.1 A
P0P2 . . . . . . . BIT 80H.2 A
XBIT . . . . . . . BIT 86H.3 A
XFA00. . . . . . . WORD FA00H A
ZREG . . . . . . . WORD FF1CH A SFR

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.

Example, source text containing literal names before assembly:


REG1 LIT 'R1'
REG1H LIT 'RH1'
REG1L LIT 'RL1'
BCAST LIT "BYTE PTR"
WCAST LIT "WORD PTR"

D100 SECTION DATA


BVAR DSB 10
D100 ENDS

C100 SECTION CODE


P100 PROC NEAR
MOV REG1L,BVAR
MOV REG1,WCAST BVAR
LAB{REG1}:
JMP LAB{REG1}
RET
P100 ENDP
C100 ENDS
END
166/167 Assembler and Utilities 53

Assembler listing from previous example:

1 REG1 LIT 'R1'


2 REG1H LIT 'RH1'
3 REG1L LIT 'RL1'
4 BCAST LIT "BYTE PTR"
5 WCAST LIT "WORD PTR"
6
7 D100 SECTION DATA
0000 8 BVAR DSB 10
9 D100 ENDS
10
11 C100 SECTION CODE
12 P100 PROC NEAR
0000 F3F20000 R 13 MOV RL1,BVAR
0004 F2F10000 R 14 MOV R1,WORD PTR BVAR

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 [, …]]

TYPEDEC is be used to define a type for a symbol. It is normally used to give


forward referenced symbols a 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

1 D_ABS SECTION DATA AT 4000H


0000 2 V1 DSW 1

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

1 D_ABS SECTION DATA PUBLIC 'DRAM'


0000 2 V1 DSB 1
0001 3 V2 DSW 1 ; Warning because of odd
offset
*** WARNING #48, LINE #3, INSUFFICIENT ALIGNMENT
0003 4 V3 DSB 1
0004 5 EVEN
0004 6 V4 DSW 1
7 D_ABS ENDS
8
9 D_BIT SECTION DATA BITADDRESSABLE
166/167 Assembler and Utilities 55

0000 10 WRD1 DSW 1


0002 11 BRD1 DSB 1
0004 12 EVEN
0004 13 WRD2 DSW 1
14 D_BIT ENDS
15
16 END

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.

„ name is the name of the external symbol.


„ type specifies one of the following possible types:
BIT a single bit
BYTE a byte variable
WORD a word variable
BITWORD a bit-addressable word
NEAR a near label
FAR a far label
DATA3 a 3-bit constant
DATA4 a 4-bit constant
DATA8 an 8-bit constant
DATA16 a 16-bit constant
INTNO a symbolic interrupt number (7-bit)
REGBANK a register bank name
56 Chapter 3. Assembler Directives

External symbols may be also defined inside a section. An ASSUME to this


section (necessary in segmented mode) forces externals of type BYTE, WORD
and BITWORD to inherit the DPP usage of the parent section in the same way as
usual variables. The advantage here is that the programmer has not to care about
the DPP which will hold the base page number at runtime. The only assumption is
the corresponding PUBLIC or GLOBAL variables are defined in a consistent
manner:
Module 1: $SEGMENTED
ASSUME DPP2 : DSEC
PUBLIC VAR1, VAR2
DSEC SECTION DATA PUBLIC
VAR1 DSW1
VAR2 DSB1

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

001C C2F20000 E 27 MOVBZ R2,ExtB1 ; use DPP2 per ASSUME


0020 0012 28 ADD R1,R2
0022 F6F10000 R 29 MOV LOCV,R1 ; use DPP2 for 'LOCV'
30 MOV R8,yvar ; Error: DPP not
known!
*** ________________________________________^
*** ERROR #77, LINE #30, MISSING 'DPP' INFORMATION
002A F2F80000 E 31 MOV R8,DPP1:yvar ; ok...
32 ; hard to maintain !
002E DB00 33 RET
34 P100 ENDP
35 C100 ENDS
36 END

SYMBOL TABLE LISTING


------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

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.

The following type of symbols can be made PUBLIC or GLOBAL:

„ variables (BYTE, WORD, BIT, BITWORD)


„ labels (NEAR, FAR)
„ constants defined using the EQU directive (DATA3, DATA4, DATA8,
DATA16).
58 Chapter 3. Assembler Directives

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

13 C100 SECTION CODE


14 P100 PROC FAR
0000 C6080000 R 15 SCXT CP,#RB1
0004 4A000000 R 16 MOV BIT1,BIT0
0008 E17F 17 MOV RH7,#CON3
000A DB00 18 RET
19 P100 ENDP
20 C100 ENDS
21 END

SYMBOL TABLE LISTING


------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

BIT0 . . . . . . . BIT 00H.0 R PUB SEC=BSEC


BIT1 . . . . . . . BIT 00H.1 R PUB SEC=BSEC
BSEC . . . . . . . ---- ---- SECTION
C100 . . . . . . . ---- ---- SECTION
CON3 . . . . . . . DATA3 0007H A
CP . . . . . . . . WORD FE10H A SFR
P100 . . . . . . . FAR 0000H R PUB SEC=C100
RB1. . . . . . . . ---- ---- PUB REGBANK
166/167 Assembler and Utilities 59

Defining and Initializing Variables


Syntax: [name[:]] DB init [, init] [, …]
[name[:]] DW init [, init] [, …]
[name[:]] DBIT [expression]
[name[:]] DS expression
[name[:]] DSB expression
[name[:]] DSW expression

This directives allow to reserve or initialize memory. The colon may optionally
follow the name.

The meaning of the various directives is as follows:


3
DB Define Byte; initialize 1 byte in memory. If init is a string of
characters, the characters are stored each in one byte adjacent
to another. A string can be approximately 500 characters in
length (the maximum length of an input line to the assembler
is 510 characters). The DB directive can be used in data or
code sections, it is not allowed in bit sections.

DW Define Word; initialize 1 word in memory. The offset in the


current section must be even (word alignment), otherwise a
warning occurs. The offset can be aligned with the EVEN
directive. The DW directive cannot be used within bit
sections.

DBIT Define BIT; reserve one or more bits in memory. DBIT is


allowed only within bit sections. If the optional expression is
present, the number of bits given by the expression are
reserved, otherwise only one bit is reserved. The expression
must evaluate to a constant value with no forward references.
Initialization of bits is not possible.

Examples:
bit1: DBIT ; reserve one bit
bit2: DBIT 10 ; reserve ten bits
bit3 DBIT 1 ; reserve one bit

DS Define Storage; reserves as many bytes of memory as


specified by the expression, the memory is not initialized. If
the current section is of the type BIT, the specified number of
60 Chapter 3. Assembler Directives

bits are reserved. DS is allowed in any type of section. A


preceding name receives type BYTE.

DSB Define Storage Byte; same as DS with the exception that


DSB cannot be used within sections of type BIT.

DSW Define Storage Word; reserves as many words of memory as


specified by the expression, the memory is not initialized.
DSW may not be used within sections of the type BIT.

Different init expressions are possible depending on the directive used:

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

D100 SECTION DATA


v1
v2
v3:
DW
DW
DW
DPP3
DPP2
DPP1
:
:
:
POF
POF
POF
symbol
symbol
symbol
3
v4: DW DPP0 : POF symbol
symbol: dw -3
D100 ENDS

C100 SECTION CODE


SCXT DPP3,#PAG D100
MOV R15,-4
MOV R8,v1 ; load DPP1:v1
MOV [R8],R15 ; store -4 to 'symbol'
POP DPP3
C100 ENDS

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

Defining and Initializing Pointers


Syntax: [name[:]] DSPTR init [, init] [, …]
[name[:]] DPPTR init [, init] [, …]
[name[:]] DBPTR init [, init] [, …]

Pointers are memory units which contain complete physical addresses of variables
or labels. The meaning of the above directives is as follows:

DSPTR: performs segment pointer initialization. DSPTR is used to


create pointers which refer to label or procedure names, in
3 other words: items which are members of code sections. For
the 167 also data pointers can be created, when the object is
accessed using the EXTS instruction. The pointer created
consists of two words. The first word contains the segment
relative offset of the reference symbol. The offset can have
values in range 0 to 65535. The second word contains the
physical segment number of the 64K segment, which the
reference symbol is member of. The value is in range 0 to
255.

DPPTR: performs page pointer initialization. DPPTR is used to create


pointers which refer to variables, which are members of data
sections. The pointer created consists of two words. The
first word contains the page relative offset of the reference
symbol. The offset can have values in range 0 to 16383. The
second word contains the physical page number of the 16K
page, which the reference symbol is member of. The value is
in range 0 to 1023.

DBPTR: performs a bit pointer initialization. DBPTR can be used to


create pointers which refer to members of bit sections or bits
which are based on bit-addressable words. A bit-pointer
consists of three words. The first word contains the bit
position (range: 0 to 15), the second word contains the page
offset of the bit-addressable word (range: 0 to 0DFFH) and
the third word contains the physical page number which is
always 3.
166/167 Assembler and Utilities 63

Examples:
LOC OBJ LINE SOURCE

1 EXTERN NPROC : NEAR


2
3 BSEC SECTION BIT
0000 4 BT1 DBIT
0001 5 BT2 DBIT
6 BSEC ENDS
7
8 DSEC SECTION DATA
0000 00000000 R 9 bp1 DBPTR BT1 ; Bit pointer ref. BT1
0000 0300
0006 00000000 R 10 bp2 DBPTR BT2 ; Bit pointer ref. BT2
0006 0300
000C 00000000 R 11 pd1 DPPTR bp1 ; Page pointer
0010 00000000 E 12 cp1 DSPTR NPROC ; Segment pointer
13 DSEC ENDS

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

Chapter 4. Invocation and Controls


This part explains how to use A166 to assemble 166/167 assembly source files
and discusses the assembler controls that may be specified on the command line
and within the source file.

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:

A166 sourcefile † controls… ‡

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)

A166 displays the following information upon successful invocation and


assembly.
DOS MACRO ASSEMBLER A166 V3.00
COPYRIGHT KEIL ELEKTRONIK GmbH 1992 - 1996

ASSEMBLY COMPLETE, NO ERRORS FOUND


66 Chapter 4. Invocation and Controls

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.

File Extension Description


basename.LST Files with this extension are listing files that contain the formatted source text
along with any errors detected by the assembler. Listing files may optionally
contain symbols used and the generated assembly code. Refer to “PRINT /
NOPRINT” on page 89 for more information.
basename.OBJ Files with this extension are object modules that contain relocatable object
code. Object modules can be linked into an absolute object module by the
L166 Linker/Locator. Refer to “OBJECT / NOOBJECT” on page 85 for more
information.

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

Name / Abbreviation Meaning


NOSYMLIST,NO SL ‡ Do not list the following symbol definitions in the symbol table.
OBJECT[(file)] / OJ Designate file to receive object code.
PAGELENGTH(n) / PL Sets maximum number of lines in each page of listing file.
PAGEWIDTH(n) / PW Sets maximum number of characters in each line of listing file.
PRINT[(file)] / PR Designates file to receive source listing.
NOPRINT / NOPR Designates that no listing file will be created.
REGUSE ‡ Defines register usage of assembler functions for the C optimizer.
RESTORE / RS ‡ Restores control setting from SAVE stack.
SAVE / SA ‡ Stores current control setting for GEN, LIST and SYMLIST.
SEGMENTED, SG / Define the mode of CPU operation.
NONSEGMENTED, NOSG
USEDEXTONLY / UEO Prevent A166 from generating external definitions for unused external
identifiers.
TABS(n) / TA Specifies the tab setting.
TITLE(string) / TT Places a string in all subsequent page headers.
TYPE, TY / NOTYPE, NOTY Defines whether type information is included in object file or not.
XREF / XR Creates a cross reference listing of all symbols used in program.
‡ — General controls
4
NOTE
Some controls like EJECT and SAVE cannot be specified on the command line.
The syntax for each control is the same when specified on the command line or
when specified within the source file. A166 will generate a fatal error for
controls that are improperly specified.
70 Chapter 4. Invocation and Controls

ABSOLUTE
Name: ABSOLUTE

Control-type: Primary

Abbreviation: AB, NOAB

Arguments: None

Default: None

µVision Control: Options—A166 Assembler—Object—Check for Absolute


Module

Definition: checks whether an assembled module is absolute or contains


relocatable references. The module is not absolute, if external

4 symbols are defined or if one section is defined without AT


expression. AT expression forces sections to be absolute.
An absolute module may be directly loaded without having it
processed by L166. If ABSOLUTE is in effect and the
module has relocatable references, then a warning is given at
the end of the module:

*** WARNING #105, LINE #nn, $ABSOLUTE: NOT AN ABSOLUTE MODULE

Example:
$ABSOLUTE
A166 SAMPLE.A66 ABSOLUTE
166/167 Assembler and Utilities 71

CASE / NOCASE
Name: CASE, NOCASE

Control Type: Primary

Abbreviation: CA, NOCA

Arguments: None

Default: NOCASE

µVision Control: Options—A166 Assembler—Object—Case sensitive


assembly

Definition: the assembler is directed to operate in case sensitive mode


(CASE) or case insensitive mode. In case insensitive mode
the assembler converts lower case input characters to upper
case. CASE becomes meaningful if modules generated by the
assembler are combined with modules generated from the C
4
compiler. Identifiers exported from C modules appear always
as written, the corresponding names in the assembler module
must therefore put into the object module as written,
preserving case sensitivity.

Example:
$CASE
A166 SAMPLE.A66 CASE
72 Chapter 4. Invocation and Controls

COND / NOCOND
Name: COND/NOCOND

Control Type: General

Abbreviation: None

Arguments: None

Default: COND

µVision Control: Options—A166 Assembler—Listing—Include conditional


code

Definition: COND indicates that skipped parts of an IF-ELSEIF-ENDIF


construct will be listed. The skipped lines can be recognized

4 by missing line numbers. NOCOND indicates that


unassembled parts will be not listed.

Examples:
$ COND
$ NOCOND
166/167 Assembler and Utilities 73

DATE
Name: DATE

Control Type: Primary

Abbreviation: DA

Arguments: a string enclosed in parentheses (max. 9 characters long).

Default: Date is obtained from Operating system.

µVision Control: Options—A166 Assembler—Listing—Date

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

Control Type: Primary

Abbreviation: DB, NODB

Arguments: None

Default: NODEBUG

µVision Control: Options—A166 Assembler—Object—Include debug


information

Definition: DEBUG directs the assembler to include symbolic


information into the object module for symbolic debugging

4 purposes. A166 also emits line number information into the


object file. This enables dScope-166 to perform source level
language display. If NODEBUG is active, no symbolic
information and line numbers will be put into the object file.

Example:
$ DEBUG
A166 SAMPLE.A66 DEBUG
166/167 Assembler and Utilities 75

EJECT
Name: EJECT

Control Type: General

Abbreviation: EJ

Arguments: None

Default: None

µVision Control: 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

Control Type: Primary

Abbreviation: EP, NOEP

Arguments: an optional filename in parenthesis that complies with the


DOS conventions.

Default: NOERRORPRINT

µVision Control: None

Definition: ERRORPRINT indicates that all erroneous lines of source


and the corresponding error message shall be output to the

4 specified file. If no file is specified the erroneous lines are


displayed at the console.

A fatal error occurs if the console is specified as the output


for the list file and ERRORPRINT has no argument.

Example:
$ ERRORPRINT (SAMPLE.ERR)
$ NOEP
A166 SAMPLE.A66 EP
166/167 Assembler and Utilities 77

EXPDECNUM
Name: EXPDECNUM

Control Type: Primary

Abbreviation: EDN

Arguments: None

Default: expand %eval result to a hex number

µVision Control: None

Definition: The EXPDECNUM directive causes the macro preprocessor


to expand the result to a decimal number. Without
EXPDECNUM, a hex number is generated.

Example:
$ EXPDECNUM
4
A166 SETUP.A66 EXPDECNUM
78 Chapter 4. Invocation and Controls

GEN / GENONLY / NOGEN


Name: GEN, GENONLY, NOGEN

Control Type: General

Abbreviation: GO (for GENONLY)

Arguments: None

Default: NOGEN

µVision Control: Options—A166 Assembler—Listing—Macro expansion

Definition: these directives specify the amount of intermediate expansion


text, which is output:

4 NOGEN: the macro call is shown along with the


final macro expansion text.

GENONLY: the macro call is shown plus the first


level of intermediate macro expansion.

GEN: the complete macro expansion including


all intermediate expansions are shown.
This mode can be selected for macro
debugging purposes.

These controls are processed by the macro preprocessor and


are ignored by the remaining assembler phases.

Example:
$ NOGEN
$ GENONLY
A166 SAMPLE.A66 GEN
166/167 Assembler and Utilities 79

INCDIR
Name: INCDIR

Control Type: Primary

Abbreviation: ID

Arguments: one or more DOS conforming path names enclosed in


parentheses

Default: None

µVision Control: None

Definition: With INCDIR, you can supply one or more paths to search
for when a $INCLUDE (file) directive processed.

When an INCLUDE directive is processed, the assembler


first tries to find the include file in the current path. If this
4
fails, then the paths specified by INCDIR will be searched.
The path order corresponds to the order used in the INCDIR
definition.

Example:
$ INCDIR (C:\C166\ASM)
A166 STARTUP.A66 INCDIR (C:\C166\ASM,C:\C166\MYINC)
80 Chapter 4. Invocation and Controls

INCLUDE
Name: INCLUDE

Control Type: General

Abbreviation: IC

Arguments: a DOS conforming filename enclosed in parentheses

Default: None

µVision Control: 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.

4 INCLUDE must be specified through a control line, usage in


the invocation line is not allowed.

The INCLUDE directive should not be intermixed with other


directives one the same control line. Directives following
INCLUDE in the same control line are ignored.

The INCLUDE directive can be used to include any text like


register and bit definitions into the assembly process.

Example:
$ INCLUDE (REG167.INC)
166/167 Assembler and Utilities 81

LIST / NOLIST
Name: LIST, NOLIST

Control Type: General

Abbreviation: LI, NOLI

Arguments: None

Default: LIST

µVision Control: None

Definition: NOLIST disables the printing of subsequent source text in the


listing file. LIST causes the text to be displayed. Lines
causing errors will be listed even if NOLIST is in effect.

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

Control Type: Primary

Abbreviation: None

Arguments: None

Default: MACRO

µVision Control: None

Definition: MACRO indicates that macro definitions and invocations will


be recognized and processed (default). NOMACRO disables
the macro preprocessor.

4 Examples:
$ MACRO
$ NOMACRO
166/167 Assembler and Utilities 83

MOD166 / NOMOD166
Name: MOD166, NOMOD16

Control Type: Primary

Abbreviation: M166, NOM166

Arguments: None

Default: MOD166

µVision Control: Options—A166 Assembler—Object—Define 80C166


Special Function Registers (SFRs)

Definition: MOD166 specifies that all system names described in the


hardware specification for the 166/167 are known to the
assembler and can be used without declaration. Assembling
with NOMOD166 being active, only the names of the general
purpose registers and the special function registers DPP0 -
4
DPP3, MDL, MDH, MDC are known to the assembler.
NOMOD166 should be used if a customer specific SFR
definition file is used:

$ NOMOD166
$ INCLUDE (REG167.DEF)

Example:
$ NOMOD166
84 Chapter 4. Invocation and Controls

MOD167
Name: MOD167

Control Type: Primary

Abbreviation: M167

Arguments: None

Default: MOD166

µVision Control: Options—A166 Assembler—Object—Enable 80C167


instructions

Definition: MOD167 enables the 167 instruction set which is a superset


of the 166 instruction set. The definition file REG167.INC

4 should be included for definition of the SFR names and the


extended set of SFR names.

Example:
$ MOD167
$ INCLUDE (REG167.INC)
166/167 Assembler and Utilities 85

OBJECT / NOOBJECT
Name: OBJECT, NOOBJECT

Control Type: Primary

Abbreviation: OJ, NOOJ

Arguments: OBJECT (filename)

Default: OBJECT (input_filename.OBJ)

µVision Control: None

Definition: The OBJECT (filename) directive changes the name of the


object file to the name provided. By default, the name and
path of the source file with the extension ‘.OBJ’ is used. The

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

Control Type: Primary

Abbreviation: PL

Arguments: a number between 10 and 65535 enclosed in parenthesis

Default: PAGELENGTH(69)

µVision Control: Options—A166 Assembler—Listing—Page Length

Definition: PAGELENGTH specifies the maximum number of lines per


page to be printed in the listing file. The argument must be a
decimal number in range 18 to 32760.

4 Example:
$ PAGELENGTH (132)
$ PL (75)
A166 SAMPLE.A66 PAGELENGTH (120)
166/167 Assembler and Utilities 87

PAGEWIDTH
Name: PAGEWIDTH

Control Type: Primary

Abbreviation: PW

Arguments: a number between 78 and 132 enclosed in parenthesis

Default: 120 characters per line

µVision Control: Options—A166 Assembler—Listing—Page Width

Definition: the PAGEWIDTH directive specifies the maximum number


of characters on a line to be printed in the listing file. Longer
lines are automatically wrapped around to the next line.

Example:
$ PW (79)
4
A166 SAMPLE.A66 PW (78)
88 Chapter 4. Invocation and Controls

PAGING / NOPAGING
Name: PAGING, NOPAGING

Control Type: Primary

Abbreviation: PA, NOPA

Arguments: None

Default: PAGING

µVision Control: None

Definition: NOPAGING disables the generation of form feeds and page


headers in the listing. PAGING enables form feeds and
headers. The length of the pages is specified by

4 Example:
PAGELENGTH directive.

$ NOPAGING
A166 SAMPLE.A66 NOPA
166/167 Assembler and Utilities 89

PRINT / NOPRINT
Name: PRINT, NOPRINT

Control Type: Primary

Abbreviation: PR, NOPR

Arguments: PRINT (filename)

Default: PRINT (input_filename.LST)

µVision Control: Options—A166 Assembler—Listing—Generate .LST file

Definition: The assembler produces a listing of each assembled program


using the path and name of the source file with the extension
‘.LST’. The name of that listing file can be redefined by use
of the PRINT option. When the NOPRINT option is
invoked, no listing is produced. 4
Example:
$ PRINT (C:\SAMPLE.LST)
$ PR (:CO:)
$ NOPRINT
A166 SAMPLE.A166 PRINT (C:\LSTS\XSAMPLE.LST)
90 Chapter 4. Invocation and Controls

REGUSE
Name: REGUSE

Control Type: General

Abbreviation: RU

Arguments: A PROC identifier and a register list enclosed in parenthesis

Default: None

µVision Control: None

Definition: The REGUSE control specifies the registers modified during


execution of the function given by PROC identifier.
REGUSE can be used in combination with the C166 compiler

4 and allows global register optimization also for functions


coded in assembly language. For more information about
global register optimization refer to the C166 Compiler
User’s Guide.

The registers R0, R1, … R15, MDC (designates MDL, MDH


and MDC) and DPP0, DPP1, DPP2, DPP3 may be given. A
register range is a shortcut for registers such as ‘R0-R8’ or
‘DPP0-DPP3’.

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

p100 PROC NEAR ; p100 is the PROC identifier


MOV R8,R1
MOV MDC,R1 ; DPP3 used to address MDC
MUL R2
MOV R1,MDL ; DPP3 used to address MDL
MOV R2,MDH
RET
p100 ENDP

C100 ENDS

END

4
92 Chapter 4. Invocation and Controls

SAVE / RESTORE
Name: SAVE/RESTORE

Control Type: General

Abbreviation: SA/RS

Arguments: None

Default: None

µVision Control: None

Definition: SAVE stores the current setting of LIST on the internal


assembler stack. This stack can store up to 9 SAVE levels.
RESTORE restores the most recently saved value of LIST.

4 Examples:
$ SAVE NOLIST
$ INCLUDE (REG167.INC)
$ RESTORE
166/167 Assembler and Utilities 93

SEGMENTED / NONSEGMENTED
Name: SEGMENTED, NONSEGMENTED

Control Type: Primary

Abbreviation: SG, NOSG

Arguments: None

Default: NONSEGMENTED

µVision Control: Options—A166 Assembler—Object—Segmented Mode

Definition: NONSEGMENTED specifies that A166 translates the source


module using the non-segmented mode of CPU operation.
The ASSUME directive and DPP-prefixes are not needed in
this mode. NONSEGMENTED specifies that the DPP’s are
once loaded and never changed, the total amount of memory
that can be addressed is 64K for both code and data.
4
SEGMENTED specifies that the translation is using the
segmented mode of CPU operation. DPP’s must be set with
the ASSUME directive to data sections or groups to establish
and check that data can be addressed properly. The full
address space can be covered in SEGMENTED mode only.

Examples:
$ SEGMENTED
$ SG
A166 SAMPLE.A66 SEGMENTED
94 Chapter 4. Invocation and Controls

SYMBOLS / NOSYMBOLS
Name: SYMBOLS/NOSYMBOLS

Control Type: Primary

Abbreviation: SB/NOSB

Arguments: None

Default: SYMBOLS

µVision Control: Options—A166 Assembler—Listing—Include Symbols

Definition: SYMBOLS specifies whether a symbol table shall be listed.


The SYMBOLS control is overridden by NOPRINT. The
XREF activates the SYMBOLS control.

4 Example:
$ SYMBOLS
$ NOSB
A166 SAMPLE.A66 NOSYMBOLS
166/167 Assembler and Utilities 95

TABS
Name: TABS

Control Type: Primary

Abbreviation: TA

Arguments: decimal number in range 1 to 16, enclosed in parentheses.

Default: TABS(8)

µVision Control: Options—A166 Assembler—Listing—Tabs

Definition: specifies the number of blanks that must be inserted to


replace a tab character in the list file.

Example:
$ TABS (4)
A166 SAMPLE.A66 TABS (4)
4
96 Chapter 4. Invocation and Controls

TITLE
Name: TITLE

Control Type: General

Abbreviation: TT

Arguments: String enclosed in parentheses (max. 60 characters)

Default: Title of ‘NAME’ or source code name without an extension.

µVision Control: Options—A166 Assembler—Listing—Title

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.

$ TITLE (Oven Controller Version 3.12)


$ TT ('quote enclosed string')
166/167 Assembler and Utilities 97

TYPE / NOTYPE
Name: TYPE / NOTYPE

Control Type: Primary

Abbreviation: TY, NOTY

Arguments: None

Default: TYPE

µVision Control: None

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

Control Type: Primary

Abbreviation: UEO

Arguments: None

Default: generate external definitions for unused external identifiers

µVision Control: None

Definition: USEDEXTONLY directs A166 to omit external definition


records for unused external identifiers.

4 Example:
$ USEDEXTONLY
$ A166 SETUP.A66 USEDEXTONLY
166/167 Assembler and Utilities 99

XREF / NOXREF
Name: XREF, NOXREF

Control Type: Primary

Abbreviation: XR/NOXR

Arguments: None

Default: NOXREF

µVision Control: Options—A166 Assembler—Listing—Include cross


reference

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

Directives for Conditional Assembly


The directives for conditional assembly belong to the class of general controls.
Conditional assembly can be used to implement different program versions or
different memory models with one source file. Therefore only one source module
must be maintained to satisfy several applications.

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.

IF blocks may be nested to a maximum of ten. If a block is not translated the


nested conditional blocks which are part of this block are also skipped.

4 The following table lists the conditional assembly control statements.

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

Arguments: (<variable> [,<variable> [, …]])


<variable> = <num. value> [, …])
(<var>, <var> = <num. value>, <var> [, …])

Default: None

µVision Control: None

Definition: SET and RESET assign a numeric value to a specified


variable. These variables can be used in expressions
containing ‘IF’ and ‘ELSEIF’ directives for conditional
assembly. The variables must conform to the usual
conventions and are only used to control the assembler. The
variables are administered separately and cannot interfere
4
with the other symbols.

The <numerical value> can be a number or an absolute


expression. If SET is used in the invocation line, the
argument to SET must be a single decimal number, otherwise
an absolute expression is allowed.
$ SET (TMP, TMP1 = 55, TMP2, TMP3)

In the example above the variables TMP, TMP2 and TMP3


are assigned the implicit value 0FFFFH (‘TRUE’) since no
explicit value is given. The TMP1 variable is assigned to 55
decimal.
$ RESET (TMP, VAR, TMP3)

The variables above are assigned to 0000H (‘FALSE’). If a


variable is unknown it is automatically assigned to 0000H.

Examples:
$ SET (TEST, ITERATION = 3)
$ RESET (TEST, INTERATION, DEBUG_VAR)
102 Chapter 4. Invocation and Controls

IF
Name: IF

Abbreviation: none

Arguments: <numerical expression>

Default: None

µVision Control: None

Definition: The numerical expression is computed and if the value is


true, the statements in the IF block will be executed. Control
passes as soon as ENDIF, ELSEIF or ELSE statement on the
same nesting level is encountered. If the value is false (0)
control is only passed after controls with a $ sign in front.

4 An error occurs if IF/ENDIF statements are not balanced.

Examples:
$ IF (DEBUG_VAR = 3)
Version_3: MOV R8,#TABLE_3
<other text lines>
$ ENDIF
166/167 Assembler and Utilities 103

ELSEIF
Name: ELSEIF

Arguments: <numerical expression>

Default: None

µVision Control: None

Definition: ELSEIF introduces an alternative IF block that has control till


the next ELSEIF, ELSE or ENDIF directive, assumed the
expression evaluates to TRUE and no previous IF or ELSEIF
was true.

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

µVision Control: None

Definition: The ELSE directive introduces an alternative to the IF or


ELSEIF block. The ELSE block is assembled till the next
ENDIF directive, assumed that no previous IF- of ELSEIF-
directive evaluated to TRUE.

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

µVision Control: None

Definition: The ENDIF directive terminates a IF block. Control is


returned to the calling IF block if the assembler was
assembling before the IF block, then the assembly will
continue. This is important when IF statements are nested.

An error occurs if the number of ENDIF directives is not


equal to the number of IF statements.

Example: 4
$ IF (TEST)
<line(s) of text>
$ ENDIF
106 Chapter 4. Invocation and Controls

4
166/167 Assembler and Utilities 107

Chapter 5. The Macro Processor

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.

Creating and Calling Macros


The macro processor is a character string replacement facility. It searches the
source file for a macro call, and then replaces the call with the macro’s return
value. A % character signals a macro call.

The macro processor function DEFINE creates macros. Macro processor


functions are a predefined part of the macro language, and can be called without
definition. The syntax for DEFINE is:
108 Chapter 5. The Macro Processor

%[*]DEFINE (macro name) [parameter-list] (macro-body)

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.

Creating Parameterless Macros


When you create a parameterless macro, there are two parts to a DEFINE call:

„ macro name

The macro name defines the name used when the macro is called.
„ macro body

The macro-body defines the return value of the call.


The syntax of a parameterless macro definition is shown below:
%*DEFINE (macro name) (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.

Macro names have the following conventions:

„ maximum of 31 characters long


„ first character must be one of ‘A’-‘Z’, ‘a’-‘z’, ‘_’, or ‘?’
„ subsequent characters must be one of ‘A’-‘Z’, ‘a’-‘z’, ‘_’, ‘?’, or ‘0’-‘9’

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.

Once a macro has been created, it may be redefined by a second DEFINE.

Macros with Parameters


Parameters in a macro body allow to fill in values when you call the macro. This
permits you to design a generic macro that produces code for many operations.

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 syntax for defining macros with parameters is:


%*DEFINE (macro-name(parameter-list)) (macro-body)

The parameter-list is a list of identifiers separated by macro delimiters. The


identifier for each parameter must be unique. 5
Typically, the macro delimiters are parentheses and commas. When using these
delimiters, you would enclose the parameter-list in parentheses and separate each
formal parameter with a comma. When you define a macro using parentheses and
commas as delimiters, you must use those same delimiters, when you call that
macro.

The macro-body must be a balanced-text string. To indicate the locations of


parameter replacement, place the parameter’s name preceded by the metacharacter
in the macro-body. The parameters may be used any number of times and in any
order within the macro-body. If a macro has the same name as one of the
parameters, the macro cannot be called within the macro-body since this would
lead to infinite recursion.

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

1 ;%*DEFINE (BMOVE (src, dst, cnt)) LOCAL lab (


2 ; MOV R2,#%cnt
3 ; MOV R1,#%src
4 ; MOV R0,#%dst
5 ;%lab: MOVB [R0+],[R1]
6 ; ADD R1,#1
7 ; CMPD1 R2,#0
8 ; JMP CC_NZ,%lab
9 ;)
10

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 example shows an assembled file containing a macro definition in lines 1 to 9.


The macro definition shows semicolons at start of each line. These semicolons are
added by the assembler to prevent assembly of the definition text which is
meaningful to the macro preprocessor, but not to the remaining assembler phases.
The listing will not include macro definitions or macro calls, if the general control
NOGEN (which is the default if none is given), is used.

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.

Local Symbols List


The JMP CC_NZ instruction in the previous example uses a local label for target
of the branch. If a fixed label name is used (for example xlab, without leading %)
then activation of the macro a second time would cause assembly errors due to
multiple definitions of a single name.

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)

The local-list is a list of valid macro identifiers separated by spaces or commas.


The LOCAL construct in a macro has no affect on the syntax of a macro call.

Macro Processor Functions


The macro processor has several predefined macro processor functions. These
macro processor functions perform many useful operations that would be difficult
or impossible to produce in a user-defined macro. An important difference
between a user-defined macro and a macro processor function is that user-defined
macros may be redefined, while macro processor functions can not be redefined.
112 Chapter 5. The Macro Processor

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.

%'the complete line including end-of-line is a comment

Source text before macro processing:


MOV R5, R15 %'the following line will be kept separate'
MOV R1, %'this comment eats the newline character
R12

Resulting output text from macro processor:


MOV R5, R15
MOV R1, R12

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

The metacharacter followed by a single decimal digit specifies the number of


characters (maximum is 9) shall not be evaluated. The escape function is useful
for inserting a metacharacter (normally the % character), a comma, or a
parenthesis.

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

Macro definition of ‘DW’:


%*DEFINE (DW (LIST, LABEL)) (
%LABEL: DW %LIST
)

Macro call to ‘DW’:


%DW (%(120, 121, 122, 123, -1), TABLE)

return value of the macro call to ‘DW’:


TABLE: DW 120, 121, 122, 123, -1
114 Chapter 5. The Macro Processor

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 syntax of the METACHAR function is:


%METACHAR (balanced_text)

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 !

Numbers and Expressions


Balanced text strings appearing in certain places in built-in macro processor
functions are interpreted as numeric expressions:

„ the argument to evaluate function ‘EVAL’


„ the argument to the flow of control functions ‘IF’, ‘WHILE’, ‘REPEAT’, and
‘SUBSTR’.
Expressions are processed as follows:

„ 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

„ The resulting string is evaluated to both a numeric and character


representation of the expressions result. The return value is the character
representation.
The following operators are allowed (shown in order of precedence):

♦ 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.

Base Suffix Valid Characters Examples


Hexadecimal H,h 0-9, A-F, a-f 1234H 99H 123H 0A0F0H 0FFH
Decimal D,d 0-9 1234 65590D 20d 123
Octal O,o,Q,q 0-7 177O 7777o 25O 123o 177777O
Binary B,b 0-1 1111B 10011111B 101010101B
Hexadecimal numbers must be preceded with a 0, if the first digit is in range A to F.

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.

1111$0000$1010$0011B - is equivalent to - 1111000010100011B


1$2$3$4 - is equivalent to -1234

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 (’).

‘A’ evaluates to 0041H


‘AB’ evaluates to 4142H
‘a’ evaluates to 0061H
‘ab’ evaluates to 6162H
‘’ the null string is not valid!
‘abc’ ERROR due to more than two 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 syntax of the SET function is:


%SET (identifier,expression)

SET assigns the value of the numeric expression to the identifier.

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.

Examples of the SET function:


Source text:
%SET (CNT, 3)
%SET (OFS, 16)
MOV R1,#%CNT+%OFS
166/167 Assembler and Utilities 117

%SET (OFS, %OFS + 10)


OFS = %OFS

Expanded output text:


MOV R1,#3+16
OFS = 26

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'

%' change values for CNT and OFS:'

%SET (CNT, %CNT+%OFS) %' CNT = 30'


%SET (OFS, %OFS * 2) %' OFS = 40'
MOV R2,#%CNT + %OFS %' 70'
MOV R5,#%CNT %' 30'

Expanded output text:


MOV R2,#30 + 40
MOV R5,#30

EVAL Function
The macro processor function EVAL accepts an expression as an argument and
5
returns the decimal character representation of its result.

The syntax of the EVAL function is:


%EVAL (expression)

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'

MOV R15,#%EVAL (%CNT+1)


MOV R14,#%EVAL (14+15*200)
MOV R13,#%EVAL (-(%CNT + %OFS - 1))
MOV RL2,#%EVAL (%OFS LE %CNT)
MOV RL7,#%EVAL (%OFS GE %CNT)
118 Chapter 5. The Macro Processor

Expanded output text:


MOV R15,#11
MOV R14,#3014
MOV R13,#-29
MOV RL2,#0
MOV RL7,#1

Logical Expressions and String Comparison


The following macro processor functions compare two balanced-text string
arguments and return a logical value based on that comparison. If the function
evaluates to ‘TRUE,’ then it returns ‘1’. If the function evaluates to ‘FALSE,’
then it returns ‘0’. The list of string comparison functions below shows the syntax
and describes the type of comparison made for each. Both arguments to these
function may contain macro calls. (This macro calls are expanded before the
comparison is made).

%EQS (arg1,arg2)True if both arguments are identical

%NES (arg1,arg2) True if arguments are different in any way

%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

%GTS (arg1,arg2)True if first argument has a higher value than second


argument

%GES (arg1,arg2)True if first argument has a higher 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

%LTS (A166,a166) 1 (TRUE), the lower case characters have a


higher ASCII value than upper case

%GTS (10,16) 0 (FALSE), these macros compare strings not


numerical values. ASCII '6' is greater than
ASCII '1'

%GES (a166,a166 ) 0 (FALSE), the space at the end of the second


argument makes the second argument greater
166/167 Assembler and Utilities 119

than the first

%*DEFINE (VAR1) (A166)


%*DEFINE (VAR2) (%VAR1)
%EQS (%VAR1,%VAR2) 1 (TRUE), expands to: %EQS(A166,A166)

Conditional Macro Processing


Some macro processor functions accept logical expressions as arguments. The
macro processor uses the value 1 and 0 to determine TRUE or FALSE. If the
value is one, then the expression is TRUE. If the value is zero, then the expression
is FALSE.

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

%ADDSUB (ADD,R15,R3) %' generate ADD R15,R3'


%ADDSUB (SUB,R15,R9) %' generate SUB R15,R9'
%ADDSUB (MUL,R15,R4) %' generates nothing !'

Expanded output text:


ADD R15,R3
SUB R15,R9

WHILE Function
Often you may wish to perform macro operations until a certain condition is met.
The macro processor function WHILE provides this facility.

The syntax for the macro processor function WHILE is:


%WHILE (expression) (balanced-text)

WHILE first evaluates the expression. If it is TRUE, then the balanced-text is


expanded; otherwise, it is not. Once the balanced-text has been expanded, the
logical argument is re-tested and if it is still TRUE, then the balanced-text is again
expanded. This loop continues until the logical argument proves FALSE.

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)
)

Expanded output text:


ADD R15,R15
ADD R15,R15
ADD R15,R15
ADD R15,R15
ADD R15,R15
166/167 Assembler and Utilities 121

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-
)

%REPEAT (5) (+%REPEAT (9) (-))+

Expanded output text:


-enter any key to shut down-
-enter any key to shut down-
-enter any key to shut down-
-enter any key to shut down-
-enter any key to shut down-
+---------+---------+---------+---------+---------+ 5
EXIT Function
The EXIT macro processor function terminates expansion of the most recently
called REPEAT, WHILE or user-defined macro function. It is most commonly
used to avoid infinite loops (example: a WHILE that never becomes FALSE, or a
recursive user-defined macro that never terminates). It allows several exit points
in the same macro.

The syntax for the macro processor function EXIT is:


%EXIT

Example:
Source text:
%SET (count, 0)

%WHILE (1)
122 Chapter 5. The Macro Processor

(%IF (%count GT 5) THEN (%EXIT)


FI DW %count, -%count
%SET (count, %count + 1))

Expanded output text:


DW 0, -0
DW 1, -1
DW 2, -2
DW 3, -3
DW 4, -4
DW 5, -5

String Manipulation Functions


The purpose of the Macro Processor is to manipulate character strings. Therefore,
there are several macro processor functions that perform common character string
manipulations.

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.

Expanded output text:


4
9
0
26
LENGTH OF 'QUEEN' = 5.
166/167 Assembler and Utilities 123

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.

The syntax for the macro processor function SUBSTR is:


%SUBSTR (balanced-text,expression1,expression2)

balanced-text is any text argument, possibly containing macro calls. Expression1


specifies the starting character of the substring. Expression2 specifies the number
of characters to be included in the substring.

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.

If expression2 is zero, then SUBSTR returns the null string. If expression2 is


greater than the remaining length or the string, then all characters from the start
character to the end of the string are included.

Examples:
Source text: 5
%DEFINE (STRING) (abcdefgh)
%SUBSTR (%string, 1, 2)
%SUBSTR (%(1,2,3,4,5), 3, 20)

Expanded output text:


ab
2,3,4,5

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.

The syntax for the macro processor function MATCH is:


%MATCH (identifier1 delimiter identifier2) (balanced-text)
124 Chapter 5. The Macro Processor

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)
)

Expanded output text:


MOV R8,#-1
MOV [R1+],R8

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

Console I/O Functions


There are two macro processor functions that perform console I/O: IN and OUT.
Their names describe the function each performs. IN outputs a character ‘>‘ as a
prompt, and returns the line typed at the console. OUT outputs a string to the
console; a call to OUT is replaced by the null string.

The syntax for the macro processor functions IN an OUT is:


%IN

%OUT (balanced-text)
166/167 Assembler and Utilities 125

Examples:
Source text:
%OUT (enter baud rate)
%set (BAUD_RATE,%in)
BAUD_RATE = %BAUD_RATE

Expanded output text:


<19200 was entered at the console>
BAUD_RATE = 19200

Advanced Macro Processing


The macro definition function associates an identifier with a functional string.
The macro may or may not have an associated pattern consisting of parameters
and/or delimiters. Also optionally present are local symbols. The syntax for a
macro definition is:
%DEFINE (macro_id define_pattern) [LOCAL id_list] (balanced_text)

The define_pattern is a balanced string which is further analyzed by the macro


processor as follows:
define_pattern = { [parm_id] [delimiter_specifier] }
5
Delimiter_specifier is one of the following:

„ some string not containing non-literal id-continuation. logical blank or


character @.
„ @delimiter_id

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:

„ more than one character,


„ a macro identifier character (A-Z, 0-9, _, or ?),
„ a commercial at (@), a space, tab, carriage return, or linefeed.

Use the escape function (%n) or the bracket function (%()) to literalize the
delimiter string.

This is the simple form shown earlier:

5 Before Macro Expansion


%*DEFINE(MAC(A,B))(%A %B)
After Macro Expansion
null string
%MAC(4,5) 4 5

In the following example brackets are used instead of parentheses. The


commercial at symbol separates parameters:

Before Macro Expansion After Macro Expansion


%*DEFINE (MOV[A%(@)B]) (MOV %A,%B) null string
%MOV[P0@P1] MOV P0,P1

In the next two examples, delimiters that could be id delimiters have been defined
as literal delimiter (the differences are noted):

Before Macro Expansion After Macro Expansion


%*DEFINE(ADD (R10 AND B)) (ADD R10,%B) null string
%ADD (R10 AND #27H) ADD R10,#27H
166/167 Assembler and Utilities 127

Spaces around AND are considered part of the argument string.

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.

Example source text:


%*DEFINE (X1 X2 X3) (P2=%X2, P3=%X3)
%X1 assembler A166

Example output text:


P2=assembler, P3=A166

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 calling a macro defined with identifier delimiters, a blank delimiter is


required to precede the identifier delimiter, but none is required to follow the
identifier delimiter.

Example source text:


%*DEFINE (ADD X1 @TO X2 @STORE X3)(
MOV R1,%X1
MOV R2,%X2
ADD R1,R2
MOV %X3,R1
)
%ADD VAR1 TO VAR2 STORE VAR3
128 Chapter 5. The Macro Processor

Example output text:


MOV R1,VAR1
MOV R2,VAR2
ADD R1,R2
MOV VAR3,R1

Literal and Normal Mode


In normal mode, the macro processor scans for the meta character. If it is found,
parameters are substituted and macros are expanded. This is the usual operation
of the macro processor.

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.

Error Error Message and Description


80 PREMATURE END OF FILE
The end of the source module was reached while processing some macro call, which
requires more input from the source file.
81 '<token>' IDENTIFIER EXPECTED
The macro processor expected an identifier while processing some macro. None was found.
The unexpected token is displayed with this error message.
82 MPL FUNCTION '<name>': '<character>' EXPECTED
The context of the macro processor language requires a specific character from the input
given by <character> while processing the built-in function given by <name>.]
83 <string>: UNBALANCED PARENTHESES
A balanced string requires the same number of right parentheses and left parentheses.
84 EXPECTED '<token>'
The syntax requires a specific token to follow, for example THEN after the balanced text
argument to IF.
85 INCOMPLETE MACRO DEFINITION

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

Error Error Message and Description


95 UNKNOWN EXPRESSION IDENTIFIER
The identifier within some expression is not an operator or a number.
96 <character>: INVALID EXPRESSION TOKEN
The given character does not form a valid operator or an identifier operator.
97 DIV/MOD BY ZERO
A division or modulo by zero error occurred while evaluating an expression.
98 EVAL: SYNTAX ERROR IN EXPRESSION
The expression to be evaluated contains a syntax error, for example two consecutive number,
not separated by an operator.
99 CAN'T OPEN FILE '<file>'
The file specified in the INCLUDE directive could not be opened.
100 '<file>' IS NOT A DISK FILE
The file name given in the INCLUDE directive does not specify a disk file. Files other than
disk files are not allowed (example: CON).
101 ERROR IN INCLUDE/INCDIR DIRECTIVE
The INCLUDE directive is ill-formed. The argument to INCLUDE must be the name of some
file, enclosed in parentheses.
102 CAN’T REDEFINE PREDEFINED MACRO ‘macroname’
Predefined macros such as SET can’t be redefined.

5
166/167 Assembler and Utilities 131

Chapter 6. Error Messages


All errors recognized by the A166 assembler cause error messages to be printed in
the listing file. A166 decides two classes for errors:

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.

A166 FATAL ERROR -


ACTION: <current action>
PARAMETER: <e.g. an illegal option>
6
ERROR: <error message with description>
A166 TERMINATED.

A166 FATAL ERROR -


ERROR: <error message with description>
A166 TERMINATED.

ACTION can be one of the following:

„ ATTACH FILE. The selected source file was not found.


„ PARSING COMMAND LINE. An unknown option, or an illegal argument
was input at the invocation line.
„ PARSING ‘$’-CONTROL LINE. A control statement in the source code is
unknown or an illegal argument was input.
132 Chapter 6. Error Messages

FILE is the file that could not be opened. The message ‘FILE’ is output if the
error occurred due to a file.

PARAMETER is an unknown option or an illegal argument for a legal option.


The ‘PARAMETER’ field is output when the error occurred due to a control
statement.

ERROR is one of the following errors:

„ LIMIT EXCEEDED: LINE TOO LONG (500)


An input source line contains more than 500 characters. The assembly run is
aborted.
„ ERRORPRINT- AND LIST-FILE CANNOT BE THE SAME
It is illegal to direct the listing file output and the error output to the console at
the same time. The assembly run is aborted.
„ NON-NULL ARGUMENT EXPECTED
In the invocation line the name of the file to be translated or a filename to an
option was left out. The assembly run is aborted.
„ CONFLICTING CONTROL
An option of the invocation line conflicts with another option. This occurs if
e.g. the controls ‘NOOBJECT’ and ‘OBJECT(xxx)’ are specified in the
invocation line.
„ CANNOT HAVE GENERAL CONTROL IN INVOCATION
Some controls are only allowed in the source text but not in the invocation
line. Following controls are not allowed in the invocation line: INCLUDE, IF,

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

„ OUT OF RANGE NUMERIC VALUE


A numerical argument to an option is out of range. This occurs e.g. when the
PAGEWIDTH option has an argument lower than 78 or higher than 132.
„ LIMIT EXCEEDED: SYMBOL-TABLE SPACE EXHAUSTED
The symbol-table space has been exhausted and cannot take any more
symbols. The assembly run is aborted. The symbol table can accommodate a
fixed amount of 6000 symbols, independent of the length of the symbols.
„ LIMIT EXCEEDED: MORE THAN 100 ‘SET’ VARIABLES
The number of $SET variables must not exceed 100.
„ INVOCATION LINE TOO LONG (500)
The total number of characters in the invocation line may not exceed 500
characters. It is not possible under DOS to have more than 122 characters but
when using the SHELL.
„ IDENTIFIER EXPECTED
The control directive expected some identifier but something else was
encountered.
„ MEMORY SPACE EXHAUSTED
There is no more memory available. This error may occur when allocating
space for a symbol or when using XREF with very large modules containing a
lot of symbols each with a lot of uses.
„ CAN’T OPEN FILE
The specified file can’t be opened for read access.
„ CAN’T CREATE FILE
The specified file can’t be opened for write access.
„ CAN’T CLOSE FILE 6
The disk file cannot be closed for some reason.
„ FILE WRITE ERROR
The specified file cannot be written to, due to a probably full disk.
„ ATTEMPT TO SHARE FILE
An attempt was made to open a file for both reading and writing. This occurs
e.g. if the name of an INCLUDE file is the same as that of the object file.
„ DISK FILE REQUIRED
The specified file is not the name a disk file.
„ LIMIT EXCEEDED: INCLUDE FILE NESTING (9)
The nesting of include files caused a violation of the maximum depth of nine.
134 Chapter 6. Error Messages

„ LIMIT EXCEEDED: INPUT FILE OR MACRO STACK OVERFLOW


The nesting of input files and macros exceeded an internal limit.
„ LIMIT EXCEEDED: BALANCED TEXT LENGTH (2045)
The internal limit of the balanced text length of the macro preprocessor has
been violated. Expansions and intermediate expansions may not produce
strings longer than 2045 characters.

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

LOC OBJ LINE SOURCE 1


2 C100 SECTION CODE
3 P100 PROC NEAR
4 MOV R1,#12A0
*** ____________________________________________^
*** ERROR #1, LINE #4, ILLEGAL CHARACTER IN NUMERIC CONSTANT
5 MOV R0,#25 *, 10
*** ______________________________________________^
*** ERROR #6, LINE #5, SYNTAX ERROR
6 P100 ENDP
7 C100 ENDS
*** ERROR #89, LINE #7, PREMATURE END OF FILE (NO END STATEMENT)

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

Error Error Message and Description


1 ILLEGAL CHARACTER IN NUMERIC CONSTANT
Numerical constants must begin with a decimal digit. Within these digits $-signs are allowed
for easier reading. Error 1 occurs if after the $-sign no valid digit is encountered or some
other invalid numeric character was found. The base of the number decides which numbers
are valid:
„ Base 2: 0, 1, and the base indicator B
„ Base 8: 0-7 and the base indicator O or Q
„ Base 10: 0-9 and the base indicator D or no indicator
„ Base 16: 0-9, A-F, and the base indicator H
2 MISSING STRING TERMINATOR
In a character string a the second string terminator was left out, the string was ended by a
carriage return (CR).
3 ILLEGAL CHARACTER
A character not contained in the set of valid A166 characters was encountered.
4 ILLEGAL USE OF A RESERVED WORD
This error occurs, if for example a reserved word is used for the name of a label.
5 SYMBOL OR LABEL REDEFINITION
A label or symbol cannot be defined more than one time in a source program.
6 SYNTAX ERROR
This error indicates that the marked token is not expected in this context.
7 RESPECIFIED PRIMARY CONTROL, LINE IGNORED
A primary control (in a $ line) was repeated or conflicted. The control was ignored. The
controls first specified remain valid.
8 MISPLACED PRIMARY CONTROL, LINE IGNORED
A primary control was misplaced. Primary controls may be entered in the invocation line or at
the beginning of the source file (as $ control lines). Processing of primary controls is
terminated, if source lines are encountered, which contain A166 directives. An exception to
this are empty lines or pure comment lines.
9 CONFLICTING CONTROL
The given control directive conflicts to some other previously given control, e.g.

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

Error Error Message and Description


15 EXPRESSION TOO COMPLEX
The expression is too complex due to too many operands and operators. Simplify the
expression. Typically this error occurs, if a total of more than 50 expression tokens
(numbers, identifiers, operators and parentheses) are contained in an expression.
16 UNKNOWN CONTROL OR BAD ARGUMENT(S)
The control directive in a control line (introduced by $) is unknown to the assembler or the
arguments to the control are invalid.
17 MISPLACED ELSEIF/ELSE/ENDIF CONTROL
One of the control directives ELSEIF, ELSE or ENDIF was found in illegal context. These
directives require that a previous IF section has been opened.
18 LIMIT EXCEEDED: IF-NESTING (10)
The number of nested IF constructs is limited to a maximum of 10.
19 NUMERIC VALUE OUT OF RANGE
This error indicates an out of range numeric value, for example:

DSEC SECTION DATA AT 45000H ; out of address space


DSEC ENDS

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.

DSEC SECTION DATA ; open DSEC


XSEC SECTION DATA ; open XSEC
XSEC ENDS ; close XSEC first
DSEC ENDS ; close then DSEC
166/167 Assembler and Utilities 137

Error Error Message and Description


29 UNMATCHED ENDS/ENDP
A code section containing one or more procedures was closed without closing the last recent
procedure first.
30 REDEFINITION: 'SECTION TYPE'
31 REDEFINITION: 'ALIGN TYPE'
32 REDEFINITION: 'COMBINE TYPE'
33 REDEFINITION: 'CLASS NAME'
These errors will occur, if a previously defined section is reopened with different attributes.
The attributes must be exactly the same or should be omitted (with the exception of 'section
type'). If the attributes are left out on a reopened section, then that section will automatically
inherit the attributes from the first definition of that section.
34 ILLEGAL SECTION TYPE
A member of a group has illegal section type. Code groups may contain sections of type
code only. Data groups may contain sections of type data only. Sections of type bit cannot
be member of a group.
35 'DPPn' EXPECTED
The context indicates that the name of some data page pointer (DPP0 to DPP3) is expected,
but something other was found. The situations where a DPP is required are:
„ External definitions (EXTRN DPP2:var1:word)
„ Assume directives (ASSUME DPP1:section_name)
The name of the DPP's are in the class of special function register names (SFR), internal to
the assembler. An error occurs, if the name of some SFR is given which is not DPP0,
DPP1, DPP2 or DPP3.
36 ':' EXPECTED
A colon was expected by context, but some other token was encountered.
37 TYPE IDENTIFIER EXPECTED
The name of a type was expected, but some other token was encountered. Type names are
BIT, BYTE, WORD, DATA3, … REGBANK.
38 'DPP': VALID ON BYTE/WORD VARIABLES ONLY
An external declaration may contain an optional DPP specification, but this is valid on
externals of type BYTE, WORD and BITWORD only.
39 ILLEGAL PUBLIC/GLOBAL SYMBOL
Symbols defined by the SET directive may not receive the attribute PUBLIC or GLOBAL.
6
The name of sections or group are also not allowed to be PUBLIC or GLOBAL.
40 USE OF '$' OUTSIDE ANY SECTION
The use of the current location counter $ is allowed within some section only. The $ sign has
no meaning outside a section.
41 ILLEGAL STRING IN EXPRESSION
A string may be part of an expression representing a numeric value. The length of the string
must be either one or two. Zero length strings or strings containing more than two characters
are not allowed.
42 UNDEFINED IDENTIFIER
The given identifier is undefined.
43 ILLEGAL ALIGN TYPE
The given align type of a bit section is invalid. Bit sections may have align type BIT, BYTE,
WORD and DWORD. The alignment type BITADDRESSABLE is not allowed since a bit
section is always bit-addressable by definition.
138 Chapter 6. Error Messages

Error Error Message and Description


44 NO CURRENTLY ACTIVE SECTION
Some directive (DB, DW, DSPTR, …) or an instruction line has been encountered outside
any section. Data definitions or reservations or machine instructions must always be part of
a section.
45 KEYWORD NOT ALLOWED IN CURRENT CONTEXT
Some statement was encountered in an illegal context, for example: DBIT in a section other
than a bit section or machine code in a data or bit section and so on.
46 CAN'T NEST CODE SECTIONS
Data sections may be nested inside data or code sections but code sections can't be nested
within other sections including code at all.
47 ILLEGAL TYPE FOR A LABEL
A label was defined using the LABEL directive and an illegal type. The valid types of labels
are BIT, BYTE, WORD, NEAR, and FAR.
48 INSUFFICIENT ALIGNMENT
Word accesses are required to be on word boundaries by the 166/167 CPU. The assembler
therefore checks that the alignment requirements of word variables are ensured. In case of a
mis-aligned (e.g. odd addressed) word, the assembler gives a warning but does not insert a
byte for alignment, this is to be done by the user.
49 MORE THAN ONE REGBANK DEFINITION
A single source module may not contain more than one REGBANK definitions.
50 REGISTER RANGE OVERLAP
51 'REGDEF' REGISTERS DO NOT MATCH 'USED' REGISTERS
The registers defined in a REGDEF or REGBANK directive do not match the registers
actually used in the source module. The assembler recognizes all registers, which are used
in the source module. The error occurs, if the registers used in the module are a superset
from the registers defined per REGDEF or REGBANK.
52 INVALID REGISTER RANGE
A register range specification is wrong. A register range can be specified using 'Rm-Rn'
where m must be lower than n, e.g. R0 - R10. R3-R0 is illegal.
53 SECTION IS ALREADY A MEMBER OF GROUP
One section cannot be a member of different groups.

6 54 'ASSUME' IN NONSEGMENTED MODE IGNORED


In NONSEGMENTED mode, DPP assumes are not required since the DPP's values are left
un-initialized or initialized once in the startup code of the application. The default values of
the DPP's after CPU reset are: DPP0=0, DPP1=1, DPP2=2, DPP3=3. The whole application
must fit within the first 64K in NONSEGMENTED mode.
55 'DPP' IN NONSEGMENTED MODE IGNORED
A DPP-prefix was given to a variable in some instruction. Another cause for this error may
be a DPP specification in an external declaration. This is not necessary in
NONSEGMENTED mode. See also ERROR 54 for details.
56 ILLEGAL COMPONENT
The type of section in an ASSUME directive was bit. Bit sections do not require an
ASSUME to take place, since the addressing method specifies the target addresses by
means of word numbers which always map to the bit-addressable space, not using the data
page pointers at all.
57 ILLEGAL REGISTER
The register name contained in an indirect register specifier (e.g. [-R10]) is not the name of a
word general purpose register R0 to R15.
58 ']' EXPECTED
The indirect register specifier is not correct, the closing ] is missing.
166/167 Assembler and Utilities 139

Error Error Message and Description


59 '#' EXPECTED
The indirect register specifier with an extra immediate offset is wrong. The correct form is
[RWn + #immediate_value]. RWn must be one of the word registers R0 to R15.
60 ILLEGAL IDENTIFIER
The identifiers type is not allowed in the current expression context. The error occurs, if for
example the symbolic name of a LITeral string is used as argument in an expression.
61 ILLEGAL OPERAND FOR THIS OPERATOR
The operand of the given operator is of incorrect type.
„ HIGH/LOW:the operand must be a SFR-symbol or a bit symbol (either module internal or
external.
„ BOF:the operand must be a bit-symbol or bit-address.
An error 61 is issued if the rules above are violated.
62 VALUE TRUNCATION
The constant operand to the operators DATA3, DATA4, DATA8 or DATA16 has a value too
large to be represented by the DATAn-operator. For example DATA4 20 gives a warning,
since the type DATA4 can represent values in range 0 to 15 only.
63 ILLEGAL RELOCATABLE EXPRESSION
The expression violates the rules for relocatable expressions. The error is issued if for
example two relocatable operands are added or multiplied. Subtraction of two relocatable
operands is allowed, assumed that both operands belong to the same section which
produces an absolute result. Addition of one relocatable operand and one absolute operand
is allowed.
64 TYPE OVERRIDE HAS INVALID OPERAND
The assembler has detected an illegal operands to the type override operator. Examples to
this situation are:
„ NEAR / FAR on operands which are not members of some code section.
„ NEAR / FAR / BYTE / WORD on section- or group names
„ BIT on non-bit operands
65 INVALID USE OF 'SHORT' OPERATOR
The SHORT operator must be applied to an operand of type NEAR, which belongs to some
code section. The SHORT operator is to give the assembler a hint that some jump instruction
branches to a forward location which is guaranteed to be in range -128 / +127 words relative
to the current execution point.
6
66 VALUE OUT OF RANGE
The given constant value is out of range. Offsets within data sections may not be greater
than 16383 since a data page cannot exceed 16K in length.

MOV BYTE PTR DPP3:20000,#'Z'; causes ERROR 66


67 ABSOLUTE VALUE (0-15) EXPECTED FOR BITPOSITION
The bit-position specifier in a bit address must be an absolute value in range 0 to 15.
140 Chapter 6. Error Messages

Error Error Message and Description


68 INVALID BASE IN BITADDRESS
69 NOT A BITADDRESSABLE BASE
The base in a bit address is illegal. Valid bases are as follows:
„ addresses from 0FD00H to 0FDFEH
„ addresses from 0FF00H to 0FFDEH
„ SFRSYM.bitpos; SFRSYM must be a bit-addressable SFR
„ bitaddressable_word.bitpos (word from a bit-addressable data section)
„ (external bitaddressable_word).bitpos
The base of a bit address written as base.bitpos must be of type word, being located on an
even address.
70 INVALID TYPE OF EXPRESSION
This error is issued if an addition or subtraction contains a bit operand or when a general
purpose register is in a context where it is not allowed.
71 EXPRESSION WITH FORWARD REFERENCE NOT PERMITTED
Some directives require expressions with no forward references, that means that all
components of the expression must have been previously defined or must be constants.
Examples to these directives are SET, EQU, and ORG.
72 ABSOLUTE EXPRESSION REQUIRED
Some directives require an absolute expressions as argument. Examples of these directives
are DS, DSB, DSW, AT expression.
73 NUMBER OF OPERANDS DOES NOT MATCH INSTRUCTION
The number of operands given to some machine instruction mnemonic does not match the
number of operands required by that instruction.
74 ILLEGAL OPERAND TYPE
The type of the instruction does not match the requirements of that instruction, for example a
bit operand in a word instruction or a GPR in an expression to the DW directive.
75 CAN'T NEST PROCEDURES
An attempt was made to nest procedures. Procedure nesting is not allowed.
76 WRITE ACCESS TO 'READ ONLY' LOCATION

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

Error Error Message and Description


81 ILLEGAL BRANCH TARGET
The branch target of some jump or call instruction is incorrect. For relative branches, the
target must be of type NEAR and within the current code section. Branches of type NEAR
must refer to some near label of a code section.
82 RELATIVE DISTANCE OUT OF RANGE
The branch target for relative branches (CALLR, JMPR) must be in range -128/+127 words
relative to the current execution point. The current execution point is the address of the
instruction following the branch.
83 'TRAP' INSTRUCTION REQUIRED TO ACTIVATE AN INTERRUPT
PROCEDURE
An interrupt procedure (defined via PROC TASK) must be activated by the TRAP instruction
which forces a software interrupt. Activation’s by CALL are illegal and would lead to runtime
stack problems.
84 NEAR REFERENCE TO FAR LOCATION
The target of some JMP or CALL instruction of type NEAR is a label of type FAR. If this is
what you want, use the type override (NEAR PTR, FAR PTR) to create a conforming label
type for the instruction.
85 FAR REFERENCE TO NEAR LOCATION
The target of some JMP or CALL instruction of type FAR is a label of type NEAR. If this is
what you want, use the type override (NEAR PTR, FAR PTR) to create a conforming label
type for the instruction.
86 SECTION LENGTH OVERFLOW
The actual section has exceeded its maximum length (e.g. 16K on data sections or 64K on
code sections).
87 MORE THAN ONE PECDEF/SSKDEF
The PECDEF and SSKDEF directive may be given only once in one source module.
88 ILLEGAL PEC-CHANNEL
The arguments to the PEC directive must be the PEC-related identifiers PECC0 to PECC7
which identify the eight PEC-channels. Other arguments are illegal.
89 PREMATURE END OF FILE (NO END STATEMENT)
The source module must end with the END directive.
90 ILLEGAL ADDRESS IN NONSEGMENTED MODE
The valid 166/167 address space in NONSEGMENTED mode is 64K. The values for
absolute addresses must therefore be not greater than 0FFFFH.
6
91 NOT IN BITADDRESSABLE RANGE (0FD00H-0FDFFH)
A bit-section or bit-addressable data section with an absolute 'AT address' is located at a
wrong address. The valid address range for such sections is 0FD00H to 0FDFFH. Other
areas are not bit-addressable by the 166/167 CPU.
92 ILLEGAL SIMPLE RELOCATABLE EXPRESSION
The expression argument to an ORG directive is illegal. Such expressions must be simple
relocatable, that means it must be either absolute or may contain a relocatable symbol which
must belong to current section.
93 NAME OF A SECTION EXPECTED
The argument list to a GROUP directive must consist of section names or the pseudo
section name SYSTEM. In case of forward references, this error will be detected in pass-2
of assembly.
94 MULTIPLE DPP ASSUME FOR ONE SECTION OR GROUP
It is not allowed to ASSUME more than one DPP to one section or group.
142 Chapter 6. Error Messages

Error Error Message and Description


95 MORE THAN ONE TASK IN ONE MODULE
One single source module may not contain more than one 'PROC TASK' definition.
96 'POF/SOF' INVALID ON GROUP NAME
The operators POF and SOF may not be applied to group name symbols.
97 RESULT EXCEEDS BYTE PRECISION
The result of an expression being part of a DB directive may not exceed the value 255.
98 ILLEGAL TRAP VECTOR
The operand to the TRAP instruction must be of type DATA3 or DATA4 or must be a
constant in range 0 to 127.
99 RELATIVE BRANCH TO EXTERNAL PROCEDURE
A relative branch cannot have an external symbol for target since the linker cannot validate
the correctness of the relative target.
100 ILLEGAL 'DPP' OPERAND
The DPP prefix used in expressions cannot have labels of type NEAR, FAR, SHORT, or
INTERRUPT as its operand. The DPP prefix is valid on data variables only.
101 INVALID SYSTEM ADDRESS
The address argument in a DEFR directive must specify an even internal system address in
range 0FE00H to 0FFDEH.
102 INVALID INTERNAL RAM ADDRESS
The address argument in a DEFA directive must specify an even internal RAM address in
range 0FA00H to 0FDFEH.
103 INVALID BIT ADDRESS
The bit address given in a DEFB directive must be written in the form 'base.bitpos'. 'Base'
must be a bit-addressable SFR and 'bitpos' must be a constant value in range 0 to 15.
104 DATAn-OPERATOR: INCOMPATIBLE OPERAND
This error is issued if the operand of a DATAn operator is used to modify the DATAn-type of
the operand or is applied to a SFR-symbol. Examples:
CON1 EQU DATA4 10
MOV R10,#DATA16 CON1 ; causes error 104
MOV R10,#DATA8 SYSCON ; applied to SFR

6 105 $ABSOLUTE: NOT AN ABSOLUTE MODULE


The control directive $ABSOLUTE was given, but the assembler encountered relocatable
references (relocatable sections or external symbols) within the module. The assembled
source module is not absolute.
106 UNTERMINATED SECTION/PROCEDURE
The end of the source module was reached while assembling without the last recent section
or procedure or both being closed. Add the appropriate ENDP and ENDS directives.
107 REGBANK NAME REQUIRED
The argument given to ‘USING’ is incorrect. It should be the name of a register bank.
108 80C167 INSTRUCTION REQUIRES ‘MOD167’ CONTROL
A 167 instruction requires the MOD167 control to enable the extended 167 instructions.
109 Unused.
110 ACCESS TO NORMAL SFR WITHIN AN ‘EXTENDED’ SEQUENCE
Within an EXTR sequence, you can’t access extended 167 SFR’s only. Any other SFR
must not be accessed within an EXTR sequence.
111 ACCESS TO EXTENDED SFR OUTSIDE AN ‘EXTENDED’ SEQUENCE
Outside an EXTR sequence, you can’t access an extended 167 SFR.
166/167 Assembler and Utilities 143

Error Error Message and Description


112 CAN’T HAVE ‘TASK’ AND ‘INTERRUPT’ IN ONE MODULE
It is not possible to have an interrupt procedure and a task procedure within one source
module.
113 PUBLIC/EXTERN ON REGBANK NOT ALLOWED
A symbol define to be a REGBANK can’t have attributes PUBLIC or EXTERN.
114 REGUSE: UNKNOWN REGISTER
A register to REGUSE must be R0-R15, DPP0-DPP3, MDL, MDH, or MDC. Other register
names are illegal.
115 MULTIPLE REGUSE FOR ONE SYMBOL
A PROC identifier cannot have more than REGUSE attached to it.
116 REGUSE REQUIRES A ‘PROC’ SYMBOL
The identifier given to REGUSE is not the name of a PROC symbol. Check lower case /
upper case spelling of the identifier.
117 STRING TOO LONG
A single string constant cannot have more than 128 characters.

6
144 Chapter 6. Error Messages

6
166/167 Assembler and Utilities 145

Chapter 7. Implementation Specifics


This chapter describes the following implementation-specific topics.

„ 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

166/167 Instruction Set


The assembler A166 accepts all assembly language instruction mnemonics as
defined in the SIEMENS specification (basic instruction set). Additionally, a
number of software instructions are defined which allow the assembler to decide
automatically which basic instruction is to be used in a particular situation. 7
146 Chapter 7. Implementation Specifics

Basic Instruction Set


The following tables show the basic instruction set. For more details in the
instructions, consult the Microcontroller Handbook for the 166/167.

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

Bit Manipulation Instructions


Bit Field Manipulation BFLDH BFLDL
Single Bit Set BSET
Single Bit Clear BCLR
Single Bit Move BMOV
Single Bit Move Of Negated Bit BMOVN
Single Bit AND BAND
Single Bit XOR BXOR
Single Bit OR BOR
Bit Compare BCMP

Comparison and Looping Instructions

7 Word Compare With Post-Increment By 1 Or 2


Word Compare With Post Decrement By 1 Or 2
CMPI1
CMPD1
CMPI2
CMPD2

Shift and Rotate Instructions


Word Right Shift SHR
Word Left Shift SHL
Word Rotate Right ROR
Word Rotate Left ROL
Arithmetic Shift Right (Signed Shift) ASHR
166/167 Assembler and Utilities 147

Move Instructions
Byte/Word Data Move MOVB MOVW
Byte Load & Zero Extend To Word MOVBZ
Byte Load & Sign Extend To Word MOVBS

System Stack Instructions


Push Word Onto System Stack PUSH
Pop Word From System Stack POP
Save Word And Load New Content SCXT

Logical Instructions
Byte/Word Bitwise AND ANDB ANDW
Byte/Word Bitwise XOR XORB XORW
Byte/Word Bitwise OR ORB ORW

Jump and Call Instructions


Conditional Jump To Relative Target JMPR
Conditional Jump To Near Target JMPA JMPI
Unconditional Jump Any Target (Far) JMPS
Jump On Bit Condition JBJNB
Jump On Bit And Clear/Set Bit JBC JNBS
Absolute/ Indirect Near Call CALLA CALLI
Call Near Relative Target CALLR
Call Far Target CALLS
Push Register And Call Near Target PCALL
Activate Interrupt Handler TRAP

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

System Control Instructions


Software Reset Of The CPU SRST
Service Watchdog Timer SRVSDT
Disable Watchdog Timer DISWDT
Enter Idle Mode IDLE
Enter Power Down Mode PWRDN
Signal End Of Initialization EINIT

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

Software Instruction Set


The software instruction set knows all instructions of the hardware instructions
plus some additional ones for easier programming. By means of software
instructions, the assembler can make the decision which instruction to use based
on the operand combinations and their types. The following table gives the
software instructions along with the possible hardware instructions, which a
software instruction may be translated to:

Software Mnemonic Hardware Mnemonic Operation Type


ADD ADDW, ADDB Word, Byte
ADDC ADDCW,ADDCB Word, Byte

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

Software Mnemonic Hardware Mnemonic Operation Type


CALLI Indirect
CALLR Relative
CALLS Segmented (Far) Call
JMP JMPA Absolute
JMPI Indirect
JMPR Relative
JMPS Segmented (Far Jmp)
RET RET Near Return
RETI Interrupt Return
RETS Segmented Return (Far)

Reserved Words in A166


The following shows the reserved words by the assembler. These words are not
allowed to be used for definition of user symbols.

Reserved Words For Directives And Operator Names


ASSUME AT BIT BITADDRESSABLE BITWORD
BOF BYTE CGROUP CODE COMMON DATA
DATA16 DATA3 DATA4 DATA8 DB DBIT
DBPTR DEFA DEFB DEFR DGROUP DPPTR
DS DSB DSPTR DSW DW DWORD
END ENDP ENDS EQ EQU EVEN
EXTERN EXTRN FAR GE GLBUSRSTK GLOBAL
GT HIGH INTNO LABEL LE LIT
LOW LT MOD NAME NE NEAR
NOT NOTHING OR ORG PAG PAGE
PEC ADDRESSABLE PECDEF POF PRIVATE PROC
PTR PUBLIC R REGBANK REGDEF RW
SECTION
SSKDEF
SEG
SYSSTACK
SEGMENT
SYSTEM
SET
TASK
SHORT
TYPEDEC
SOF
UGE
7
UGT ULE ULT USRSTACK W WORD
XOR
150 Chapter 7. Implementation Specifics

Reserved General Purpose Register Names


R0 R1 R2 R3 R4 R5
R6 R7 R8 R9 R10 R11
R12 R13 R14 R15
RL0 RH0 RL1 RH1 RL2 RH2
RL3 RH3 RL4 RH4 RL5 RH5
RL6 RH6 RL7 RH7

Reserved Words Of Assembler Mnemonics And Condition Codes


ADD ADDB ADDC ADDCB ADDCW ADDW
AND ANDB ANDW ASHR BAND BCLR
BCMP BFLDH BFLDL BMOV BMOV BMOVN
BOR BSET BXOR CALL CALLA CALLI
CALLR CALLS CC_C CC_EQ CC_N CC_NC
CC_NE CC_NET CC_NN CC_NV CC_NZ CC_SGE
CC_SGT CC_SLE CC_SLT CC_UC CC_UGE CC_UGT
CC_ULE CC_ULT CC_V CC_Z CMP CMPB
CMPD1 CMPD2 CMPI1 CMPI2 CMPW CPL
CPLB CPLW DISWDT DIV DIVL DIVLU
DIVU EINIT IDLE JB JBC JMP
JMPA JMPI JMPR JMPS JNB JNBS
MOV MOVB MOVBS MOVBZ MOVW MUL
MULU NEG NEGB NEGW NOP OR
ORB ORW PCALL POP PRIOR PUSH
PWRDN RET RETI RETP RETS ROL
ROR SCXT SHL SHR SRST SRVWDT
SUB SUBB SUBC SUBCB SUBCW SUBW
TRAP XOR XORB XORW

7
166/167 Assembler and Utilities 151

Predefined SFR and Bit Names


The assembler A166 knows most of the special function register names (SFR).
These predefined names (often referred to as ‘system names’) can be turned off by
means of the NOMOD166 directive. If NOMOD166 is given, then the user must
include a file containing the system name definitions for SFR’s and probably for
system bits, as required.

Predefined SFR Names And PEC-Channels


ADCIC ADCON ADDAT ADEIC CAPREL CC0
CC0IC CC1 CC10 CC10IC CC11 CC11IC
CC12 CC12I CCC13 CC13I CCC14 CC14IC
CC15 CC15I CCC1IC CC2 CC2IC CC3
CC3IC CC4 CC4IC CC5 CC5IC CC6
CC6IC CC7 CC7IC CC8 CC8IC CC9
CC9IC CCM0 CCM1 CCM2 CCM3 CP
CRI CCSP DP0 DP1 DP2 DP3
DP4 DPP0 DPP1 DPP2 DPP3 DSTP0
DSTP1 DSTP2 DSTP3 DSTP4 DSTP5 DSTP6
DSTP7 MDC MDH MDL ONES P0
P1 P2 P3 P4 P5 PECC0
PECC1 PECC2 PECC3 PECC4 PECC5 PECC6
PECC7 PSW S0BG S0CON S0EIC S0RBUF
S0RIC S0TBUF S0TIC S1BG S1CON S1EIC
S1RBUF S1RIC S1TBUF S1TIC SP SRCP0
SRCP1 SRCP2 SRCP3 SRCP4 SRCP5 SRCP6
SRCP7 STKOV STKUN SYSCON T0 T01CON
T0IC T0REL T1 T1IC T1REL T2
T2CON T2IC T3 T3CON T3IC T4
T4CON T4IC T5 T5CON T5IC T6
T6CON T6IC TFR WDT WDTCON ZEROS

7
152 Chapter 7. Implementation Specifics

Predefined Bit Names


ADBSY ADCH ADCIE ADCIR ADEIE ADEIR
ADM ADST BTYP BYT DISC CC0IE
CC0IR CC10IE CC10IR CC11IE CC11IR CC12IE
CC12IR CC13IE CC13IR CC14IE CC14IR CC15IE
CC15IR CC1IE CC1IR CC2IE CC2IR CC3IE
CC3IR CC4IE CC4IR CC5IE CC5IR CC6IE
CC6IR CC7IE CC7IR CC8IE CC8IR CC9IE
CC9IR CI CLKEN CRIE CRIR E
IEN ILLBUS ILLINA ILLOPA ILVL MCTC
MDRIU MTTC MULIP N NMI PRTFLT
RDYEN ROMEN RWDC S0EIE S0EIR S0FE
S0FEN S0M S0OE S0OEN S0PE S0PEN
REN S0RIE S0RIR S0STP S0TIE S0TIR
S1EIE S1EIR S1FE S1FEN S1M S1OE
S1OEN S1PE S1PEN S1REN S1RIE S1RIR
S1STP S1TIE S1TIR SGTDIS STKOF STKUF
T0IE T0IR T0M T0R T1IE T1IR
T1M T1R T2I T2IE T2IR T2M
T2R T2UD T3I T3IE T3IR T3M
T3OE T3OTL T3R T3UD T3UDE T4I
T4IE T4IR T4M T4R T4UD T5CLR
T5I T5IE T5IR T5M T5R T5SC
T5UD T6I T6IE T6IR T6OE T6OTL
T6R T6SR T6UD UNDOPC USR0 V
WDTIN WDTR WDTREL Z

7
166/167 Assembler and Utilities 153

Chapter 8. L166 Linker/Locator


The L166 linker/locator is used to link or join together object modules that were
created using the A166 assembler or the C166 compiler. Object modules that are
created by these translators are relocatable and cannot be directly executed. They
must be converted into absolute object modules using the L166 linker/locator.

The L166 linker/locator:

„ 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

OH166 dScope In-Circuit


Object Hex Converter HLL Debugger Emulator

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:

„ Combines several program modules into one module, automatically


incorporating modules from the library files,
„ Combines relocatable partial sections of the same section name into a single
segment,
„ Allocates and manipulates the necessary memory for all relocatable and
absolute sections in the application program,
„ Analyzes the program structure and manipulates the data memory using
overlay techniques,
„ Resolves external and public symbols,
„ Defines absolute addresses and computes the addresses of relocatable sections,
„ Produces an absolute object file that contains the entire program,
„ Produces a listing file that contains information about the Link/Locate
procedure, the program symbols, and the cross reference of public and
external symbol names,
„ Detects errors found in the invocation line or during the Link/Locate run.

In addition, the L166 linker/locator provides support for the following:

„ RTX166 Tiny Real-Time Multitasking Operating System,


„ RTX166 Full Real-Time Multitasking Operating System.

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.

“Command-Line Directives” on page 165 provides an alphabetized listing of all of


the directives that you can enter on the command line, along with examples.

“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.

“Application Example” on page 219 contains a program example which shows


how to 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.

While processing object and library files, the L166 linker/locator:

„ Combines program modules,


„ Combines sections,
„ Locates sections,
„ Overlays data memory,
„ Resolves external references,
„ Calculates absolute addresses, 8
„ Generates an absolute object file,
„ Generates a listing (MAP) file.
156 Chapter 8. L166 Linker/Locator

Each of these functions is described in the following sections.

Combining program modules


Input files are processed in the sequence given by the invocation line. With
standard program modules, which are created by C166 or A166, the complete
input file contents are processed. With library files (processed by LIB166) only
those specific modules that contain public symbols for currently unresolved
external symbols are included

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.

A section is a contiguous area of memory that is defined in the source module.


The absolute memory address is assigned by L166 during the locate step. The
section size can be changed by combining sections and by the L166 SECSIZE
control directive. In A166 source modules it is also possible to generate absolute
sections with a fixed section size.

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.

„ BYTE: can be located at any memory address.


166/167 Assembler and Utilities 157

„ WORD: can be located at a memory address that is a multiple of two (0, 2,


4, 6, …).
„ DWORD: can be located at a memory address that is a multiple of four (0, 4,
8, 12, …).
„ PAGE: can be located at a page boundary; this is a start address of an 16 KB
memory page (0, 0x4000, 0x8000, 0xC000, …).
„ SEGMENT: can be located at a segment boundary; this is a start address of
an 64 KB memory segment (0, 0x10000, 0x20000, 0x30000, …).
„ BIT: can be located at any bit address in the bit-addressable RAM.
„ PECADDRESSABLE: can be located at a memory address in segment 0
(address range 0x0000-0xFFFF) that is a multiple of 2 (0, 2, 4, 6, …).

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 types STACK, USERSTK, GLOBUSRSTK are


overlaid but their section length are added together. The new section has the
length of all combined partial sections.

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.

The primary purpose of classes is to collect together (in an arbitrary order)


sections that share a common attribute and to manipulate this collection at locate-
time by specifying only the class name.

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:

„ A group of the type CODE (CGROUP) specifies a collection of sections that


must be located within an 64 KB range. This means that the entire group of
sections can be addressed with offsets from a single code segment. Or, in
other words, the CSP register need not be changed when addressing any
section in one CODE group.
„ A group of the type DATA (DGROUP) specifies a collection of sections that
must be located within an 16 KB range. This means that the entire group of
sections can be addressed with offsets from a single data page. Or, in other
words, the DPP register need not be changed when addressing any section in
one DATA group.
Groups permit efficient addressing within the module. L166 does not manipulate
sections of a group to make sure that they fall within the valid address range.
However, if they do not fit the range, an error message is issued. The sections
included in a group do not have to be contiguous in the 166/167 memory. The
only requirement is that all sections defined in a group must totally fall within one
8 code segment or one data page.
166/167 Assembler and Utilities 159

Allocating 166/167 Memory


After the combination of the sections, their location in the physical 166/167
memory is defined.

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.

Resolving External References

External symbols refers to symbol values or addresses defined in other modules.


A declared external symbol is resolved with a public or global symbol of the same
name. Therefore a public or global symbol must exist in another module for each
external symbol.

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.

Absolute Address Calculation

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.

Producing the Absolute Object File

The executable program is generated in absolute object format. This absolute


object file may contain additional symbol information (DEBUG), for symbolic
program debugging. The symbol information can be suppressed by L166 control
directives. The output file is executable and can be loaded by dScope, an emulator
or be translated by OH166 into a Intel .H86 file and programmed in EPROMs.

Producing a Listing File


L166 produces a listing file that contains the following information:

„ 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

„ A list of all unresolved external symbols. An external symbol is unresolved if


no corresponding public symbol exists in another input file. Each reference to
an unresolved external symbol is displayed as error message at the end of the
listing file.
„ A symbol table which contains the symbol information from the input files.
This information contains the value, type, representation, block length, tgroup
index and symbol name. The symbol table contains the following information
which can be identified by the type: GLOBAL, PUBLIC, SYMBOL, LINE,
BLOCK and BLOCKEND.
„ An alphabetically sorted cross reference report of all PUBLIC and EXTERN
symbols which contains symbol representation, tgroup and module names
where a reference to that symbol exists. In the first module displayed, the
PUBLIC symbol is defined. Further module names display the modules in
which the PUBLIC symbol is used by an external reference. If no PUBLIC
symbol is present, the message “** UNRESOLVED **” is displayed. Some
symbols are generated by L166, in this case “** L166 GENERATED **” is
printed. The cross reference report is produced by entering the control
directive IXREF in the invocation line.
„ Errors detected during the link/locate run are displayed on the screen as well
as at the end of the listing file. A summary of L166 errors, their causes and
recoveries are described in section “Error Messages” on page 210.

Using RTX166 and RTX166 Tiny


Programs you create that utilize the RTX166 and RTX166 Tiny Real-Time
Operating Systems must be linked using the L166 linker/locator. The RTX166
and RTX166TINY directives enable link-time options that are required to
generate RTX166 Full and RTX166 Tiny applications.

Linking Programs with L166


To invoke the L166 linker/locator, type L166 at the DOS prompt followed by
any object modules or directives and press Enter. You may include object
modules and directives on the command line or you may specify a command
response file. Use one of the following command-line formats:
8
L166 †inputlist‡ †TO outputfile‡ †directives‡

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.

The inputlist uses the following general format:

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

8 filename. Multiple modulenames may be separated by commas.


166/167 Assembler and Utilities 163

Long Command Lines


The invocation line for the L166 linker/locator may be very long due to the
number of specified input files and directives. To enter very long command lines,
type the ampersand character (‘&’) at the end of a line to indicate that you want to
enter more arguments. The L166 linker/locator prompts you with a double greater
than sign (‘>>’) to indicate that you may enter more arguments.

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 only the input file C:\MYDIR\PROG.OBJ is processed and


stored in the output file C:\MYDIR\PROG.ABS. The file ..PROG.ABS is
located to absolute addresses.
L166 SAMPLE1.OBJ, SAMPLE2.OBJ, SAMPLE3.OBJ TO SAMPLE.ABS

In this example the input files SAMPLE1.OBJ, SAMPLE2.OBJ and


SAMPLE3.OBJ are linked in the output file SAMPLE.ABS. The output file is
located to absolute addresses.
L166 PROG1.OBJ, PROG2.OBJ, UTILITY.LIB

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.

Entering Names in Lower Case


8 L166 converts the complete input line into upper case. Usually, all SECTION,
CLASS, and GROUP names are generated in uppercase by C166. However, in
some cases you may be required to enter lowercase characters in names or other
items. L166 let you do this allows this by using a string in the command line.
166/167 Assembler and Utilities 165

Example: L166 myfile.obj REGBANK ('lower_regs' (0xFC40))

In this example the register bank name lower_regs is not


converted into uppercase.

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.

Directive and Function


Abbreviation
ASSIGN, AS Define a public symbol at L166 level.
CLASSES, CL Define physical class addresses and class locating order.
DPPUSE, DU Re-assign the DPP registers for C166 NCONST and NDATA
groups.
GROUPS, GR Define physical group addresses and group locating order.
INTNO, IN Define interrupt or trap vectors for interrupt functions.
IXREF, IX Produce a cross reference report.
LINKONLY, LO Suppress the locate process of L166; support for incremental
linkage.
NAME, NA Specify a module name of the output file.
NOAMAKE, NOAM Specify that AMAKE information is excluded in the output file.
NOCASE, NOCA Disable case sensitivity of L166.
NOCOMMENTS, NOCM Remove translator comments in the listing and output file.
NODEFAULTLIBRARY, NLIB C166 run-time libraries are not automatically added.
NOINIT, NOIN Disable memory zero initialization for C166 data sections.
NOLINES, NOLI Remove line numbers in the listing and output file.
NOMAP, NOMA Suppress memory map in the listing file.
NOPUBLICS, NOPU Remove public symbols in the listing and object file.
NOTYPE, NOTY Remove symbolic type information in the object file.
NOVECTAB, NOVT
OBJECTCONTROLS, OC
PAGELENGTH, PL
Remove the interrupt vector table in the output file.
Specify the content of the output file.
Set maximum number of lines per page in the listing file
8
PAGEWIDTH, PW Set the maximum width of the listing file.
PRINT, PR Define the listing filename.
PRINTCONTROLS, PC Specify the content of the listing file.
166 Chapter 8. L166 Linker/Locator

Directive and Function


Abbreviation
PUBLICSONLY, PO Use only the PUBLIC symbols of an input module.
PURGE, PU Remove all debug information in the listing an object file.
REGBANK, RB Define physical register bank addresses and locating order.
REGFILE, RF Specify the name of the file that contains register usage
information.
RESERVE, RS Reserve physical 80C166 memory areas.
RESERVE, RS Reserve physical 80C166 memory areas.
RTX166 Select support for the RTX166 Full Real-Time Operating System.
RTX166TINY Select support for the RTX166 Tiny Real-Time Operating System.
SECSIZE, SS Change the length of sections.
SECTIONS, SE Define physical section addresses and section locating order.
VECTAB, VT Specify a start address for the interrupt vector table.
WARNINGLEVEL, WL Disable linker warning.

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

µVision Control: Options—L166 Linker—Location—Assign 1 / Assign 2

Description: ASSIGN defines a PUBLIC symbol with a numeric value at


L166 level. The defined symbol matches with an unresolved
external symbol.
L166 myfile.obj ASSIGN ('func' (0x2000), 'bitvar'
Example: (0FD20H.2))

In this example the public symbols ‘func’ and ‘bitvar’ are


defined. The value 0x2000 is given as address for ‘func’.
The value 0FD20H.2 is used as bit-address for the symbol
‘bitvar’.

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

µVision Control: Options—L166 Linker—Classes—Class 1-Class 8

Description: CLASSES specifies a physical address range or the locating


order for all sections with the classname given. The
CLASSES control provides an easy way to define the
physical 166/167 memory layout. Refer also to “Definition
of the Physical Memory Layout” on page 203.
L166 myfile.obj CLASSES (NDATA0 (0x20000 - 0x23FFF), &
Examples: NDATA (0x20000 - 0x22000))

In this example all sections with the classname NDATA0


are placed in the address range 0x20000-0x23FFF and all
sections with the classname NDATA are placed in the
address range 0x20000-0x22000.

Default: L166 generates the following default class settings. These


class specifications ensures that specific C166 class names
are located to the correct physical 166/167 address ranges.
CLASSES (NCONST (0 - 0x3FFF),
NCODE (0 - 0xF9FF),
NDATA (04000H - 07FFFH), NDATA0 (04000H - 07FFFH),
SDATA (0C000H - 0FFFFH), SDATA0 (0C000H - 0FFFFH),
IDATA (0FA00H - 0FDFFH), IDATA0 (0FA00H - 0FDFFH),
BIT (0FD00H - 0FDFFH), BIT0 (0FD00H - 0FDFFH),
BDATA (0FD00H - 0FDFFH), BDATA0 (0FD00H - 0FDFFH))

8
170 Chapter 8. L166 Linker/Locator

DPPUSE
Syntax: DPPUSE (dppnr = NDATA (range),
dppnr = NCONST (range))

Abbreviation: DU

µVision Control: Options—L166 Linker—Location—DPP Use 1 and


DPP Use 2

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:

dppnr is the number of a DPP register (0 for DPP0, 1 for


DPP1, 2 for DPP2, 3 for DPP3). range is the address range
where the NDATA or NCONST group should be place.
L166 generates proper initializations for all DPP registers.
The DPP registers are assigned in ascending order to the
NDATA or NCONST group. L166 assigns for an address
range always several DPP registers if the range does not fit
within one 16KB PAGE.
L166 myfile.obj DPPUSE(0=NDATA (20000H-2BFFFH), 3=NCONST
Examples: (0C000H-0EFFFH))

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

L166 myfile.obj DPPUSE (1=NDATA (18000H-1BFFFH), 2=NCONST


(8000H-0EFFFH))

In this example the register DPP1 is used to access the


NDATA addresses. The register DPP1 is therefore loaded
with the value 6 for the address range 18000H - 1BFFFH.
The DPP2 and DPP3 registers are used for accessing
NCONST addresses. DPP2 is loaded with the value 2
pointing to address 08000H. DPP3 is loaded with the value 3
pointing to address 0C000H. This allows the address range
8000H - 0EFFFH to be used for NCONST objects.

See also: GROUPS

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).

You must always state an address range for NDATA and


NCONST. It is not possible to re-assign just one group.

The DPPUSE control also ensures that correct CLASS


definitions for NDATA and NCONST are generated.

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.

If you are converting the address of an automatic object to a


far/huge/xhuge pointer you need to specify the C166
NOFIXDPP directive.

An run-time error can occur, if you are accessing an near 8


object in the DPPUSE area with an far pointer, since the
variable can overlap a 16KB page boundary. Therefore it is
recommended to use huge accessing and to avoid 64KB
overlaps in the DPPUSE range of a group.
172 Chapter 8. L166 Linker/Locator

GROUPS
Syntax: GROUPS (groupname [(address)] [, …])

Abbreviation: GR

µVision Control: Options—L166 Linker—Add’l—enter the GROUPS control


in an additional line.

Description: GROUPS specifies a physical start address or the locating


order for a group name. All sections which are not stated in
the SECTIONS control and which are member of the
specified group are located according the arguments in the
group directive.
L166 myfile.obj GROUPS (NDATA (0x10000), NCONST)
Examples:

All sections which are member of the group NDATA are


located at address 0x10000. After that the group NCONST
is located.

See also: DPPUSE

8
166/167 Assembler and Utilities 173

INTNO
Syntax: INTNO (interruptsymbol (trapnumber) [, …])

Abbreviation: IN

µVision Control: Options—L166 Linker—Add’l—enter the INTNO control in


an additional line.

Description: INTNO defines an trap number for the given interrupt


symbol.
L166 myfile.obj INTNO (TIMER0 (20H))
Example:

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

µVision Control: Options—L166 Linker—Listing—Generate Cross Reference

Description: IXREF controls the generation of the module cross reference


report. If IXREF is entered a cross reference for public and
external symbols is produced. If IXREF is not entered no
cross reference is produced.

The option NOGENERATED suppresses symbols starting


with ‘?’. These question mark symbols are normally
produced by the C166 compiler for calling specific C
functions or passing parameters.

The option NOLIBRARIES suppresses those symbols which


are defined in a library file.
L166 myfile.obj IXREF
Example: L166 myfile.obj IXREF (NOGENERATED)
L166 myfile.obj IXREF (NOLIBRARIES, NOGENERATED)

8
166/167 Assembler and Utilities 175

LINKONLY
Syntax: LINKONLY

Abbreviation: LO

µVision Control: None

Description: The LINKONLY directive allows incremental linkage.


LINKONLY suppresses the locate process of L166. If the
LINKONLY directive is used, the outputfile of the L166
Linker is still relocateable and can be located in a second
Linker/Locator run.
L166 myfile1.obj, myfile2.obj TO file.lnk LINKONLY
Example:

8
176 Chapter 8. L166 Linker/Locator

NAME
Syntax: NAME (modulename)

Abbreviation: NA

µVision Control: Options—L166 Linker—Add’l—enter the NAME control in


an additional line.

Description: NAME defines the modulename for the output file. If no


NAME directive is entered the modulename of the first input
module is accepted as default.
L166 myfile.obj NAME (SAMPLE_PROGRAM)
Example:

In this example the modulename SAMPLE_PROGRAM is


defined for the output file.

8
166/167 Assembler and Utilities 177

NOAMAKE
Abbreviation: None

Arguments: None

µVision Control: Options—L166 Linker—Add’l—enter the NOAMAKE


control in an additional line.

Description: The NOAMAKE directive allows you to direct the linker to


exclude AMAKE information from the generated absolute
object file. By default, the L166 linker/locator generates
object modules that include records containing time and date
information for the source files and include files used to build
specific object modules.
L166 MYPROG.OBJ TO MYPROG.ABS NOAMAKE
Example:

8
178 Chapter 8. L166 Linker/Locator

NOCASE
Syntax: NOCASE

Abbreviation: NOCA

µVision Control: Options—L166 Linker—Add’l—enter the NOCASE control


in an additional line.

Description: NOCASE directs L166 to ignore the case of all symbolic


information which appears in the input files. If NOCASE is
specified all names contained in the input files are converted
to upper-case letters. L166 differs between lower-case and
uppercase if the control directive NOCASE is not stated.
L166 file1.obj,file2.obj NOCASE
Example:

8
166/167 Assembler and Utilities 179

NOCOMMENTS
Syntax: NOCOMMENTS

Abbreviation: NOCM

µVision Control: Options—L166 Linker—Listing / Linking —Comments.

Description: NOCOMMENTS removes the comment records contained in


the input files from the listing file and the output file.
Comment records are added to the object module for various
reasons. A166 and C166 add a comment record identifying
the compiler or assembler that produced it.
L166 file1.obj NOCOMMENTS
Example:

See also: OBJECTCONTROL, PRINTCONTROL, PURGE

8
180 Chapter 8. L166 Linker/Locator

NODEFAULTLIBRARY
Syntax: NODEFAULTLIBRARY

Abbreviation: NLIB

µVision Control: Options—L166 Linker—Linking—Ignore Default Libraries.

Description: NODEFAULTLIBRARY switches off the automatic linking


of C Run-Time-Libraries.

Normally L166 automatically adds the necessary Run- Time-


Libraries to the specified object files. In doing so the memory
model used by C166 and the usage of float or double
arithmetic is considered.

With the DOS command SET C166LIB=drive:\path, the


drive and/or path can be defined in which the library files are
stored. Thus it is unnecessary to locate library files in the
same directory as the object files. Without the C166LIB
environment variable the library files are searched in the
current directory.

Depending on the C166 memory model and the usage of float


or double arithmetic in the C source files, the correct libraries
are automatically chosen. Which libraries are added is
detailed in the table below.

If the control directive NODEFAULTLIBRARY is entered,


the C run-time libraries must be stated in the following
sequence:
L166 inputlist, C166FPS.LIB, C166S.LIB

In this example the SMALL memory model with float


arithmetic is used. If the program contains no float operations
the C166FPS.LIB should be not stated.
8 Example: L166 file1.obj NODEFAULTLIBRARY
166/167 Assembler and Utilities 181

NOINIT
Syntax: NOINIT

Abbreviation: NOIN

µVision Control: Options—L166 Linker—Add’l—enter the NOINIT control in


an additional line.

Description: NOINIT disables the memory zero initialization which is


performed for C166 data variables when the C166 #pragma
NOINIT is not stated. Depending on the section name, L166
generates an address table for memory zero initialization. The
control directive NOINIT suppresses this initialization table.
L166 file1.obj NOINIT
Example:

8
182 Chapter 8. L166 Linker/Locator

NOLINES
Syntax: NOLINES

Abbreviation: NOLI

µVision Control: Options—L166 Linker—Listing / Linking—Line numbers.

Description: NOLINES removes the line number information contained in


the input files from the listing file and the output file. The
line number information is used by dScope or emulators to
display the source text for assembler instructions. This line
information is only required for program debugging and has
no influence on the executable code.
L166 file1.obj NOLINES
Example:

See also: OBJECTCONTROL, PRINTCONTROL, PURGE

8
166/167 Assembler and Utilities 183

NOMAP
Syntax: NOMAP

Abbreviation: NOMA

µVision Control: Options—L166 Linker—Listing—Memory map.

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

µVision Control: Options—L166 Linker—Listing / Linking—Public symbols.

Description: NOPUBLICS removes the debug information for public


symbols contained in the input files from the listing file and
the output file. This debug information is used by dScope or
emulators to calculate and display the value of public
symbols. The public symbol information is only required for
program debugging and has no influence on the executable
code.
L166 file1.obj NOPUBLICS
Example:

See also: OBJECTCONTROL, PRINTCONTROL, PURGE

8
166/167 Assembler and Utilities 185

NOTYPE
Syntax: NOTYPE

Abbreviation: NOTY

µVision Control: Options—L166 Linker—Linking—Include type information.

Description: NOTYPE removes symbol type information for debug


symbols from the output file. The symbol type information is
used by dScope or emulators to display the correct format for
debug objects. C166 generates complete symbol information
up to structure members and parameter passing values. The
symbol type information is only required for program
debugging and has no influence on the executable code.
L166 file1.obj NOTYPE
Example:

See also: OBJECTCONTROL, PRINTCONTROL, PURGE

8
186 Chapter 8. L166 Linker/Locator

NOVECTAB
Syntax: NOVECTAB

Abbreviation: NOVT

µVision Control: Options—L166 Linker—Linking—Generate Interrupt Vector


Table.

Description: NOVECTAB disables the generation of the interrupt vector


table. Without the NOVECTAB directive L166 generates
automatically an interrupt vector table which addresses the
entry points of the defined interrupt procedures. Therefore all
interrupt procedures must have an unique interrupt or trap
number.
L166 file1.obj NOVECTAB
Example:

See Also: VECTAB

8
166/167 Assembler and Utilities 187

OBJECTCONTROLS
Syntax: OBJECTCONTROLS ( subcontrol [, …])

Abbreviation: OC

µVision Control: Options—L166 Linker—Linking—Object Debug


Information.

Description: With the OBJECTCONTROLS directive specific debug


information can be removed from the output file. The
subcontrol option can be one or more of the following
parameters:

Subcontrol Information Removed


NOCOMMENTS Comment records.
NOLINES Line number information.
NOPUBLICS Public symbol information.
NOSYMBOLS Local symbol information.
PURGE Complete debug information.

L166 file1.obj OBJECTCONTROLS (PURGE)


Examples:

In this example the complete debug information is removed


from the output file. However, the debug information is
printed in the L166 listing file.
L166 file2.obj OC (NOLINES, NOSYMBOLS)

With this L166 invocation only line numbers and local debug
symbols are removed from the output file.

See also: NOCOMMENTS, NOLINES, NOPUBLICS,


NOSYMBOLS, PRINTCONTROLS, PURGE

8
188 Chapter 8. L166 Linker/Locator

PAGELENGTH
Syntax: PAGELENGTH (number)

Abbreviation: PL

µVision Control: Options—L166 Linker—Listing—Page Length.

Description: PAGELENGTH sets the maximum number of lines per page


in the listing file to <n>. The minimum page length is 10 lines
per page. Specifying a number less than 10 causes an error
default to the minimum number of 10. If no page length is
specified, the default is 68 lines per page.
L166 sample.obj PAGELENGTH (55)
Example:

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

µVision Control: Options—L166 Linker—Listing—Page Width.

Description: PAGEWIDTH defines the maximum width of a line in the


listing file. The allowable range is 72-132 columns, with the
default being 78.
L166 SAMPLE.OBJ PAGEWIDTH (132)
Example:

This L166 invocation defines a width of 132 characters per


line.

8
190 Chapter 8. L166 Linker/Locator

PRINT
Syntax: PRINT (filename)

Abbreviation: PR

µVision Control: None

Description: PRINT defines the name of the listing file. If no PRINT


directive is entered the name of the listing file is built from the
name of the output file with the extension .M66. The default
is: PRINT (outputfile.M66)
L166 SAMPLE1.OBJ TO MYPROG.ABS PRINT (SAMPLE.LST)
Example:

Without entering PRINT the listing file is produced with the


name MYPROG.M66.

8
166/167 Assembler and Utilities 191

PRINTCONTROLS
Syntax: PRINTCONTROLS ( subcontrol [, …])

Abbreviation: PC

µVision Control: Options—L166 Linker—Linking—Listing File Contents.

Description: With PRINTCONTROLS specific debug information can be


removed from the listing file. The subcontrol option can be
one or more of the following parameters:

Subcontrol Information Removed


NOCOMMENTS Comment records.
NOLINES Line number information.
NOPUBLICS Public symbol information.
NOSYMBOLS Local symbol information.
PURGE Complete debug information.

L166 file1.obj PRINTCONTROLS (PURGE)


Examples:

In this example the complete debug information is removed


from the listing file. However, the debug information is
copied to the L166 output file.
L166 file2.obj PC (NOLINES, NOSYMBOLS)

With this L166 invocation only line numbers and local debug
symbols are removed from the listing file.

See also: NOCOMMENTS, NOLINES, NOPUBLICS,


NOSYMBOLS, OBJECTCONTROLS, PURGE

8
192 Chapter 8. L166 Linker/Locator

PUBLICSONLY
Syntax: PUBLICSONLY (inputfile)

Abbreviation: PO

µVision Control: None

Description: With PUBLICSONLY only the publics symbols of a input


file are used. SECTION/GROUPS/CLASSES the data
content and debug symbols are removed. PUBLICSONLY
can be used to link overlays or generate memory banks in an
application. The PUBLICSONLY directive is used in the
input file list; it is not possible to specify it in the directives
part of the L166 command line.
L166 f1.obj, PUBLICSONLY (f2.obj, f3.obj)
Example: L166 PO (f1.obj), f2.obj, PO (ABC.LIB)

8
166/167 Assembler and Utilities 193

PURGE
Syntax: PURGE

Abbreviation: PU

µVision Control: None

Description: PURGE removes the complete debug information contained


in the input files from the listing file and the output file.
PURGE has the same effect as specifying NOCOMMENTS,
NOLINES, NOPUBLICS and NOSYMBOLS. The debug
information is only required for program debugging and has
no influence on the executable code.
L166 file1.obj PURGE
Example:

See also: NOCOMMENTS, NOLINES, NOPUBLICS,


NOSYMBOLS, OBJECTCONTROL,
PRINTCONTROL

8
194 Chapter 8. L166 Linker/Locator

REGBANK
Abbreviation: RB

Arguments: REGBANK (regbank_name [ (address) ][, …])


REGBANK (base_addr [, regbank_name [ (addr) ][, …]])

µVision Control: Options—L166 Linker—Sections—RegBank.

Description: The REGBANK directive defines the base address, a


physical memory address, or an order for the specified
register banks. Those register banks defined in the
REGBANK directive are allocated sequentially. The first
register bank is usually located at the register base address
(default 0xFC00) which can be also re-defined with the
REGBANK control. The user has the choice to define the
start address of one or more register banks within the location
parameter. If an address is defined the register bank is
located at that memory address. A warning message is
displayed if this register bank overlaps other sections or
register banks.
L166 MYPROG.OBJ REGBANK (0xFB00)
Example:

This example places all registers banks from address


0FB00H upwards.
L166 MYPROG.OBJ REGBANK (?C_MAINREGS(0xFC80),IREGS)

This example locates the register bank ?C_MAINREGS at


address 0xFC80 and places the register bank IREGS after
?C_MAINREGS.

8
166/167 Assembler and Utilities 195

REGFILE
Abbreviation: RF

Arguments: REGFILE (filename)

µVision Control: Options—Make—Misc—Register Optimization.

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

µVision Control: Options—L166 Linker—Location—Reserve 1 and


Reserve 2.

Description: RESERVE prevents L166 from locating sections in the


specified areas of memory. L166 will not use all memory
addresses from startaddress to endaddress inclusive.
startaddress must be less than of equal to endaddress.

If an absolute section uses a reserved memory area, a warning


message is generated.

Example: L166 file1.obj RESERVE (4H-200H)

This example reserves the memory space 0x0004-0x0200.


L166 file2.obj RESERVE (0x200-0x3FFF, 0x10000-0x1FFFF)

This example reserves the memory spaces 0x0200-0x3FFF


and 0x1FFFF-0x20000.

8
166/167 Assembler and Utilities 197

RTX166
Abbreviation: None

Arguments: None

µVision Control: Options—L166 Linker—Linking—RTX166.

Description: The RTX166 directive specifies that the application should


be linked for use with the RTX166 Full Real-Time
Multitasking Operating System. This involves resolving
references within your program to RTX166 Full functions
found in the RTX166 Full library.

See Also: RTX166TINY


L166 RTX_EX1.OBJ RTX166
Example:

8
198 Chapter 8. L166 Linker/Locator

RTX166TINY
Abbreviation: None

Arguments: None

µVision Control: Options—L166 Linker—Linking—RTX166 tiny.

Description: The RTX166TINY directive specifies that the application


should be linked for use with the RTX166 Tiny Real-Time
Multitasking Operating System. This involves resolving
references within your program to RTX166 Tiny functions
found in the RTX166 Tiny library.

See Also: RTX166


L166 RTX_EX1.OBJ RTX166TINY
Example:

8
166/167 Assembler and Utilities 199

SECSIZE
Syntax: SECSIZE (sectionname[%classname] (size))

Abbreviation: SS

µVision Control: Options—L166 Linker—Sections—Secsize 1 and Secsize 2.

Description: SECSIZE allows to specify the memory space used by a


section. For BIT sections the size may be specified in bits
with the “.” operator.

The sectionname and classname specifies any section


containing in the input module.

The value size specifies the change of the section size. There
are three ways of specifying this value:

„ + indicates that the value should be added to the current


section length.
„ - indicates that the value should be subtracted from the
current section length.
„ No sign indicates that the value should become the new
section length.
L166 file1.obj SECSIZE (?C_USERSTACK%NDATA (+ 200H))
Example:

In this example the size of the section ?C_USERSTACK in


the class NDATA is enlarge by 0x200 bytes.

8
200 Chapter 8. L166 Linker/Locator

SECTIONS
Syntax: SECTIONS (sectionname[%classname] [(addr)] [, …])

Abbreviation: SE

µVision Control: Options—L166 Linker—Sections—Section 1-Section 5.

Description: The SECTIONS directive defines a physical memory address


or an order for the specified sections. Those sections defined
in the SECTIONS directive are allocated sequentially. The
first section is always located at the lowest possible address
(usually 0 or implicit specified by a CLASSES or GROUPS
directive), subsequent sections are always located at
ascending addresses.

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.

Example: L166 abc.obj SECTIONS (?PR?ABC%NCODE (0x12000))

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))

In addition to the example above, the section ‘?CO?ABC’


with the class name ‘NCONST’ is after the section
‘?PR?ABC’.
L166 abc.obj SECTIONS (?CO?ABC%NCONST (0x2000), &
?BI0?ABC%BIT0 (0FD20H.5)

In this example the section ?CO?ABC with the class name


NCONST is located to address 0x2000. The section
8 ?BI?ABC with the class name BIT0 is located to bit address
0FD20H.5.
166/167 Assembler and Utilities 201

VECTAB
Abbreviation: VT

Arguments: VECTAB (offset)

µVision Control: Options—L166 Linker—Location—Interrupt Vector Table


Address.

Default: VECTAB (0)

Description: The VECTAB allows to specify a start address for the


interrupt vector table. The default start address for the
interrupt vector table is 0. In some applications—basically
with Monitor-166—it is required to change the start address
of the interrupt vector table.
L166 MYFILE.OBJ VECTAB (8000H)
Example:

See Also: NOVECTAB

8
202 Chapter 8. L166 Linker/Locator

WARNINGLEVEL
Abbreviation: WL

Arguments: A number between 0 and 2.

µVision Control: Options—L166 Linker—Linking—Warnings.

Default: WARNINGLEVEL (2)

Description: The WARNINGLEVEL directive lets you suppress linker


warnings. Refer to “Warnings” on page 210 for a full list of
the linker warnings.

Warning Level Description


0 Disables almost all linker warnings.
1 Lists only those warnings which may generate
incorrect code, including information about data
type mismatches of total different types.
2 (Default) Lists all WARNING messages including warnings
all data type mismatches.

L166 MYFILE.OBJ WL (1)


Example:

8
166/167 Assembler and Utilities 203

Definition of the Physical Memory Layout


The following explains the address assignment of 166/167 programs written in
C166 to different physical memory layouts. Since the memory layout of an
166/167 system depends on the hardware structure, no general rule can be given.
Instead of that, the address assignment is explained with the following examples.

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.

Memory Type Address Range Used by


ROM 0x0000-0x7FFF Interrupt vectors, near addressed area for constant
values, start-up code.
RAM 0x8000-0xFFFF Near addressed data and system page.
ROM 0x10000-0x1FFFF Near addressed executable program code.

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.

Memory Type Address Range Used by


ROM 0x0000-0x7FFF Interrupt vectors, near addressed area for constant
values, start-up code.
RAM 0x8000-0xFFFF Near addressed data and system page.
ROM 0x10000-0x1FFFF Near addressed executable program code.
RAM 0x30000-0x3FFFF Far/huge/xhuge addressed data area.

To specify the memory layout of example 2 the linker/locator L166 should be


invoked with the following CLASSES control directive.
L166 <input_files> .
CLASSES (ICODE (0 - 0x7FFF),
NCONST (0x4000 - 0x7FFF),
FCONST (0 - 0x7FFF), HCONST (0 - 0x7FFF),
NDATA (0x8000 - 0xBFFF), NDATA0 (0x8000 - 0xBFFF),
FDATA (0x30000 - 0x3FFFF), FDATA0 (0x30000 - 0x3FFFF),
HDATA (0x30000 - 0x3FFFF), HDATA0 (0x30000 - 0x3FFFF),
XDATA (0x30000 - 0x3FFFF), XDATA0 (0x30000 - 0x3FFFF),
FCODE (0 - 0x7FFF, 0x10000 - 0x1FFFF))
SECTIONS (?C_INITSEC (0x400), ?C_MEMCLRSEC)

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.

Memory Type Address Range Used by


ROM 0x00000-0x1FFFF Interrupt vectors, near addressed area for constant
values, start-up code, executable program code.
RAM 0x20000-0x27FFF Far/huge/xhuge data RAM.
NVRAM 0x28000-0x2FFFF Non-volatile data RAM, near addressed data, 'far'
addressed NVRAM data.

8
166/167 Assembler and Utilities 205

To specify the memory layout of example 3 the linker/locator L166 should be


invoked with the following CLASSES control directive.
L166 <input_files> .
CLASSES (ICODE (0 - 0x7FFF),
NCONST (0x4000 - 0x7FFF),
FCODE (0 - 0xEFFF, 0x10000 - 0x1FFFF))
FCONST (0 - 0xEFFF, 0x10000 - 0x1FFFF),
HCONST (0 - 0xEFFF, 0x10000 - 0x1FFFF),
XCONST (0 - 0xEFFF, 0x10000 - 0x1FFFF),
FDATA (0x28000 - 0x2FFFF), FDATA0 (0x20000 - 0x27FFF),
HDATA (0x28000 - 0x2FFFF), HDATA0 (0x20000 - 0x27FFF),
XDATA (0x28000 - 0x2FFFF), XDATA0 (0x20000 - 0x27FFF),
NDATA (0x28000 - 0x2BFFF), NDATA0 (0x28000 - 0x2BFFF),
SECTIONS (?C_INITSEC (0x400), ?C_MEMCLRSEC)

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.

See Also: C166 Compiler User’s Guide, Chapter 6. Advanced


Programming Techniques, “Section, Group and Class Names”.

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.

256 KB RAM starts in this


example at 0x40000.

you place elements with


huge or xhuge depending
on the object size. At the
beginning of the RAM 48
KB near space for 16-bit
accesses is available.

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 (Siemens Task Concept)


With TGROUPS L166 supports also the so-called ‘SIEMENS TASK
CONCEPT’. Whereas the Siemens Task Concept limits also the number of
interrupt procedures within a “Siemens Task”, L166 uses TGROUPS only for
isolating symbols, sections and groups from different TGROUPS.

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:

C Program: L166 Invocation:


func1 () { L166 &
int i; { file1.obj },
for (i = 1; i < 100; i++); { file2.obj }
}

main () { We assume that both modules ‘file1.obj’


int i;
and ‘file2.obj’ have a PUBLIC symbol
for (i = 1; i < 100; i++) func (); with the name ‘i’. By using the ‘{’ and
}
‘}’ this PUBLIC symbols are isolated
In this C program the variable ‘i’ in from each other. This means that the
‘func’ has a different location as PUBLIC symbol ‘i’ from ‘file1.obj’
variable ‘i’ in ‘main’. The scope of cannot be accessed from ‘file2.obj’. The
automatic variables is limited to the scope of PUBLIC symbols, sections and
function containing the variable groups is limited to the TGROUP
definition. containing the definitions.

The general format of the L166 invocation with TGROUPS is:


L166 [taskname1] {inputlist [tgroupcontrols]},
[taskname2] {input_list [tgroupcontrols]} { , ... }
inputlist [ TO outputfile ] [ directives ]

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

tgroupcontrols is one of the following L166 control directives which refers to


PUBLIC symbols, sections or groups contained within object files
in this TGROUP: ASSIGN, GROUPS, INTNO, SECSIZE and
SECTIONS.
outputfile is the name of an output file as described in section “Linking
Programs with L166” on page 161.
directives contains L166 control directives as described in section “Linking
Programs with L166” on page 161.

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.

Compatibility to Siemens Tools


TGROUPS provide compatibility to programs which are initial developed with
Siemens Tools. To convert an existing Siemens program from Siemens LNK166
and LOC166 to the L166 invocation format the command lines must be modified
as follows:

Siemens LNK166, LOC166 Invocation Lines:

8 LNK166 MOD_TSK1,MODA_TSK1,MODB_TSK1 TO MOD_TSK1

LNK166 MOD_TSK2,MODA_TSK2,MODB_TSK2 TO MOD_TSK2

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))

L166 Invocation Line with the same effect:


L166 @DEMO.L66

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))

Using TGROUPS with Emulators

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

Warning Warning Message and Description


10 EXISTING SYSTEM STACK DEFINITION EXPANDED
The program contains more than one SSKDEF definition, therefore the SSKDEF
definition with the largest system stack definition is used. L166 reports multiple
SSKDEF directives with this warning.
11 SECTION SIZE UNDERFLOW: OLD SIZE + CHANGE < 0
SECTION: section-name
CLASS: class-name
The size change specified in the SECSIZE control directive causes the section size to
be less than zero.
12 EMPTY SECTIONS ENCOUNTERED
The 166/167 program contains sections with size 0. This sections are not located.
Verify the memory MAP in the listing file.
13 DECREASING SIZE OF SECTION
SECTION: section-name
CLASS: class-name
The size specified in the SECSIZE control has caused L166 to decrease the size of
the specified section.
14 INCOMPATIBLE MEMORY MODEL
MODULE: filename (modulename)
MODEL: memory model
The specified module is not translated in the same memory model as the former L166
input modules. The memory model of the invalid module is displayed. The memory
model of other input modules is displayed in the L166 listing file.
15 INCOMPATIBLE CPU MODE
MODULE: filename (modulename)
MODE: cpu mode
The specified module is not translated with the same 166/167 CPU mode as the
former L166 input modules. The CPU mode of the invalid module is displayed. The
CPU mode of other input modules is displayed in the L166 listing file.
16 UNSUPPORTED SYSDEF VALUE
MODULE: filename (modulename)
The specified module contains a SYSDEF value which is not supported by L166.
17 NO SYSTEM STACK ALLOCATED; EXISTING SYSDEF VAL
IGNORED
You are using the value 7 for the system stack definition. In this case you must ensure
that the system stack is allocated with other methods.
18 NONSEGMENTED CPU MODE SUPPORTS ONLY 64KB MEMORY
In the NONSEGMENT mode you cannot access memory above 0x10000.
19 DPP REASSIGNED, USE C166 WITH NOFIXDPP CONTROL
MODULE: filename (modulename)
This module must be re-translated with the C166 NOFIXDPP directive, since you are
using the L166 DPPUSE directive to re-assign the DPP values.
20 DATA TYPES DIFFERENT
SYMBOL:
MODULE:
symbol-name
module-name
The definition of the specified symbol in the specified module is not identical with the
8
public definition of that symbol. The module which contains the public symbol can be
determined with the IXREF listing. This warning is disabled with WARNINGLEVEL
(0) directive.
212 Chapter 8. L166 Linker/Locator

Warning Warning Message and Description


21 DATA TYPES SLIGHTLY DIFFERENT
SYMBOL: symbol-name
MODULE: module-name
The definition of the specified symbol in the specified module is not 100% identical
with the public definition of that symbol. This warning is the result when unsigned
signed mismatches occur, i.e. unsigned char does not match char. The module which
contains the public symbol can be determined with the IXREF listing. This warning is
disabled with WARNINGLEVEL (1) directive.

Non Fatal Errors


Error Error Message and Description
101 SECTION COMBINATION ERROR
SECTION: section-name
CLASS: class-name
MODULE: filename (modulename)
The attributes of the specified partial section in the specified module cannot be
combined with the attributes of the previous defined partial sections with the same
section and class name. The partial section is ignored.
102 EXTERNAL ATTRIBUTE MISMATCH
SYMBOL: external-name
MODULE: filename (modulename)
The attributes of the specified external symbol in the specified module do not match
the attributes of the previously defined external symbols. The specified symbol is
ignored.
103 EXTERNAL ATTRIBUTE DO NOT MATCH PUBLIC
SYMBOL: public-name
MODULE: filename (modulename)
The attributes of the specified public symbols in the specified module do not match the
attributes of the previous defined external symbols. The specified symbol is ignored.
104 MULTIPLE PUBLIC DEFINITIONS
SYMBOL: public-name
MODULE: filename (modulename)
The specified public symbol in the specified module has already been defined in a
previously processed file.
105 PUBLIC REFERS TO IGNORED SECTION
SYMBOL: public-name
SECTION: section-name
CLASS: class-name
The specified public symbol is defined in the specified segment. It cannot be
processed on account of an error. The public symbol is therefore ignored.

8 106 SECTION OVERFLOW


SECTION:
CLASS:
section-name
class-name
The specified segment is longer than 64 Kbyte and cannot be processed.
166/167 Assembler and Utilities 213

Error Error Message and Description


110 CANNOT FIND SECTION
SECTION: section-name
The specified section is contained in the invocation line but cannot be found in an input
module. The specified section is ignored.
112 SECTION DOES NOT FIT WITHIN GROUP RANGE
SECTION: section-name
CLASS: class-name
The specified section is not located within the group range assigned to this section.
113 SECTION IN LOCATING CONTROL IS ALREADY ABSOLUTE
SECTION: section-name
CLASS: class-name
The specified section is already absolute and cannot be relocated with a L166
directive.
114 SECTION DOES NOT FIT WITHIN SEGMENT BOUNDARY
SECTION: section-name
CLASS: class-name
The specified section is not located within a physical 166/167 segment (64 KB block).
115 SIZE OF DGROUP EXCEEDS 16K
GROUP: group-name (GRP number)
All of the sections that belong to the specified data group do not fit within a data page
(16 KB block).
116 SIZE OF CGROUP EXCEEDS 64K
GROUP: group-name (GRP number)
All of the sections that belong to the specified code group do not fit within a code
segment (64 KB block).
117 GROUP HAS NO CONSTITUENT SECTIONS
GROUP: group-name (GRP number)
The specified group has no sections and is not placed in the output file.
118 REFERENCE MADE TO ERRONEOUS EXTERNAL
SYMBOL: symbol-name
MODULE: filename (modulename)
ADDRESS: code-address
The specified external symbol that was erroneously processed, is referenced at the
specified code address.
119 REFERENCE MADE TO ERRONEOUS SECTION
SECTION: section-name
CLASS: class-name
MODULE: filename (modulename)
ADDRESS: code-address
The specified section processed with an error, is referenced in the specified code
address.
120 CONTENT BELONGS TO ERRONEOUS SECTION
SECTION: section-name
CLASS:
MODULE:
class-name
filename (modulename)
A specified section that was erroneously processed has a code or data content. This
8
section contents are not available.
214 Chapter 8. L166 Linker/Locator

Error Error Message and Description


121 IMPROPER FIXUP
MODULE: filename (modulename)
SECTION: section-name
CLASS: class-name
OFFSET: section-address
After evaluation of absolute fixups, an address is not accessible. The improper
address along with the specific module name, partial section, and section offset
address are displayed. The fixup is not processed.
122 CANNOT FIND MODULE
MODULE: filename (modulename)
The module specified in the invocation line cannot be found in the input file.
123 REGISTERBANK DOES NOT FIT
REGBANK: registerbank_name
The specified register bank does not fit into physical 166/167 memory.
124 INTERRUPT NUMBER ALREADY USED
One interrupt or trap number is assigned to several interrupt procedures. The usage
of the interrupt numbers can be verified in the L166 listing file.
125 INTERRUPT NUMBER NOT DEFINED
For an interrupt procedure is an interrupt or trap number not defined. The usage of the
interrupt numbers can be verified in the L166 listing file.
126 GROUP CONTAINS ERRONEOUS SECTIONS
GROUP: group-name (GRP number)
The specified group contains a section which is processed with an error.
127 UNRESOLVED EXTERNAL SYMBOL
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.
128 REFERENCE MADE TO UNRESOLVED EXTERNAL
SYMBOL: external-name
MODULE: filename (modulname)
ADDRESS: code-address
The specified unresolved external symbol is referenced at the specified code address.
129 SECTION DOES NOT FIT WITHIN PAGE BOUNDARY
SECTION: section-name
CLASS: class-name
The specified section in not located within one data page (16 KB block).
130 DUPLICATE TASK NUMBER
TASK1: task-name
TASK2: task-name
TASKID: task-id-number
Two RTX166 tasks are assigned to the same task_id_number. This is not legal.

8 131 ILLEGAL PRIORITY FOR TASK


TASK:
TASKID:
task-name
task-id-number
The priority for the specified task is not legal.
166/167 Assembler and Utilities 215

Error Error Message and Description


132 ILLEGAL TASKID: RTX166 TINY SUPPORTS ONLY 32 TASKS
TASK: task-name
TASKID: task-id-number
You have assigned a task_id_number in an RTX166 Tiny application which is higher
than 32.
133 MULTIPLE TGROUP DEFINITIONS WITH SAME NAME
MODULE: filename (modulname)
TGROUP: tgroup-name
There are two input files with the same tgroup name in this application.

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

Error Error Message and Description


209 FILE USED IN CONFLICTING CONTEXTS
FILE: filename
A specified filename is used for multiple files or used as an input as well as an output
file.
210 I/O ERROR ON INPUT FILE:
system error message
FILE: filename
An I/O error is detected by accessing an input file. A detailed error description of the
EXCEPTION messages is described afterwards.
211 I/O ERROR ON OUTPUT FILE:
system error message
FILE: filename
An I/O error is detected by accessing an output file. A detailed error description of the
EXCEPTION messages is described afterwards.
212 I/O ERROR ON LISTING FILE:
system error message
FILE: filename
An I/O error is detected by accessing a listing file. A detailed error description of the
EXCEPTION messages is described afterwards.
213 I/O ERROR ON REGFILE:
system error message
FILE: filename
An I/O error is detected by accessing the register definition file. A detailed error
description of the EXCEPTION messages is described afterwards.
214 INPUT PHASE ERROR
MODULE: filename (modulename)
This error occurs when L166 encounters different data during pass two. This error
could be the result of an assembly error.
215 CHECK SUM ERROR
MODULE: filename (modulename)
The check sum does not correspond to the contents of the file.
216 INSUFFICIENT MEMORY
The memory available for the execution of L166 is used up.
217 NO MODULE TO BE PROCESSED
No module to be processed is found in the invocation line.
218 NOT AN OBJECT FILE
FILE: filename
The specified file is not an object file.
219 NOT AN 80166 OBJECT FILE
FILE: filename
The specified file is not a valid 166/167 object file.
220 INVALID INPUT MODULE

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

Error Error Message and Description


222 SECTION/CLASS/GROUP SPECIFIED MORE THAN ONCE
partial command line
The invocation line contains a section, class or group name more than once. The
command line is displayed up to and including the point of error.
224 DUPLICATE KEYWORD OR CONFLICTING CONTROL
partial command line
The same keyword is contained in the invocation line more than once or contradicts
with other keywords. The command line is displayed up to and including the point of
error.
225 ADDRESS ARE NOT IN ASCENDING ORDER
partial command line
The base addresses for the sections or groups are not stated in ascending order
during the L166 control directive. The command line is displayed up to and including
the point of error.
226 SEGMENT ADDRESS INVALID FOR CONTROL
partial command line
The base addresses for the segments are invalid for the location control. The
command line is displayed up to and including the point of error.
227 PARAMETER OUT OF RANGE
partial command line
The specified value for the PAGEWIDTH or PAGELENGTH parameter is out of the
acceptable range. The command line is displayed up to and including the point of
error.
228 MORE THAN 255 TGROUPS
partial command line
The L166 invocation line contains more than 255 TGROUP braces '{', '}'. The
command line is displayed up to and including the point of error.
229 INTERNAL PROCESS ERROR
L166 detects an internal processing error. Please contact your distributor.
230 SYMBOL SPECIFIED MORE THAN ONCE
partial command line
The invocation line contains more than one start address for unnamed segment group.
The command is displayed up to and including the point of error.
232 CANNOT PROCESS OBJECT FILES WITH TGROUPS
FILE: filename
The specified input file contains already TGROUPS and cannot be processed
anymore by L166.
235 USE RTX166 SWITCH
The application uses RTX166 task definitions. This requires to specify the RTX166 or
RTX166TINY directive.
236 TGROUPS AND REGFILE NOT ALLOWED IN COMBINATION
You cannot use TGROUPS and the REGFILE in the same time application.
237 DPP3 MUST POINT TO PAGE 3
partial command line
The DPP3 register is not assigned to PAGE 3 with the DPPUSE directive. The DPP3
must always point to page 3 to allow SFR access.
8
238 DPP ALREADY LOADED WITH A DIFFERENT PAGE VALUE
partial command line
A DPP register is already loaded with a different value due to the previous range
specification in the DPP directive.
218 Chapter 8. L166 Linker/Locator

Error Error Message and Description


239 DPPUSE MUST BE GIVEN FOR NDATA & NCONST GROUP
partial command line
The DPPUSE directive contains only a specification for NDATA or NCONST; however
you must always specify both group ranges.
250 CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED
You have reached the code size limit of the C166 Lite or Evaluation Version.
251 RESTRICTED MODULE IN LIBRARY NOT SUPPORTED
A library contains a module which is translated with a code size restricted version of
A166 or C166.
252 LINKONLY NOT SUPPORTED IN RESTRICTED VERSION
The LINKONLY directive cannot be used with a code size restricted version.

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:

Exception Exception Message and Description


0021H PATH OR FILE NOT FOUND
The specified path or filename is missing.
0026H ILLEGAL FILE ACCESS
An attempt was made to write to or delete a write-protected file.
0029H ACCESS TO FILE DENIED
The file indicated is a directory.
002AH I/O-ERROR
The drive being written to is either full or the drive was not ready.
0101H ILLEGAL CONTEXT
An attempt was made to access a file in an illegal context. Example the printer (:LP:)
was opened for reading.

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

DOS C166 COMPILER V1.00, COMPILATION OF MODULE CSAMPLE1


OBJECT MODULE PLACED IN CSAMPLE1.OBJ
COMPILER INVOKED BY: E:\C166P\BIN\C166.EXE CSAMPLE1.C DEBUG

stmt level source

1 /* CSAMPLE1.C: C166 COMPILER Sample Program */


2 /* Copyright KEIL ELEKTRONIK GmbH, 1992 */
3
4 #include <stdio.h> /* define I/O functions
*/
5
6 extern int getnumber ();
7 extern output (int);
8 extern void serinit (void);
9
10 main () { /* main program */
11 1 int number1, number2, result; /* operation registers */
12 1 bit operation; /* define operation */
13 1
14 1 serinit (); /* serial port control */
15 1
16 1 printf ("\n\nC166 COMPILER demostartion program\n\n");
17 1
18 1 while (1) { /* repeat forever */
19 2 number1 = getnumber (); /* read number1 */
20 2 number2 = getnumber (); /* read number2 */
21 2 printf ("Input operation: '+' (ADD) or '-' (SUB) ? ");
22 2 operation = (getchar () == '+'); /* get operation */
23 2 output (operation ? (number1 + number2) /* perform operation
*/
24 2 : (number1 - number2) );
25 2 }
26 1 }

MODULE INFORMATION: INITIALIZED UNINITIALIZED


CODE SIZE = 78 ------
NEAR-CONST SIZE = 82 ------
FAR-CONST SIZE = ------ ------
NEAR-DATA SIZE = ------ ------
FAR-DATA SIZE = ------ ------
IDATA-DATA SIZE = ------ ------
SDATA-DATA SIZE = ------ ------
BDATA-DATA SIZE = ------ ------
BIT SIZE = ------ ------
INIT'L SIZE = ------ ------

8 END OF MODULE INFORMATION.

C166 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)


166/167 Assembler and Utilities 221

CSAMPLE2.C
C166 COMPILER V1.00, CSAMPLE2 06/05/92 14:05:17 PAGE 1

DOS C166 COMPILER V1.00, COMPILATION OF MODULE CSAMPLE2


OBJECT MODULE PLACED IN CSAMPLE2.OBJ
COMPILER INVOKED BY: E:\C166P\BIN\C166.EXE CSAMPLE2.C DEBUG

stmt level source

1 /* CSAMPLE2.C: C166 COMPILER Sample Program */


2 /* Copyright KEIL ELEKTRONIK GmbH, 1992 */
3
4 #include <stdio.h> /* define I/O functions */
5
6 getline (char *line) {
7 1 while ((*line++ = getchar()) != '\n');
8 1 }
9
10 int atoi (char *line) {
11 1 bit sign;
12 1 int number;
13 1
14 1 /* skip white space */
15 1 for ( ; *line == ' ' || *line == '\n' || *line == '\t'; line++);
16 1
17 1 /* establish sign */
18 1 sign = 1;
19 1 if (*line == '+' || *line == '-') sign = (*line++ == '+');
20 1
21 1 /* compute decimal value */
22 1 for (number=0; *line >= '0' && *line <= '9'; line++)
23 1 number = (number * 10) + (*line - '0');
24 1
25 1 return (sign ? number : -number);
26 1 }
27
28 unsigned int getnumber () {
29 1 char line [40];
30 1
31 1 printf ("Input Number ? ");
32 1 getline (line);
33 1 return (atoi (line));
34 1 }
35
36
37 output (int number) {
38 1 printf ("\nresult: %d\n\n", number);
39 1 }

MODULE INFORMATION: INITIALIZED UNINITIALIZED


CODE SIZE = 186 ------
NEAR-CONST SIZE = 30 ------
FAR-CONST SIZE = ------ ------
NEAR-DATA SIZE = ------ ------
FAR-DATA SIZE = ------ ------
IDATA-DATA SIZE =
SDATA-DATA SIZE =
BDATA-DATA SIZE =
BIT SIZE =
------
------
------
------
------
------
------
------
8
INIT'L SIZE = ------ ------
END OF MODULE INFORMATION.
222 Chapter 8. L166 Linker/Locator

CSAMPLE3.A66
A166 MACRO ASSEMBLER CSAMPLE3 06/05/92 14:05:20 PAGE 1

DOS MACRO ASSEMBLER A166 V1.00


OBJECT MODULE PLACED IN CSAMPLE3.OBJ
ASSEMBLER INVOKED BY:
E:\C166P\BIN\A166.EXE CSAMPLE3.A66 DEBUG

LOC OBJ LINE SOURCE

1 ; CSAMPLE3.A66: A166 ASSEMBLER Sample Program


2 ; Copyright KEIL ELEKTRONIK GmbH, 1992
3
4
5 $SEGMENTED
6 $CASE
7
8 PUBLIC serinit
9 ASSUME DPP3:SYSTEM
10
11 ?PR?SERINIT section code 'NCODE'
12
13 serinit proc near
14
15 ;*******************************
16 ;*** INIT SERIAL INTERFACE 0 ***
17 ;*******************************
18
0000 AFE2 19 BSET P3.10 ; PORT 3.10 OUTPUT LATCH (TXD)
0002 AFE3 20 BSET DP3.10 ; PORT 3.10 DIRECTION CONTROL
(TXD OUTPUT)
0004 BEE3 21 BCLR DP3.11 ; PORT 3.11 DIRECTION CONTROL
(RXD INPUT)
0006 E7B68000 22 MOVB S0TIC,#080H ; SET TRANSMIT INTERRUPT FLAG
000A E7B70000 23 MOVB S0RIC,#000H ; DELETE RECEIVE INTERRUPT FLAG
000E E65A4000 24 MOV S0BG ,#0040H ; SET BAUDRATE TO 9600 BAUD
0012 E6D81180 25 MOV S0CON,#8011H ; SET SERIAL MODE
0016 CB00 26 RET
27
28 serinit endp
29
30 ?PR?SERINIT ENDS
31
32 end

SYMBOL TABLE LISTING


------ ----- -------

N A M E TYPE VALUE I ATTRIBUTES

?PR?SERINIT. . . . ---- ---- SECTION


DP3. . . . . . . . WORD FFC6H A SFR
DPP3 . . . . . . . WORD FE06H A SFR
P3 . . . . . . . . WORD FFC4H A SFR
S0BG . . . . . . . WORD FEB4H A SFR
S0CON. . . . . . . WORD FFB0H A SFR

8 S0RIC. . . .
S0TIC. . . .
serinit. . .
.
.
.
.
.
.
.
.
.
WORD
WORD
NEAR
FF6EH
FF6CH
0000H
A
A
R
SFR
SFR
PUB SEC=?PR?SERINIT

ASSEMBLY COMPLETE. 0 WARNING(S), 0 ERROR(S)


166/167 Assembler and Utilities 223

Linking the Sample Program


L166 LINKER/LOCATOR V1.0 06/05/92 14:05:21 PAGE 1

DOS L166 LINKER/LOCATOR V1.0, INVOKED BY:


E:\C166P\BIN\L166.EXE CSAMPLE1.OBJ, CSAMPLE2.OBJ, CSAMPLE3.OBJ CLASSES (NCODE
(1000H-3FFFH))
>> RESERVE (8H-0BH, 088H-08BH, 0B8H-0BBH) IXREF

CPU MODE: SEGMENTED


MEMORY MODEL: SMALL

INPUT MODULES INCLUDED:


CSAMPLE1.OBJ (CSAMPLE1)
COMMENT TYPE 128: C166 V1.00
CSAMPLE2.OBJ (CSAMPLE2)
COMMENT TYPE 128: C166 V1.00
CSAMPLE3.OBJ (CSAMPLE3)
COMMENT TYPE 128: A166 V1.00
C:\CL166\C166S.LIB (?C_STARTUP)
COMMENT TYPE 128: A166 V1.00
C:\CL166\C166S.LIB (PRINTF)
COMMENT TYPE 128: A166 V1.00
C:\CL166\C166S.LIB (GETCHAR)
COMMENT TYPE 128: C166 V1.00
C:\CL166\C166S.LIB (PUTCHAR)
COMMENT TYPE 128: A166 V1.00
C:\CL166\C166S.LIB (GETKEY)
COMMENT TYPE 128: C166 V1.00

INTERRUPT PROCEDURES OF MODULE: CSAMPLE1 (CSAMPLE1)

INTERRUPT PROCEDURE INT INTERRUPT NAME


=====================================================
C_STARTUP 0 RESET

MEMORY MAP OF MODULE: CSAMPLE1 (CSAMPLE1)

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

05000H 05000H 00001H DATA BYTE --- 3 PUBL NDATA0 ?ND0?GETCHAR


0FA00H 0FBFFH 00200H --- --- --- --- --- * SYSTEM STACK *
0FC00H 0FC1FH 00020H DATA WORD --- --- --- *REG* ?C_MAINREGISTERS

GROUP LIST OF MODULE: CSAMPLE1 (CSAMPLE1)

GROUP NAME TYPE TGR GRP CLASS SECTION NAME


=============================================================
NCODE CODE --- 1 NCODE ?PR?CSAMPLE1
NCODE ?PR?CSAMPLE2
NCODE ?PR?printf
NCODE ?PR?GETCHAR
NCODE ?PR?putchar
NCODE ?PR?GETKEY

NCONST DATA --- 2 NCONST ?NC?CSAMPLE1


NCONST ?NC?CSAMPLE2
NCONST ?NC?PRINTF

NDATA DATA --- 3 NDATA ?C_USERSTACK


NDATA0 ?ND0?GETCHAR

PUBLIC SYMBOLS OF MODULE: CSAMPLE1 (CSAMPLE1)

VALUE PUBLIC SYMBOL NAME REP TGR CLASS SECTION NAME


==============================================================================
=
0008CH ?C_CLRMEMSECSTART VAR --- --- ---
00004H ?C_INITSECSTART VAR --- --- ---
00000H ?C_PAGEDPP1 CONST --- --- ---
00001H ?C_PAGEDPP2 CONST --- --- ---
000BCH ?C_STARTUP LABEL --- ICODE ?C_STARTUP_CODE
00000H RESET INTNO --- --- ---
01534H _getkey LABEL --- NCODE ?PR?GETKEY
05000H _ungetchar_ VAR --- NDATA0 ?ND0?GETCHAR
01066H atoi LABEL --- NCODE ?PR?CSAMPLE2
014D2H getchar LABEL --- NCODE ?PR?GETCHAR
0104EH getline LABEL --- NCODE ?PR?CSAMPLE2
010E2H getnumber LABEL --- NCODE ?PR?CSAMPLE2
01000H main LABEL --- NCODE ?PR?CSAMPLE1
010FCH output LABEL --- NCODE ?PR?CSAMPLE2
0118EH printf LABEL --- NCODE ?PR?printf
01502H putchar LABEL --- NCODE ?PR?putchar
01544H serinit LABEL --- NCODE ?PR?SERINIT
01176H sprintf LABEL --- NCODE ?PR?printf

SYMBOL TABLE OF MODULE: CSAMPLE1 (CSAMPLE1)

VALUE TYPE REP LENGTH TGR SYMBOL NAME


=================================================
01000H GLOBAL LABEL --- --- main

01000H BLOCK LVL=0 004EH --- main


01002H BLOCK LVL=1 0048H ---
0000EH SYMBOL REG --- --- number1
0000DH SYMBOL REG --- --- number2
00000H SYMBOL AUTO --- --- result

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

01022H LINE --- --- --- #22


01036H LINE --- --- --- #23
01048H LINE --- --- --- #25
01048H LINE --- --- --- #18
0104AH LINE --- --- --- #26
--- BLOCKEND LVL=0 --- ---
0104EH PUBLIC LABEL --- --- getline
010E2H PUBLIC LABEL --- --- getnumber
010FCH PUBLIC LABEL --- --- output
01066H PUBLIC LABEL --- --- atoi

0104EH BLOCK LVL=0 0018H --- getline


0000DH SYMBOL REG --- --- line
0104EH LINE --- --- --- #6
01052H LINE --- --- --- #7
01062H LINE --- --- --- #8
--- BLOCKEND LVL=0 --- ---

01066H BLOCK LVL=0 007CH --- atoi


00008H SYMBOL REG --- --- line
01068H BLOCK LVL=1 0076H ---
R15.00 SYMBOL BIT --- --- sign
00006H SYMBOL REG --- --- number
--- BLOCKEND LVL=1 --- ---
01066H LINE --- --- --- #10
0106CH LINE --- --- --- #15
01084H LINE --- --- --- #18
01086H LINE --- --- --- #19
010A6H LINE --- --- --- #22
010AAH LINE --- --- --- #23
010D4H LINE --- --- --- #25
010DEH LINE --- --- --- #26
--- BLOCKEND LVL=0 --- ---

010E2H BLOCK LVL=0 001AH --- getnumber


010E6H BLOCK LVL=1 0010H ---
00000H SYMBOL AUTO --- --- line
--- BLOCKEND LVL=1 --- ---
010E2H LINE --- --- --- #28
010E6H LINE --- --- --- #31
010EEH LINE --- --- --- #32
010F2H LINE --- --- --- #33
010F6H LINE --- --- --- #34
--- BLOCKEND LVL=0 --- ---

010FCH BLOCK LVL=0 000CH --- output


00008H SYMBOL REG --- --- number
010FCH LINE --- --- --- #37
010FCH LINE --- --- --- #38
01106H LINE --- --- --- #39
--- BLOCKEND LVL=0 --- ---
01544H PUBLIC LABEL --- --- serinit

01544H BLOCK LVL=0 0018H --- serinit


01544H LINE --- --- --- #19
01546H LINE --- --- --- #20
01548H LINE --- --- --- #21
0154AH LINE --- --- --- #22
0154EH LINE --- --- --- #23
01552H
01556H
0155AH
01544H
LINE
LINE
LINE
SYMBOL
---
---
---
LABEL
---
---
---
---
---
---
---
---
#24
#25
#26
serinit
8
--- BLOCKEND LVL=0 --- ---
: : : : : :
: : : : : :
: : : : : :
: : : : : :
226 Chapter 8. L166 Linker/Locator

: : : : : :

INTER-MODULE CROSS-REFERENCE LISTING

NAME . . . . . . . REP TGR MODULE NAMES


=========================================

?C_CLRMEMSECSTART. VAR --- ** L166 GENERATED ** ?C_STARTUP


?C_INITSECSTART. . VAR --- ** L166 GENERATED ** ?C_STARTUP
?C_PAGEDPP1. . . . CONST --- ** L166 GENERATED ** ?C_STARTUP
?C_PAGEDPP2. . . . CONST --- ** L166 GENERATED ** ?C_STARTUP
?C_STARTUP . . . . LABEL --- ?C_STARTUP CSAMPLE1
RESET. . . . . . . INTNO --- ?C_STARTUP
_getkey. . . . . . LABEL --- GETKEY GETCHAR
_ungetchar_. . . . VAR --- GETCHAR
atoi . . . . . . . LABEL --- CSAMPLE2
getchar. . . . . . LABEL --- GETCHAR CSAMPLE1 CSAMPLE2
getline. . . . . . LABEL --- CSAMPLE2
getnumber. . . . . LABEL --- CSAMPLE2 CSAMPLE1
main . . . . . . . LABEL --- CSAMPLE1 ?C_STARTUP
output . . . . . . LABEL --- CSAMPLE2 CSAMPLE1
printf . . . . . . LABEL --- PRINTF CSAMPLE1 CSAMPLE2
putchar. . . . . . LABEL --- PUTCHAR GETCHAR PRINTF
serinit. . . . . . LABEL --- CSAMPLE3 CSAMPLE1
sprintf. . . . . . LABEL --- PRINTF

L166 RUN COMPLETE. 0 WARNING(S), 0 ERROR(S)

8
166/167 Assembler and Utilities 227

8
166/167 Assembler and Utilities 229

Appendix A. LIB166 Library Manager


The LIB166 library manager lets you create and maintain library files. A library
file is a formatted collection of one or more object files. Library files provide a
A
convenient method of referencing a large number of object files and can be used by
the L166 linker/locator.

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.

Type EXIT to leave the LIB166 library manager interactive mode.


230 Appendix A. LIB166 Library Manager

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.

Command Abbreviation Description


ADD A Adds an object module to the library file.
CREATE C Creates a new library file.
DELETE D Removes an object module from a library file.
EXIT E Exits the interactive mode of the LIB166 library manager.
HELP H Displays help information for the LIB166 library manager.
LIST L Displays module and public symbol information stored in a
library file.
166/167 Assembler and Utilities 231

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

Adding Object Modules


A The ADD command instructs the LIB166 library manager to add one or more
object modules to a specified library file. The ADD command must be entered in
the following format:

ADD filename †(modulename, …)‡ †, …‡ TO libfile

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

* ADD FPMOD.OBJ TO NEW.LIB


166/167 Assembler and Utilities 233

Removing Object Modules


The DELETE command removes object modules from a library file. This
command must be entered in the following format:
A
DELETE libfile (modulename †, modulename …‡)

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)

* DELETE NEW.LIB (FPMULT, FPDIV)


234 Appendix A. LIB166 Library Manager

Listing Library Contents


A Use the LIST command to direct the LIB166 library manager to generate a listing
of the object modules that are stored in a library file. LIST may be specified on
the command line or after the * prompt in interactive mode. This command has
the following format:

LIST libfile †TO listfile‡ †PUBLICS‡

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>

>LIB166 L UNI.LIB PUBLICS <cr>

Example of the LIB166 output:


LIBRARY: UNI.LIB
SIMPLE
SUBTRACTION
ADDITION
FPMUL
MULTIPLICATION
FPDIV
DIVISION
166/167 Assembler and Utilities 235

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

LIB166 Error Messages


A This chapter lists the fatal and non-fatal errors that may be generated by the
LIB166 library manager during execution. Each section includes a brief
description of the message, as well as corrective actions you can take to eliminate
the error or warning condition.

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.

Error Error Message and Description


215 CHECK SUM ERROR
FILE: filename
The checksum for filename is incorrect. This usually indicates a corrupt file.
216 INSUFFICIENT MEMORY
There is not enough memory for the LIB166 library manager to successfully complete
the requested operation.
217 NOT A LIBRARY
FILE: filename
The filename that was specified is not a library file.
219 NOT AN 80C166 OBJECT FILE
FILE: filename
The filename that was specified is not a valid 80C166 object file.
222 MODULE SPECIFIED MORE THAN ONCE
MODULE: filename (modulename)
The specified modulename is included on the command line more than once.
166/167 Assembler and Utilities 237

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

Error Error Message and Description


221 FILE SPECIFIED MORE THAN ONCE

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

Appendix B. OH166 Object-Hex


Converter
The OH166 Object-HEX Converter creates an Intel HEX file from an absolute
object file. Program code stored in the absolute object file is converted into
hexadecimal values and is output to a file in Intel HEX file format. The Intel
HEX file may then be used by an EPROM programmer or emulator.
B
Using OH166
To invoke the OH166 object-HEX converter from the DOS prompt, type OH166
along with the name of the absolute object file. The OH166 command line must
be entered in the following format:

OH166 abs_file †H167‡†RANGE(start–end)‡†OFFSET(offset)‡†FLASH(fill_byte)‡

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

OH166 Error Messages


This section lists the errors and warnings you may encounter when using the
OH166 Object-HEX Converter. Each error and warning lists the message and a
brief description as well as corrective actions you can take to eliminate the error or
warning condition.

B *** ERROR: ‘<filename>’ - DISK FILE REQUIRED


The specified file is not a disk file. The object file must exist on either a hard
disk or diskette. The console CON:, COM1: or similar devices are not allowed
as input files.
*** ERROR: ADDRESS SPACE OUTSIDE INTEL-H86 RANGE, USE ‘H167’
SWITCH
The object file contains addresses above 1MB; in this case the H167 option
must be selected to generate Intel Hex 386 files.
*** ERROR: CAN’T CREATE FILE ‘<filename>’
The specified file can not be created. This may be a case where a disk or hard
disk is full or if the file already exists and is write protected.
*** ERROR: CAN’T OPEN FILE ‘<filename>’
OH166 failed to find or open the selected object file.
*** ERROR: ILLEGAL OMF166 RECORD <record-type>
The absolute object file contains an invalid record type.
*** I/O-ERROR ON FILE <filename>
*** OH166 ABORTED
While reading from a object file or writing to a HEX file an error occurred.
*** WARNING: UNRESOLVED EXTERNAL(S)
The absolute object file still contains unresolved external definitions. Probably
the file has not yet been processed by L166 without error messages. Therefore
the H86 file can be invalid.
*** WARNING: UNRESOLVED REFERENCE(S)
The absolute object file still contains unresolved references definitions.
Probably the file has not yet been processed by L166 without error messages.
Therefore the H86 file can be invalid.
166/167 Assembler and Utilities 241

Intel HEX File Format


The Intel HEX file is an ASCII text file with lines of text that follow the Intel
HEX file format. Each line in an Intel HEX file contains one HEX record. These
records are made up of hexadecimal numbers that represent machine language
code and/or constant data. Intel HEX files are often used to transfer the program
and data that would be stored in a ROM or EPROM. Most EPROM
programmers or emulators can use Intel HEX files.
B
Record Format
An Intel HEX file is composed of any number of HEX records. Each record is
made up of five fields that are arranged in the following format:

:llaaaatt†dd...‡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:

: is the colon that starts every Intel HEX record.


ll is the record-length field that represents the number of data bytes
(dd) in the record.
aaaa is the address field that represents the starting address for
subsequent data in the record.
tt is the field that represents the HEX record type, which may be
one of the following:

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.

End-of-File (EOF) Record


An Intel HEX file must end with an end-of-file (EOF) record. This record must
have the value 01 in the record type field. An EOF record always appears as
follows:
:00000001FF

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

8086 Segment Address Record


The Intel HEX file contains 8086 segment address records to specify a paragraph
number (one paragraph is 16 Bytes). This record type is replaced by an extended
linear address record if you are using the H167 directive. The paragraph number
is used as offset for all subsequent data records in the HEX file. 8086 segment
address records appear as follows:
:020000021000EC B
where:
02 is the number of data bytes in the record.
0000 is always 0 in a extended 8086 segment record.
02 is the record type 02 (an extended linear address record).
1000 is the paragraph number (address: 0x10000).
EC is the checksum of the record.

Extended Linear Address Record


The Intel HEX file contains extended linear address records when the H167
directive is used. This record specifies the two most significant bytes (bits 16-31)
of the absolute address. This address offset is used for all subsequent data records
in the HEX file. Extended linear address records appear as follows:
:0200000400FFFB

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

Example Intel HEX File


Following is an example of a complete Intel HEX file:
:020000021000EC
:10C20000E0A5E6F6FDFFE0AEE00FE6FCFDFFE6FD93
:10C21000FFFFF6F50EFE4B66F2FA0CFEF2F40EFE90

B :10C22000F04EF05FF06CF07DCA0050C2F086F097DF
:10C23000F04AF054BCF5204830592D02E018BB03F9
:020000020000FC
:04000000FA00000200
:00000001FF
166/167 Assembler and Utilities 245

Appendix C. RTX166 TINY


This appendix describes the functions and the usage of the RTX166 Tiny real-time
operating system.

RTX166 is a multitasking real-time operating system for the 166/167 family.


RTX166 simplifies system and software design of complex and time-critical
projects. RTX166 is a powerful tool to manage several jobs (tasks) on a single
CPU.

RTX166 is available in two versions:

RTX166 Allows round-robin and preemptive task switching with 128


task priorities and can be operated with interrupt functions in
C
parallel. RTX166 supports signal passing; message passing
with a mailbox system and semaphores. The os_wait
function of RTX166 can wait for the following events:
interrupt; timeout; signal from task or interrupt; message
from task or interrupt; semaphore.

RTX166 Tiny Is a subset of RTX166 and can be implemented on a single-


chip system without off-chip memory. However, program
using RTX166 Tiny can access off-chip memory. RTX166
Tiny allows round-robin task switching, supports signal
passing and can be operated with interrupt functions in
parallel. The os_wait function of RTX166 Tiny can wait for
the following events: timeout; interval; signal from task or
interrupt.

This documentation only describes the options of RTX166 Tiny.

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

Simple 80C166 Program Written in C.


int counter;

main () {
while (1) {
counter++;
}
}

This endless loop can be considered as a single task which is executed


continuously.

Round-Robin Task Switching


C RTX166 Tiny allows a quasi-parallel, simultaneous execution of several tasks.
Each task is executed for a predefined timeout period. A timeout suspends the
execution of a task and causes another task to be started. The following example
uses this round-robin task switching technique.

Simple C Program using RTX166


#include <rtx166t.h> /* Definitions for RTX166 Tiny */
int counter0;
int counter1;

job0 () _task_ 0 {

os_create_task (1); /* Mark task 1 as "ready" */

while (1) { /* Endless loop */


counter0++; /* Increment counter 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

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.

Wait for Timeout


RTX166 uses an 166/167 timer in order to generate cyclic interrupts (timer ticks).
The simplest event argument for os_wait is a timeout, where the currently
executing task is interrupted for the specified number of timer ticks. The
following uses timeouts for the time delay. C
Program with os_wait Function
#include <rtx166t.h> /* Definitions for RTX166 Tiny */

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

Wait for Signal


Another event for os_wait is a signal. Signals are used for task coordination: if a
task waits with os_wait until another task issues a signal. If a signal was
previously sent, the task is immediately continued.

Program with Wait for Signal.


#include <rtx166t.h> /* Definitions for 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.

Preemptive Task Switching

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

Generating RTX166 Applications


RTX166 Tiny is completely integrated in C166. For this reason, the generation of
executable RTX166 applications is relatively easy. All examples listed are
complete programs; assembler instructions must not be created. L166 selects the
RTX166 used, checks the system consistency and produces task tables.

Generation Example:
C166 EXAMPLE1.C
L166 EXAMPLE1.OBJ RTX166TINY

C
250 Appendix C. RTX166 TINY

RTX166 Tiny Technical Data


„ Max. 32 tasks can be defined. All tasks can be simultaneously active.
„ Round-robin task switching (timeout can be configured).
„ Wait function allows (all events can be combined):
„ Wait for timeout.
„ Wait for interval.
„ Wait for signal from task or interrupt.

C „ Memory and hardware requirements:


CODE memory: 1500 bytes
DATA memory: 8 + 4 * number_of_tasks Bytes
Timer 0-6 as system clock (Timer 0 is default)
„ Task switching time: 400-4000 states (depending on stack load)
„ System clock (ticks): more than 5000 states (can be defined)
„ Interrupt latency: 20 states
Note: timing is based on external ROM with no waitstates.
1 state = 100ns @ 20MHz

RTX166 Tiny Functions


The following table illustrates all functions of 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

RTX166 Full Technical Data


The RTX166 Full technical data has been summarized for comparison purposes.
However, RTX166 Full is not part of this package.

„ 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.

RTX166 Full Functions


The following table illustrates all functions of RTX166.

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:

„ C166 Compiler Version 1.30 or later.


„ L166 Linker/Locator Version 1.30 or later.
„ A166 Macro Assembler Version 1.30 or later.

The RTX166 Tiny Library files (RTX166TT.LIB, RTX166TS.LIB,


RTX166TL.LIB) must be stored in directory C166\LIB; the path for the C166
runtime libraries must be set.

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:

1. A running task is interrupted if:


„ The task calls the function os_wait and the specified event has not arrived
yet.
„ The task is longer than the defined timeout in the state RUNNING. When
this happens, a round-robin task switch occurs.
2. Another task is started if:
„ No other running (RUNNING) task exists.
„ The task to be started is in the READY or TIMEOUT state.

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>

„ Tasks cannot return a function value (return type “void”).


„ No parameters can be passed to tasks (“void” in parameter list).
„ <task_id> is number assigned by the user (Task_ID) in the area 0-15. Each
task must be assigned a unique non-recurring task_id. This task_id is required
in diverse system functions for identifying the task.
C
NOTE
To minimize the memory requirements of RTX166 Tiny, number your tasks
sequentially starting with 0.

Example:
void example_1 (void) _task_ 8

C166 Specific Support


Although the generation of RTX166 Tiny applications is completely automated,
note the following points when creating programs:

„ Similar to other 80C166 programs, interrupts can be enabled and disabled.


Timer 0 interrupt and the global interrupt enable flag must not be disabled.
„ All C166 memory models can be used.
„ All C166 standard library functions including floating point library can be
used in all tasks without any restrictions.
256 Appendix C. RTX166 TINY

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.

Handling 166/167 Interrupt Control Registers

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

C process the interrupt.

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.

C166 Memory Models


A RTX166 Tiny application can essentially use all memory models supported by
C166 (TINY, SMALL, COMPACT, MEDIUM and LARGE). The selected
memory model only influences, however, the location of the application objects.
The RTX166 Tiny system variables are always stored in registers or in the NEAR
memory (NDATA class). Typical RTX166 Tiny application are normally
implemented in the SMALL model.

Use of the C166 Run-Time Library


All C166 standard library functions including floating point operations can be
used in all tasks without any restrictions.
166/167 Assembler and Utilities 257

RTX166 Tiny System Functions


RTX166 Tiny functions can be directly called from C166. RTX166 Tiny
provides functions for task management, task communication, and other services.

This section contains an extensive description of all RTX166 Tiny system


functions. Each of the following descriptions includes the following points:

„ 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

in an INCLUDE statement at the start if the source program (#include


<rtx166t.h>).

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.

Prototype: int os_clear_signal (int task_id);

Parameter: task_id is the number of the task for which the signal flag is
to be cleared.

Return value: 0: Signal flag was already cleared.


1: Signal flag was set and is now successfully cleared.

C See also:
-1: The specified task does not exist.

os_wait, os_send_signal, isr_send_signal

Example:
void xyz_task (void) _task_ 8 {
/* task code */

/* clear signal flag from task 5 */


os_clear_signal (5);

}
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.

Prototype: int os_create_task (int task_id);

Parameter: task_id identifies the task to be started. The same number as


in the task declaration must be used (0-31).

Return value: 0: Task started successfully (no error).


-1: Task could not be started; no task was declared with this
number (wrong number).
C
See also: os_delete_task

Example:
void count_task (void) _task_ 2 {
/* task code */
}
a

void first_task (void) _task_ 0


{
/* Function 'count_task' is to be started */

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.

Prototype: int os_delay_task (unsigned int timer_ticks);

Parameter: timer_ticks determines the number of timer ticks which must


complete when waiting for timeout or interval. This
parameter is insignificant if wait for timeout (K_TMO) or

C wait for interval (K_IVL) were not specified. The range of


permissible values for timer_ticks is 0-65535.

Return value: TMO_EVENT: A timeout or interval has completed.

See also: os_wait

Example:
void first_task (void) _task_ 0 {
/* task code */

/* delay task for 100 timer ticks */


os_delay_task (100);

/* 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.

Prototype: int os_delete_task (int task_id);

Parameter: task_id identifies the task to be deleted. The same number as


in the task declaration must be used. Only tasks that were
previously started with os_create_task (exception: task 0 is
started after reset), can be deleted with os_delete_task. The
running task can also delete itself.

Return value: 0: Task was stopped successfully.


-1: The specified task was not active or is not defined.
C
See also: os_create_task

NOTE
If a task deletes itself, a task switching subsequently is
executed.

Example:
void first_task (void) _task_ 0 {
/* task code */

/* task stopped itself */


if (os_delete_task (0)) {
/* error handling */
}
}
264 Appendix C. RTX166 TINY

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.

Prototype: int os_running_task_id (void);

Parameter: ---

Return value: 0-31; the task_ID of the task currently being executed by the
processor is returned.

C See also: os_create_task

Example:
void xyz_task (void) _task_ 3 {
unsigned char task_id;

/* task code */

/* check task_id of running task */


task_id = os_running_task_id ();
/* task_id is set to 3 */

}
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.

Prototypes: int os_send_signal (int task_id);


int isr_send_signal (int task_id);

Parameter: task_id is the number of the task to which a signal is to be

Return value:
sent.

0: Signal was sent successfully.


C
1: The signal flag was already set.
-1: The specified task does not exist.

See also: os_wait, os_clear_signal, os_wait_signal

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 */

/* send signal to task 5 */


os_send_signal (5);

void timer2 (void) interrupt 5 {


/* interrupt code */

/* send signal to task 8 */


os_send_signal (8);

}
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.

Prototype: int os_wait (int event_selector,


unsigned int timer_ticks,
int dummy);

C Parameter: event_selector specifies the events which are to be waited


for. The event_selector is formed by addition of the desired
events. File RTX166T.H defines the possible events:

K_IVL Wait for interval


K_SIG Wait for signal
K_TMO Wait for timeout

Example 1: Wait for interval: event_selector = K_IVL.

Example 2: Wait for timeout or signal:


event_selector = K_TMO + K_SIG.

timer_ticks determines the number of timer ticks which must


complete when waiting for timeout or interval. This
parameter is insignificant if wait for timeout (K_TMO) or
wait for interval (K_IVL) were not specified. The range of
permissible values for timer_ticks is 0-65535.

The parameter dummy is necessary for compatibility to


RTX166. The value is irrelevant for RTX166 Tiny.

Return value: SIG_EVENT: A signal was received.


TMO_EVENT: A timeout or interval has completed.
NOT_OK: The value for the event_selector is
illegal.

See also: os_send_signal, os_clear_signal, isr_send_signal,


os_delay_task, os_wait_signal.
166/167 Assembler and Utilities 267

Example:
void count_task (void) _task_ 2 {

while (1) { /* endless loop */


/* wait for signal or timeout */
switch (os_wait (K_SIG + K_TMO, 10, 0) {
case TMO_EVENT: {
/* If no signal occurs within 10 timer ticks,
a timeout occurs and this part of the program is
executed. */
break;

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.

Prototype: int os_wait_signal (void);

Parameter: none

C Return value:

See also:
SIG_EVENT: A signal was received.

os_send_signal, os_clear_signal, isr_send_signal, os_wait.

Example:
void task_xyz (void) _task_ 5 {
/* task code */

/* wait for a signal */


os_wait_signal (100);

/* 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.

The following system values can be configured:

„ Interval for the system timer (timer ticks).


„ Timeout and enable for round-robin task switching.
„ The CPU timer used by RTX166 Tiny C
CONF_TNY.A66
The file CONF_TNY.A66 contains some EQU directives for the configuration of
the system values. The function of the EQU directives is described below:

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.

STACKTOP STACKTOP STACKTOP


Stack Area Stack Area
for Task 1 for Task 1

Stack Area
for Task 2

Stack Area
for Task 1

Stack Area Stack Area


for Task 2 for Task 2

Stack Area Stack Area Stack Area


for Task 3 for Task 3 for Task 3
STACKBOT STACKBOT STACKBOT

Stack Assignment for Stack Assignment for Stack Assignment for


Task0 = Running Task Task1 = Running Task Task2 = Running Task

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

Optimizing RTX166 Tiny Applications


The following notes should be considered in order to create a more efficient
application with RTX166 Tiny:

„ When possible, do not use round-robin task switching.


Tasks which use round-robin task switching require 13 bytes stack area in
order to store the context of the task. This context storage is omitted if the
task switching is triggered by the os_wait function. Moreover, the os_wait
function usually produces a considerably improved system reaction time since
a task which is waiting for execution (READY) must not wait for the timeout
of the currently running (RUNNING) task.
„ Do not select the time of the timer interrupts (timer ticks) too small.
In order to achieve a possibly low system overhead, the value of TIMER_INT
C
should not be selected too small. The timer interrupt function processing lasts
approximately 100-300 CPU states depending on the number of defined tasks.

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 Start State Wait for Sig Timer USRSP SYSSP


Event
0 00B0H DELETED 0 -82 906EH FC00H
1 01B2H TIMEOUT SIGNAL 0 -82 9068H FC00H
2 00D8H WAITING TIMEOUT 0 918 9042H FBECH
3 03BEH DELETED 0 -82 903CH FBEAH
4 03FAH WAITING TIMEOUT 0 423 903CH FBEAH
5 048CH WAITING TIMEOUT 0 3 9036H FBE8H
6 0198H DELETED 0 -82 806EH FA00H

C Interpretation of the outputs of the debug function:

TaskID Indicates the number which was used in the task definition.

Start Indicates the start address of the task function.

State Indicates the state of the task (see task state).

Wait for Event Indicates which events the task is currently waiting for.

Signal Indicates the state of the signal flag.

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: The first RTX166 Program


The program RTX_EX1.C demonstrates round-robin task switching using
RTX166 tiny. Refer to “Round-Robin Task Switching” on page 246 for more
information about task switching.

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

The program RTX_EX1 is stored in the directory C166\EXAMPLES\RTX_EX1.

To select this directory type:


CD \C166\EXAMPLES\RTX_EX1

To translate the C source file type:


C166 RTX_EX1.C

To link and generate the RTX166 tiny application type:

C L166 RTX_EX1.OBJ RTX166TINY

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.

Define watch variables and start program execution:


>WS counter0
>WS counter1
>WS counter2
>G

The result of the program is simple: counter0, counter1 and counter2 are
incremented quasi-parallel. In the EXE window each task switch is reported.

To display the task status of the application type:


Ctrl+C
Click Toolbox button <Task State>

To quit dScope type:


>EXIT
166/167 Assembler and Utilities 275

RTX_EX2: A simple RTX166 Application


The application program RTX_EX2.C demonstrates the usage of the os_wait
function and signal passing. These functions are described in chapter
“Introduction”.

RTX_EX2.C
1 /*********************************************************************/
2 /* */
3 /* RTX_EX2.C: A RTX166 Application */
4 /* */
5 /*********************************************************************/
6
7
8
9
#pragma CODE DEBUG

#include <rtx166t.h> /* RTX166 tiny functions & defines */


C
10
11 int counter0; /* counter for task 0 */
12 int counter1; /* counter for task 1 */
13 int counter2; /* counter for task 2 */
14 int counter3; /* counter for task 2 */
15
16 /*********************************************************************/
17 /* Task 0 'job0': RTX166 tiny starts execution with task 0 */
18 /*********************************************************************/
19 job0 () _task_ 0 {
20 1 os_create_task (1); /* start task 1 */
21 1 os_create_task (2); /* start task 2 */
22 1 os_create_task (3); /* start task 3 */
23 1
24 1 while (1) { /* endless loop */
25 2 counter0++; /* increment counter 0 */
26 2 os_wait (K_TMO, 5, 0); /* wait for timeout: 5 ticks */
27 2 }
28 1 }
29
30 /*************************************************************************/
31 /* Task 1 'job1': RTX166 tiny starts this task with os_create_task (1) */
32 /*************************************************************************/
33 job1 () _task_ 1 {
34 1 while (1) { /* endless loop */
35 2 counter1++; /* increment counter 1 */
36 2 os_wait (K_TMO, 10, 0); /* wait for timeout: 10 ticks */
37 2 }
38 1 }
39
40 /*************************************************************************/
41 /* Task 2 'job2': RTX166 tiny starts this task with os_create_task (2) */
42 /*************************************************************************/
43 job2 () _task_ 2 {
44 1 while (1) { /* endless loop */
45 2 counter2++; /* increment counter 2 */
46 2 if (counter2 == 0) { /* signal overflow of counter 2 */
47 3 os_send_signal (3); /* to task 3 */
48 3 }
49 2 }
50 1 }
51
52 /************************************************************************/
53 /* Task 3 'job3': RTX166 tiny starts this task with os_create_task (3) */
54 /************************************************************************/
55 job3 () _task_ 3 {
276 Appendix C. RTX166 TINY

56 1 while (1) { /* endless loop */


57 2 os_wait (K_SIG, 0, 0); /* wait for signal */
58 2 counter3++; /* process overflow from counter 2 */
59 2 }
60 1 }

Running RTX_EX2

The program RTX_EX2 is stored in the directory C166\EXAMPLES\RTX_EX2.

To select this directory type:


CD \C166\EXAMPLES\RTX_EX2

C To translate the C source file type:


C166 RTX_EX2.C

To link and generate the RTX166 tiny application type:


L166 RTX_EX2.OBJ RTX166TINY

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.

Define watch variables and start program execution:


>WS counter0
>WS counter1
>WS counter2
>WS counter3
>G

The result of the application program RTX_EX2:

„ counter0 is incremented every 5 RTX166 timer ticks.


„ counter1 is incremented every 10 RTX166 timer ticks.
„ counter2 is incremented as fast as possible. This task gets most of the
available CPU time.
„ counter3 processes the overflow of counter2.
166/167 Assembler and Utilities 277

To display the task status of the application type:


Ctrl+C
Click Toolbox button <Task State>

To quit dScope type:


>EXIT

Traffic: Pedestrian Traffic Light Controller


The both preceding examples show basic features of RTX166 tiny. Even without
RTX166, this examples can be coded easily. The following application “Traffic”
cannot be simply implemented without a multitasking Real Time Operating
System like RTX166. Although the traffic light controller is much to simple to be
C
realize with an 166/167 microcontroller, it shows with an easy example the
principles of programming an RTX166 application.

“Traffic” is a time-controlled Pedestrian Traffic Light Controller. Between an


user-defined clock time interval the traffic light is operating. Outside this time
interval the yellow light is blinking. If a pedestrian pushes the request button the
traffic light goes immediately into the ‘walk’ state. Otherwise the traffic light
works continuously.

Commands to the Traffic Light Controller

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:

Display Display clock, start and end time.


Example: D <cr>

Time Set the current time in 24-hour format.


Example: T 12:25:40 <cr>

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>

End Set the end time in 24-hour format.


Example: E 22:30:00 <cr>
278 Appendix C. RTX166 TINY

Software for the Traffic Light Controller

The whole application is coded in three modules which are described below:

SERIAL.C This module implements an interrupt driven serial interface


and contains the functions putchar () and getkey (). The high-
level I/O functions printf () and getline () are calling this basic
I/O routines. Our application operates also without this
module, but with lower performance.

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:

„ Task 0 “Initialize”: initialize the serial interface and start


all other tasks. Task 0 deletes its self, since initialization
is only needed once.
„ Task 1 “Command”: is the command processor of our
traffic light controller. This task controls and processes
all commands received via the serial interface.
„ Task 2 “Clock”: controls the clock time.
„ Task 3 “Blinking”: yellow light is blinking when the
clock time is outside the active time range.
„ Task 4 “Lights”: controls the traffic light phases while
the clock time is between start time and end time (the
traffic light is active).
„ Task 5 “Keyread”: read the pedestrian push button and
send signal to Task “Lights”.
„ Task 6 “Get_ESC”: if an ESC character is input, the
display command is terminated. This task is only active if
task Command processes the display command.

Translation

The program Traffic is stored in the directory C166\EXAMPLES\TRAFFIC.

To select this directory type:


166/167 Assembler and Utilities 279

CD \C166\EXAMPLES\TRAFFIC

To translate the C source files type:


C166 TRAFFIC.C
C166 SERIAL.C
C166 GETLINE.C

To link the modules type:


L166 TRAFFIC.OBJ, SERIAL.OBJ, GETLINE.OBJ RTX166TINY

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.

The following shows the listing files of the TRAFFIC application.

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

33 #define INIT 0 /* task number of task: init */


34 #define COMMAND 1 /* task number of task: command */
35 #define CLOCK 2 /* task number of task: clock */
36 #define BLINKING 3 /* task number of task: blinking */
37 #define LIGHTS 4 /* task number of task: signal */
38 #define KEYREAD 5 /* task number of task: keyread */
39 #define GET_ESC 6 /* task number of task: get_escape */
40
41 struct time { /* structure of the time record */
42 unsigned char hour; /* hour */
43 unsigned char min; /* minute */
44 unsigned char sec; /* second */
45 };
46
47 struct time ctime = { 12, 0, 0 }; /* storage for clock time values */
48 struct time start = { 7, 30, 0 }; /* storage for start time values */
49 struct time end = { 18, 30, 0 }; /* storage for end time values */
50
51 sbit red = P2^1; /* I/O Pin: red lamp output */
52 sbit yellow = P2^5; /* I/O Pin: yellow lamp output */

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

173 4 os_wait (K_SIG, 0, 0); /* wait for time change or ESC */


174 4 }
175 3
176 3 os_delete_task (GET_ESC); /* ESC check not longer needed */
177 3 display_time = 0; /* clear display time flag */
178 3 printf ("\n\n");
179 3 break;
180 3
181 3 case 'T': /* Set Time Command */
182 3 if (readtime (&inline[i+1])) { /* read time input and */
183 4 ctime.hour = rtime.hour; /* store in 'ctime' */
184 4 ctime.min = rtime.min;
185 4 ctime.sec = rtime.sec;
186 4 }
187 3 break;
188 3
189 3 case 'E': /* Set End Time Command */
190 3 if (readtime (&inline[i+1])) { /* read time input and */
191 4 end.hour = rtime.hour; /* store in 'end' */
192 4 end.min = rtime.min;

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

243 2 yellow = 0; /* yellow light off */


244 2 os_wait (K_TMO, 300, 0); /* wait for timeout: 300 ticks */
245 2 if (signalon ()) { /* if blinking time over */
246 3 os_create_task (LIGHTS); /* start lights */
247 3 os_delete_task (BLINKING); /* and stop blinking */
248 3 }
249 2 }
250 1 }
251
252
253 /*********************************************************************/
254 /*Task 4'lights':executes if current time is between start & end time*/
255 /*********************************************************************/
256 lights () _task_ LIGHTS { /* traffic light operation */
257 1 red = 1; /* red & stop lights on */
258 1 yellow = 0;
259 1 green = 0;
260 1 stop = 1;
261 1 walk = 0;
262 1 while (1) { /* endless loop */

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

size of serial receiving buffer


*/
*/

*/
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

135 1 S0TIC = 0x45; /* transmit interrupt enable; ILVL = 1; GLVL = 1 */


136 1 S0RIC = 0x46; /* receive interrupt enable; ILVL = 1; GLVL = 2 */
137 1 S0BG = 0x0A; /* set baudrate to 57600 BAUD */
138 1 S0CON = 0x8011; /* set serial mode */
139 1 }

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:

„ Display memory contents in hexadecimal and ASCII format.


„ Change memory contents interactively.
„ Display and change CPU registers and Special Function Register contents.
„ Initialize the 166/167 memory with a constant value.
„ Disassemble memory contents in 166/167 mnemonics.
„ In-line Assembler.
„ Real-Time Go with up to 16 fixed and 1 temporary break point.
„ Control commands for up to 16 fixed break points. D
„ Single step execution with the option to execute a subroutine as one step.
„ Down-Load and Up-Load for Intel HEX and Object files.
„ Command menu (help).

Hardware and Software Requirements


The following requirements must be met for Monitor-166 to operate correctly:

„ Siemens 166/167/165/163 CPU or ST10


„ 5 Kbyte EPROM starting at address 0 (loaded with Monitor-166 software)
„ Serial interface for communication with the PC.

Monitor-166 requires following hardware components of the 166/167 system:

„ 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

„ 5 Kbyte external code memory (EPROM).

All other hardware components can be used by the application.

MON166.EXE: DOS Monitor Driver


MON166 is invoked by entering its name: MON166. The communication with
the serial interface is performed with the hardware interrupt. Various parameters
can be stated in the invocation line. These parameters change the working method
of MON166.

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.

D The general syntax of the MON166 invocation is as follows:


MON166 [ parameter ] <cr>

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.

NOINT the serial interface is polled. No hardware interrupt system is


necessary. The abbreviation of NOINT is N.
BAUDRATE (bps) allows the setting of the transfer baudrate. If this option
is omitted, 9600 bps is used. bps specifies the baudrate. Possible
values are: 300, 600, 1200, 2400, 4800, 9600, 19200, 38400 and
57600. The abbreviation of BAUDRATE is BR.
166/167 Assembler and Utilities 291

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

After invocation, MON166 displays the message:


MS-DOS MON166

INSTALLED FOR PC/XT/AT (COM Line 1) USING HARDWARE INTERRUPT SERVICE


BAUDRATE: 9600 (DEFAULT) D
*** MONITOR MODE *** or *** TERMINAL MODE ***

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

MON166.EXE Control Keys


Command lines can be manipulated using the following control keys:

Control Key Function


Enter Execute entire entry line.
<-- Backspace Delete character in front of the cursor.
DEL, Ctrl+D Delete character below the cursor.
Ctrl+A Delete all characters to the right of the cursor.
Ctrl+X Delete all characters to the left of the cursor.
Ctrl+Z Delete entire entry line.
Escape, Ctrl+C Abort entry and start new entry line.
Home Position cursor at the beginning of the entry line.
End Position cursor at the end of the entry line.
Insert Toggle between insert/overwrite mode.
<-- Cursor left Move cursor a position to the left.

D --> Cursor right


Cursor up
Cursor down
Move cursor a position to the right.
Assume an prior entry line in the line editor.
Assume a later entry line in the line editor.

The following control the output on the console:

Control Key Function


Ctrl+S Stops output to the console and suspends the execution
of the current command.
Ctrl+Q Cancels the effect of CTRL+S. Output to the console
resumes.
Ctrl+C, ESC Terminates the execution of a command and returns to
the command line interpreter. MON166 produces the
following console message:

*** TERMINATED ***


#
166/167 Assembler and Utilities 293

MON166.EXE Terminal Control Codes


List of all MON166 Terminal Control Codes:

Screen control codes Function


00H null
07H bell
08H backspace
09H tab
0AH line feed
0BH cursor up
0CH cursor right
0DH carriage return
14H cursor right
17H erase to end of screen
18H erase to end of line
1AH
1BH 28H (ESC '(' )
1BH 29H (ESC ')' )
clear screen and home
highlight on
highlight off
D
1BH 30H (ESC '0' ) underline
1BH 31H (ESC '1' ) underline off
1BH 32H (ESC '2' ) cursor on
1BH 33H (ESC '3' ) cursor off
1BH 3DH (ESC '=' ) set cursor position (ADM-3A Modus)
1BH 41H (ESC 'A' ) cursor up
1BH 42H (ESC 'B' ) cursor down
1BH 43H (ESC 'C' ) cursor right
1BH 44H (ESC 'D' ) cursor left
1BH 45H (ESC 'E' ) clear screen and home
1BH 48H (ESC 'H' ) cursor home
1BH 4AH (ESC 'J' ) erase to end of screen
1BH 4BH (ESC 'K' ) erase to end of line
1BH 4CH (ESC 'L' ) insert line
1BH 4DH (ESC 'M' ) delete line
1BH 59H (ESC 'Y' ) set cursor position (VT-52 Modus)
1BH 62H (ESC 'b' ) erase to beginning of screen
1BH 6AH (ESC 'j' ) save cursor position
1BH 6BH (ESC 'k' ) restore cursor position
1BH 6CH (ESC 'l' ) delete line
1BH 6FH (ESC 'o' ) erase to beginning of line
1BH 70H (ESC 'p' ) reverse on
294 Appendix D. Monitor-166

Screen control codes Function


1BH 71H (ESC 'q' ) reverse off
1BH 76H (ESC 'v' ) scroll on
1BH 77H (ESC 'w' ) scroll off
1BH 7AH (ESC 'z' ) reset terminal
1CH cursor down
1DH cursor home
1EH cursor up
1FH cursor left

Serial Transmission Line


Monitor-166 requires only the signals TRANSMIT DATA, RECEIVE DATA and
SIGNAL GROUND from the RS232 or V.24 line. However, in most cases, some
additional connections are necessary in the serial connectors, to enable transmit
and receive data.
D PIN connections of various computer systems

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

#FILL 2000 4000 0 <cr>

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:

F1: Terminate MON166 and Return to DOS

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

F2: Transmit the Content of a File

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>

F3: Protocol the Screen Output

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.

If a file with the entered name already exists, the question:


Overwrite existing file (y or [n])?

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

Help: Display Command Menu

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

Exit: Exit MON166 and Return to DOS

Syntax Meaning
EXIT Exit MON166 and return to DOS
298 Appendix D. Monitor-166

Displaying and Changing Memory


The following commands let you change memory and display memory areas of the
166.

DISPLAY: Display Memory

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.

D If no end address is entered 4 lines are displayed.

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)

ENTER: Change Memory Interactively

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:

„ RETURN: the current content remains unchanged.


„ PERIOD (‘.’): the Enter command is terminated.
„ VALUE: after RETURN the new value is written into the memory.
166/167 Assembler and Utilities 299

FILL: Fill Memory

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

Unassemble: Display Assembler Mnemonics

Syntax Meaning

D
U [startaddr [,endaddr]] Disassemble Memory

Unassemble displays the memory contents as 166/167 assembler mnemonics.


The start and end address is optional and if not specified the last address used by
previous Unassemble command will be assumed. The disassembly includes also
SFR registers if enough information is present.

Examples:
#U
#U 100
#U 1000, 1100

Assemble: Load 166/167 Instructions into Memory

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

The following options can be used:

„ RETURN: the current memory contents are not changed.


„ PERIOD(‘.’): the command is terminated.
„ INSTRUCTION: The previous 166/167 instruction is replaced by the
present instruction. An error message is issued if the instruction is invalid.

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
#

D eXamine: Display and Change Processor Registers

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:

„ BS BREAKPOINT SET define a break point.


„ BK BREAKPOINT KILL kill break point(s).
„ BL BREAKPOINT LIST list break points.
„ BE BREAKPOINT ENABLE activate break point(s).
„ BD BREAKPOINT DISABLE temporarily deactivate break point(s).

To perform a breakpoint Monitor-166 writes a TRAP instruction into the user


program. The advantage is, that no additional hardware is required for the break
logic. But you can set breakpoints only in RAM memory. Also the trap vector
cannot be used by the application program. Usually the NMI trap is used for
D breakpoints. Therefore the 4 memory bytes from 8H-0BH cannot be used by the
application program. On the other hand, a high to low transition at the NMI# pin
forces a program stop.

BreakSet: Define Breakpoint

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:

„ An attempt is made to define more than 16 break points.


„ The break address is already defined.
„ The break address is illegal (odd address).

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>

BreakKill: Kill Breakpoint

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.

BreakDisable: Disable Breakpoint

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

BreakEnable: Enable Breakpoint

D Syntax
BE ALL
Meaning
enable all break points
BE bp [, …] enable named break points

BreakEnable enables breakpoints. The ALL option enables all breakpoints. A


single breakpoint can be enabled by specifying the breakpoint number (not
address). Several break points can be specified by separating each breakpoint
number with a comma. BreakList displays the defined breakpoint numbers.

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:

„ Go Execute an 166/167 program in real-time.


„ Trace Single step through an 166/167 program.
„ Procedure Single step over a subroutine (CALL) as one step.

Go: Real-time Program Execution

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.

If a defined breakpoint is equal to the program start address, a single step is


performed first. If a breakpoint is reached the following message is displayed:
PROCESSING TERMINATED AT xxxxx

Examples:
#G <cr>
#G8100 <cr>
#G,8200 <cr>
#G8000,8010 <cr>

Trace: Single Step Program Execution

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.

The following is an example of the display following a step. It is important to note


that an instruction is first executed and then the display is issued. The IP and the
disassembled instruction refers the next instruction to be executed!
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
08344 MOV R14,#1234
#

Procedure: Single Step over Procedure

Syntax Meaning

D P [count] single step over CALLS or procedures

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

Load and Save


MON166 implements functions for loading and saving program files:

„ LOAD Load an Intel HEX-86 or object formatted program.


„ SAVE Save a program in the Intel HEX format.

LOAD: Load a program

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

Predefined Special Function Registers


MON166 defines the SFR registers of the 80C166 as listed in the following table.

SFR Address SFR Address SFR Address SFR Address


ADCIC 0FF98H CC5IC 0FF82H P1 0FF04H STKUN 0FE16H
ADCON 0FFA0H CC6 0FE8CH P2 0FFC0H SYSCON 0FF0CH
ADDAT 0FEA0H CC6IC 0FF84H P3 0FFC4H T0 0FE50H
ADDRS 0FE18H CC7 0FE8EH P4 0FF08H T01CON 0FF50H
ADEIC 0FF9AH CC7IC 0FF86H P5 0FFA2H T0IC 0FF9CH
BUSCON 0FF14H CC8 0FE90H PECC0 0FEC0H T0REL 0FE54H
CAPREL 0FE4AH CC8IC 0FF88H PECC1 0FEC2H T1 0FE52H
CC0 0FE80H CC9 0FE92H PECC2 0FEC4H T1IC 0FF9EH
CC0IC 0FF78H CC9IC 0FF8AH PECC3 0FEC6H T1REL 0FE56H
CC1 0FE82H CCM0 0FF52H PECC4 0FEC8H T2 0FE40H
CC10 0FE94H CCM1 0FF54H PECC5 0FECAH T2CON 0FF40H

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

MON166 Error Messages


During the work with MON166 some error conditions can arise, which are due to
wrong parameters respectively. The possible error conditions are listed in the
following:

*** ERROR 1: FILE NOT FOUND


The specified file or path does not exist.
*** ERROR 3: CAN’T CREATE FILE
The specified file cannot be saved. A file with the same name possibly already
exists without access rights for writing.
*** ERROR 4: ERROR WHILE WRITING FILE
An error occurred during the writing of a file; i.e. no more room on the memory
storage medium.
*** ERROR 5: CAN’T OPEN READ-ONLY-FILE FOR WRITE ACCESS
An attempt was made to write to or erase a write-protected file.
*** ERROR 6: ACCESS TO FILE DENIED
D
The name mentioned is not the name of a file but that of a directory.
*** ERROR 10: MISSING PARAMETER
A required parameter is missing.
*** ERROR 11: BAD DIGIT
The number entered contains illegal characters for a number.
*** ERROR 12: TOO MANY PARAMETERS
Too many parameters were passed to a MON166 command.
*** ERROR 13: BAD COMMAND
The command entered is unknown.
*** ERROR 14: BAD SERIAL TRANSMISSION
An incorrect check sum was encountered during the serial data transmission.
The transmitted data could be erroneous. Please check the serial cable to the
166/167 board.
*** ERROR 15: BAD HEX RECORD! ABORT LOADING
The loaded hex file contains illegal data or check sum.
*** ERROR 16: INVALID OR CORRUPTED OBJECT FILE
The loaded object file contains illegal data or check sum.
310 Appendix D. Monitor-166

*** ERROR 18 IN LINE xx: INVALID MEMORY TYPE


The symbol file specified in the LS command contains a memory type other
than DATA or BIT in the line specified.
*** ERROR 19 IN LINE xx: HEX VALUE EXPECTED
The symbol file in the LS command contains an invalid HEX number in the
line specified.
*** ERROR 20: WRONG REGISTER
The register is in appropriate for the instruction.
*** ERROR 21: NO RAM AT ADDRESS: xxxx
Data cannot be stored into memory at the specified address.
*** ERROR 22: NO BREAKPOINT AVAILABLE
An attempt was made to define more than 16 break points.
*** ERROR 23: BREAKPOINT DOES NOT EXIST
The specified break point does not exist.
Note: The argument for BD, BE or BK commands must be the break point
D number, not the address. The break point number is a value from 0 to 0F Hex.
*** ERROR 24: CANNOT WRITE BREAKPOINT
A break point must be set to a RAM memory area since a TRAP instruction is
inserted to the application program to perform a break point.
*** ERROR 26: BREAKPOINT ALREADY DEFINED
This break point is already defined. Use the BL command to display all defined
break points.
*** ERROR 27: CANNOT WRITE BREAKPOINT VECTOR
MONITOR-166 could not write a new break point vector. Usually the NMI
trap at address 08H-0BH is used for break points. If the MONITOR-166
EPROM is installed at address 0 then this vector is already defined.
*** ERROR 28: INVALID OPCODE
It is not possible to perform a single- or procedure step on an invalid opcode.
Use the Unassemble command to see where invalid opcodes are.
*** ERROR 29: ILLEGAL OR UNINSTALLED COM LINE
The specified serial interface line is not installed in your computer system.
Note: COM3 or COM4 must be operated with the setting NOINT or INT14
since no standard hardware interrupts exist for these serial interfaces.
*** ERROR 30: ILLEGAL DIGIT IN NUMBER
An octal number cannot contain a digit larger than 7. A hex number can only
contain digits from 0 to 9 or A to F.
166/167 Assembler and Utilities 311

*** ERROR 31: SYNTAX ERROR


One parameter in the invocation line is unknown.
*** ERROR 32: NUMERIC CONSTANT EXPECTED
During inline assembly a numeric value is missing.
*** ERROR 33: CONSTANT VALUE OUT OF RANGE
The given constant value is out of range. Bit positions may not be greater than
15.
*** ERROR 34: INVALID BITADDRESS
Specification of the word base of a bit address must be:
- in the area 0FD00 to 0FDFF
- in the area 0FF00 to 0FFDF
- in the current context (word register).
*** ERROR 35: WORD-REGISTER (RWn) EXPECTED
A word register is expected for this instruction.
*** ERROR 36: ‘]’ EXPECTED
The indirect register specifier is not correct, the closing ‘]’ is missing.
*** ERROR 37: ‘#’ EXPECTED
D
The indirect register specifier with an extra immediate offset is wrong. The
correct form is [RWn + #immediate_value]. RWn must be one of the word
registers R0 to R15.
*** ERROR 38: UNKNOWN IDENTIFIER
The given identifier is undefined.
*** ERROR 39: ILLEGAL OPERAND TYPE
The type of the instruction does not match the requirements of that instruction,
for example a bit operand in word instruction or a word in a byte instruction.
*** ERROR 40: ILLEGAL REGISTER COMBINATION
This instruction requires a 2 bit short GPR address (R0-R3) and not the
registers R4-R15.
*** ERROR 41: NUMBER OF OPERANDS DOES NOT MATCH INSTRUCTION
The number of operands of the assembler instruction does not correspond to
the required number of operands.
*** ERROR 42: TARGET OUT OF RANGE
The specified destination of a conditional jump command does not lie in the
memory area from -255 to +256 of the current address.
*** ERROR 41: ILLEGAL OR UNINSTALLED COM LINE
The specified serial interface line is not installed in your computer system.
312 Appendix D. Monitor-166

Note: COM3 or COM4 must be operated with the setting NOINT or INT14
since no standard hardware interrupts exist for these serial interfaces.

MON166.DLL: dScope Monitor Driver


dScope can also interface to target systems by the use of this MON166.DLL
driver. The serial interface parameters such as COM port and baudrate are
selected in the configuration dialog. When starting the MON166.DLL it tries to
communicate with the target system using the previous settings. If it fails, a
dialog is automatically opened where you can select new COM port parameters.
When an bootstrap loader is detected in the target system, Monitor-166 is
downloaded automatically.

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.

MON166.DLL Configuration Dialog


The MON166.DLL configuration dialog allows to select the Monitor-166 options.
You enter this dialog with the Config option in the Peripherals menu.
166/167 Assembler and Utilities 313

„ 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.

Restrictions of dScope with MON166.DLL


Map Command
The memory mapping of a CPU board with Monitor-166 is selected with hardware
components. It is not possible to display or change this memory mapping with the
dScope MAP command. The MAP command is therefore not supported.

Performance analyzer / Call stack analyzer / Code coverage.


These features are not available with Monitor-166.

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

Resources used by Monitor-166


Monitor-166 normally uses the NMI trap for break points and one of the serial
interface traps. Therefore it is necessary to reserve these areas when linking the
application program.

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]

D „ CpuType selects predefined configuration files suitable for various 166/167


boards. It is recommended to use a predefined configuration whenever
possible. The CpuType selects a set of configuration files (e.g. CpuType :=
KEI7 selects the INSTKEI7.A66, BOOTKEI7.A66 and CONFKEI7.A66
files):

CpuType: = 166 for generic 80C166 board


= 167 for generic 167/165 board
Predefined configurations:
= KEI7 for KEIL MCB167 board
= PHY6 for PHYTEC MC 80C166 board
= ERT6 for ERTEC EVA166 board
= ERT7 for ERTEC EVA167 board
= FOR6 for FORTH\MIKRAP ModuNORM 80C166 board
= FOR7 for FORTH\MIKRAP ModuNORM 80C167 board
= TEC7 for Techne 167 board

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

serialtype := 1 using serial interface 1


serialtype := 2 using simulated serial interface

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

In this example, Monitor-166 uses serial interface 0. Monitor-166 occupies the


code area from 3EB00H to 3FFFFH and the data area from 3E900H to 3EAFFH.
The Monitor-166 is configured for using the bootstrap loader of the 167. The
bootstrap mode must be enabled by hardware (see jumper settings).

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 performs the following operations:

„ Re-translates object files.


E
„ Re-creates linker output file, where only the modified modules are
re-translated.
„ Performs application-wide register optimization also known as application
register coloring. AMAKE accomplishes this by re-translating the source
modules.
„ Lists file dependencies and information about the project generation.
„ Creates a batch file for generating the complete project.
„ Strips AMAKE information from object files so they may be used with older
versions of the 166/167 tool set or other third party tools.

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

Re-translating an Object File


The following example shows how to re-translate a single object file which was
initially translated by the following command line.
C166 HELLO.C CODE DEBUG SMALL REGFILE (HELLO.REG)

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

AMAKE extracts the information how to generate HELLO.OBJ and creates


AUTOMAKE.BAT which contains only the compiler invocation.

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:

„ The path of the source file or of an include file has changed.


„ The time or date stamp of the source file or of an include file has changed.
AMAKE checks for an exact time and date match.

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

Re-creating a Linker Output File


Projects consisting of several object files are created and processed similar to a
single object file. The following example shows the creation of the project
MEASURE which is delivered with the compiler packages.

The project MEASURE consists of three source files: MEASURE.C,


MCOMMAND.C, and GETLINE.C.

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)

Link the project with the following command.


L166 @MEASURE.LIN
E
This completes the initial creation step of the project. If one or more of the source
files are changed, the project can be re-created with AMAKE by typing:
AMAKE MEASURE

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.

Application-wide Register Optimization


If the file project.REG is used with the compiler and linker invocation commands,
AMAKE performs application-wide register optimization. When optimizing
register usage for a whole program, AMAKE may take more than one pass to
create a project. The AMAKE batch driver AMAKE.BAT attempts up to three
320 Appendix E. AMAKE Project Management Utility

passes to optimize the register usage of an project. If the register usage is too
optimistic further re-translations can occur.

List Project Information


AMAKE creates the log file which displays the file dependency and information
about the project generation. The log file shows each target file along with the
input files, which it depends from. The input files are shown with path name, date
and time stamp used when the project was created the last time. Each outdated
component is marked as <Needs retranslation>. If AMAKE detects changes to
the project, the recreation commands are listed at the end of the log file.

An example log file of the project MEASURE is listed in the following:


AMAKE V1.0 09/17/93 09:43:11 PAGE 1

DOS AMAKE V1.0


COMMANDS PLACED IN AUTOMAKE.BAT
AMAKE INVOKED BY: E:\TMP\AMK.EXE MEASURE

PROCESSING 166-OBJECT FILE 'MEASURE'


USING TEMPLATE 'AMAKE.INI' FOR CREATION OF 'AUTOMAKE.BAT'

E COMPONENTS:
-----------

Target: MEASURE.OBJ (17/09/93 09:42:36)


Source: MEASURE.C (16/09/93 08:32:46)
Include(s): C:\C166P\INC\STDIO.H (07/02/92 10:45:16)
C:\C166P\INC\STDLIB.H (14/05/93 08:02:02)
C:\C166P\INC\REG166.H (12/02/92 17:43:10)
C:\C166P\INC\CTYPE.H (14/04/92 07:41:40)
Created by: C166 MEASURE.C CODE DEBUG REGFILE(MEASURE.REG)
<Needs retranslation>

Target: MCOMMAND.OBJ (17/09/93 09:38:42)


Source: MCOMMAND.C (15/09/93 07:48:04)
Include(s): C:\C166P\INC\STDIO.H (07/02/92 10:45:16)
C:\C166P\INC\REG166.H (12/02/92 17:43:10)
Created by: C166 MCOMMAND.C CODE DEBUG REGFILE(MEASURE.REG)

Target: GETLINE.OBJ (17/09/93 09:42:54)


Source: GETLINE.C (17/09/93 09:42:44)
Include(s): C:\C166P\INC\STDIO.H (07/02/92 10:45:16)
Created by: C166 GETLINE.C CODE DEBUG REGFILE(MEASURE.REG)

Target: MEASURE (17/09/93 09:42:54)


Link command: MEASURE.LIN (16/09/93 10:56:50)
Link input files: MEASURE.OBJ (17/09/93 09:42:36)
MCOMMAND.OBJ (17/09/93 09:38:42)
GETLINE.OBJ (17/09/93 09:42:54)
C:\CL166\C166FPS.LIB (09/09/93 14:04:14)
C:\CL166\C166S.LIB (09/09/93 14:04:08)
166/167 Assembler and Utilities 321

Created by: L166 @MEASURE.LIN


<Needs retranslation>

RECREATION COMMANDS:
--------------------

C166 MEASURE.C CODE DEBUG REGFILE(MEASURE.REG)


L166 @MEASURE.LIN

Create a Batch File


AMAKE creates a batch file with the default name AUTOMAKE.BAT. This
batch file contains all commands to build the project. The translation commands
are extracted from the object file. Additional commands which typically handle
the translator exit status information are inserted from the template file. AMAKE
uses AMAKE.INI as default template file.

The following shows the content of a batch command file:


@echo on
C166 MEASURE.C CODE DEBUG REGFILE (MEASURE.REG)
@ECHO OFF
IF ERRORLEVEL 1 GOTO EXIT
@ECHO ON
C166 MCOMMAND.C CODE DEBUG REGFILE (MEASURE.REG)
@ECHO OFF
IF ERRORLEVEL 1 GOTO EXIT
@ECHO ON
C166 GETLINE.C CODE DEBUG REGFILE (MEASURE.REG)
E
@ECHO OFF
IF ERRORLEVEL 1 GOTO EXIT
@ECHO ON
L166 @MEASURE.LIN
@ECHO OFF
IF ERRORLEVEL 1 GOTO EXIT
@ECHO ON
GOTO FINISH
:EXIT
@ECHO OFF
ECHO.
ECHO *** ERROR(S) FOUND.
:FINISH

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

AMAKE Template File


AMAKE uses a template file to insert additional commands to the batch file. If
not template file is specified by the AMAKE control TEMPLATE, the default
template file AMAKE.INI is used. The AMAKE.INI file is first searched in the
current directory. If it does not exists the directory of the AMK.EXE program is
scanned; this is usually the BIN directory of the toolset.

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:

AMAKE creates a batch file in the following way:

„ 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.

The following shows parts of the default template file AMAKE.INI.


[c166] The section entry for the C166 compiler
@ECHO OFF the commands after the section entry are
IF ERRORLEVEL 1 GOTO EXIT copied to the batch file.
@ECHO ON

[a166] The next section entry.


@ECHO OFF
IF ERRORLEVEL 1 GOTO EXIT
@ECHO ON
.
.
166/167 Assembler and Utilities 323

.
[start] The 'start' section.
@echo on

[exit] The 'exit' section.


@ECHO OFF
ECHO.
ECHO *** ERROR(S) FOUND.

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 section [start] is intended to contain project set-up commands such as


environment settings.

The section [exit] is intended to contain commands which probably clean up


commands from the [start] section. The commands of this section are executed if
AMAKE fails to create the project.

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 creates a log file containing the following information:


DOS AMAKE V1.0
COMMANDS PLACED IN AUTOMAKE.BAT
AMAKE INVOKED BY: E:\TMP\AMK.EXE MEASURE PURGE
324 Appendix E. AMAKE Project Management Utility

Creating stripped file 'MEASURE.O' from file 'MEASURE'

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:

AMAKE inputfile †controls‡

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.

Control Abbr. Description


CMDFILE (filename) CF Directs AMAKE to create a command file using the specified
filename. If CMDFILE is not specified the command file is given
the name AUTOMAKE.BAT. Note that changing the name of the
command file also requires changes to the file AMAKE.BAT in
order to run correctly.
LOG (filename) LG Creates a log file with information about the project generation. If
the LOG control is not specified, the base name of the input file
and a the extension .LOG is use as name for the log file.
NOCMDFILE NOCF Directs AMAKE not to create a command file. AMAKE will create
the logfile (unless otherwise specified) but does not cause re-
translations to take place.
NOEXECUTE NOE Directs AMAKE not to execute the command file
AUTOMAKE.BAT. In this case, the command file
AUTOMAKE.BAT must be activated manually.
NOLOG NOLG Prevents AMAKE from creating a log file.
NOREGOPTIMIZE NORO Directs AMAKE not to perform global register optimizations.
NOTEMPLATE NOTP Directs AMAKE not to use any template file.
PAGELENGTH PL Specifies the number of lines per page of the log file. The
(number) number must be in range 18 to 32760, the default is 69 lines per
page.
166/167 Assembler and Utilities 325

Control Abbr. Description


PAGEWIDTH (number) PW Specifies the pagewidth used when creating log file. The number
must be in range 72 to 132, the default is 132 characters per line.
PURGE [ (filename) ] PU Specifies that the AMAKE information contained in the project file
should be removed. AMAKE creates a new file with either the
base name of the project file and a file extension of .o or the
specified name. The new file contains anything but not the
AMAKE information from the project file.
RECREATE RC Directs AMAKE to re-create all object files of a project. This
means that the project is re-built by translating and linking all
modules regardless of whether they are valid or not.
REGOPTIMIZE RO Directs AMAKE to perform global register optimizations. This is
the default setting if REGOPTIMIZE is not specified.
Register optimization opportunities in a project may result from
changes in a function of some source file, which may cause the
register load from that function to be different from the load
known to functions in other modules. This type of information is
transferred via a .REG file generated by the translators and
linkers. With the REGOPTIMIZE command, AMAKE creates the
command file if the overall register loads of the project can be
optimized, otherwise no command file is created. If the project
must be re-built due to register loads which are too optimistic
then the command file is generated anyway.
TEMPLATE (filename) TP Directs AMAKE to use the specified file as template for creating
the command file. If the TEMPLATE control is not specified, the
file AMAKE.INI is used as template file.

Invocation Examples E
Following are a few examples for AMAKE command lines:

AMAKE MEASURE LOG (MS.LOG)

In this example, the object file MEASURE is processed and the log output is
directed to the file MS.LOG.

AMAKE MEASURE PURGE (MEASURE.PRG)

In this example, the stripped object file MEASURE.PRG is created from the
object file MEASURE, which is left unchanged.

AMAKE MEASURE PAGEWIDTH (80)

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

AMAKE MEASURE CMDFILE (GENALL.BAT) RECREATE

In this example, AMAKE generates the batch file GENALL.BAT from the object
file MEASURE which can be used for initial project creation.

AMAKE Error Messages


The following errors may be generated by AMAKE. Each message listed below
includes a brief description as well as corrective actions you may take to eliminate
the error condition. AMAKE error messages display using the following format:

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:

Physical Address = (DPPn * 0x4000L) + (bit0-bit13 of the near address)

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.

in-circuit emulator (ICE)


A hardware device that aids in debugging embedded software by providing
hardware-level single-steping, tracing, and break-pointing. Some ICEs provide
a trace buffer that stores the most recent CPU events.

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

Compatibility to Siemens Tools ...... 208 PAGEWIDTH.............................87


COND ..............................................72 PAGING .....................................88
COND, control .................................72 PRINT ........................................89
condition code ..................................12 REGUSE.....................................90
conditional assembly....................... 100 RESET...................................... 101
CONF_TNY.A66 ........................... 269 RESTORE...................................92
Constant SAVE .........................................92
Expression ..................................60 SEGMENTED ............................93
constant expression, defined ........... 329 SET........................................... 101
context pointer..................................41 SYMBOLS..................................94
Controls TABS..........................................95
ABSOLUTE................................70 TITLE.........................................96
CASE..........................................71 TYPE..........................................97
COND.........................................72 USEDEXTONLY........................98
DATE .........................................73 XREF..........................................99
DEBUG ......................................74 courier typeface, use of ......................iv
EJECT ........................................75 CPUTIMER.INC ............................ 269
ELSE ........................................ 104 Cross reference listing ........................9
ELSEIF..................................... 103
ENDIF ...................................... 105 D
ERRORPRINT ............................76
EXPDECNUM............................77 data section.......................................32
GEN/GENONLY/NOGEN..........78 DATE...............................................73
IF .............................................. 102 DATE, control..................................73
INCDIR ......................................79 DB....................................................59
INCLUDE...................................80 DBIT ................................................59
LIST ...........................................81 DBPTR.............................................62
MACRO......................................82 DEBUG............................................74
MOD166.....................................83 DEBUG, control ...............................74
MOD167.....................................84 declaration, defined ........................ 330
NOCASE ....................................71 DEFA...............................................50
NOCOND ...................................72 DEFB ...............................................50
NODEBUG .................................74 define ............................................. 107
NOERRORPRINT.......................76 Define Bit.........................................59
NOLIST......................................81 Define Byte.......................................59
NOMACRO ................................82 Define Storage..................................59
NOMOD166 ...............................83 Define Storage Byte ..........................60
NONSEGMENTED ....................93 Define Storage Word ........................60
NOOBJECT ................................85 Define Word.....................................59
NOPAGING................................88 define-pattern ................................. 125
NOPRINT ...................................89 definition, defined........................... 330
NOSYMBOLS ............................94 DEFR ...............................................50
NOTYPE ....................................97 DGROUP .........................................37
NOXREF ....................................99 Directive
OBJECT .....................................85 ASSUME ....................................38
PAGELENGTH ..........................86 BIT .............................................48
DB ..............................................59
166/167 Assembler and Utilities 337

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

EXTRN ............................................55 group name.......................................17


Groups............................................ 158
F
far.....................................................44
H
Filename, notational Hash mark (#) in listing......................9
conventions.....................................iv
Files generated by A166....................67 I
fix-up................................................46
forward.............................................24 ICE, defined ................................... 331
forward reference..............................46 identifier-delimiter.......................... 127
function call, defined ...................... 331 IF ................................................... 102
function, defined............................. 330 IF, control....................................... 102
Functions Immediate data .................................25
bracket ...................................... 113 Implementation specifics ................ 145
comment ................................... 112 limits......................................... 145
CONSOLE................................ 124 INCDIR............................................79
EQS .......................................... 118 INCDIR, control ...............................79
escape ....................................... 112 in-circuit emulator, defined............. 331
EVAL ....................................... 117 INCLUDE ........................................80
EXIT......................................... 121 include file, defined ........................ 331
GES .......................................... 118 INCLUDE, control ...........................80
GTS .......................................... 118 initialize memory..............................59
IF .............................................. 119 instruction set ................................. 145
IN ............................................. 124 Intel HEX
LEN .......................................... 122 8086 segment address record..... 243
LES........................................... 118 Data record ............................... 242
LTSs ......................................... 118 End-of-file record...................... 242
MATCH.................................... 123 EOF record ............................... 242
METACHAR ............................ 114 Example file.............................. 244
NES .......................................... 118 Extended linear address
OUT.......................................... 124 record..................................... 243
REPEAT ................................... 121 Record format ........................... 241
SET........................................... 116 Intel HEX file format...................... 241
SUBSTR ................................... 123 Intel HEX files........................ 155, 239
WHILE ..................................... 120 internal RAM ...................................42
INTERRUPT ....................................44
Interrupt Handling.......................... 256
G Interrupt Vector.............................. 201
GEN .................................................78 interrupt vector number ....................12
GEN/GENONLY/NOGEN, INTNO .............................................44
control ...........................................78 Invoking A166..................................65
general purpose register....................16 isr_send_signal............................... 265
GENONLY.......................................78 italicized text, use of ..........................iv
GLBUSRSTACK..............................35
GLOBAL.................................... 34, 57
GROUP ............................................37
166/167 Assembler and Utilities 339

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

Body ......................................... 108 MON166.DLL ........................ 289, 312


Delimiters ................................. 109 MON166.EXE................................ 289
Error ......................................... 129 Monitor-166 ................................... 289
Parameter.................................. 109 Comments................................. 297
Processor............................. 63, 107 Configuration............................ 314
MACRO, control ..............................82 Console Output ......................... 292
macro, defined................................ 331 Serial Transmission Line........... 294
manifest constant, defined .............. 331 Trace......................................... 305
MAP file......................................... 160 MPL ............................................... 107
Memory allocation.......................... 159
memory model, defined .................. 331 N
metacharacter ................................. 108
mnemonic.........................................11 NAME..............................................63
MOD166 ..........................................83 Name Assignment .......................... 257
MOD166, control .............................83 near ..................................................44
MOD167 ..........................................84 newline character, defined .............. 331
MOD167, control .............................84 NOCASE..........................................71
module name ....................................63 NOCASE, control.............................71
MON166 NOCOND.........................................72
Command Line ......................... 292 NOCOND, control............................72
Control Keys ............................. 292 NODEBUG ......................................74
Error Messages ......................... 309 NODEBUG, control..........................74
Invocation ................................. 290 NOERRORPRINT ............................76
Program Test............................. 305 NOERRORPRINT, control ...............76
Terminal Control Codes ............ 293 NOGEN.................................... 78, 110
MON166 command NOLIST ...........................................81
Assemble................................... 299 NOLIST, control...............................81
BreakDisable............................. 303 NOMACRO......................................82
BreakEnable.............................. 304 NOMACRO, control.........................82
BreakKill .................................. 303 NOMOD166.....................................83
BreakList .................................. 303 NOMOD166, control ........................83
Breakpoints............................... 302 NONSEGMENTED..........................93
BreakSet ................................... 302 non-segmented ........................... 32, 56
Display...................................... 298 NONSEGMENTED, control.............93
Enter ......................................... 298 NOOBJECT .....................................85
eXamine.................................... 300 NOOBJECT, control.........................85
Exit ........................................... 297 NOPAGING .....................................88
F1 Exit ...................................... 295 NOPAGING, control ........................88
F2 Transmit File ....................... 296 NOPRINT ........................................89
F3 Protocol Output .................... 296 NOPRINT, control............................89
Fill ............................................ 299 normal mode .................................. 128
Go............................................. 305 NOSYMBOLS..................................94
Load Program ........................... 307 NOSYMBOLS, control.....................94
Procedure .................................. 306 NOTHING........................................39
Save Program............................ 307 NOTYPE..........................................97
Unassemble............................... 299 NOTYPE, control .............................97
NOXREF..........................................99
166/167 Assembler and Utilities 341

NOXREF, control ............................ 99 SEG............................................ 25


null character, defined.....................331 shift............................................ 20
null pointer, defined........................332 short ........................................... 24
Numbers ...................................13, 115 sign ............................................ 19
SOF............................................ 26
O Subtraction ................................. 18
Optional items, notational
OBJ files .......................................... 67 conventions .................................... iv
OBJECT .....................................67, 85 ORG ................................................ 53
object file, defined...........................332 os_clear_signal ...............................260
OBJECT, control ............................. 85 os_create_task.................................261
object, defined.................................332 os_delay_task..................................262
OH166 ....................................155, 239 os_delete_task.................................263
Command line ...........................239 os_running_task_id.........................264
Error messages ..........................240 os_send_signal................................265
OH166, defined...............................332 os_wait ...........................................266
Omitted text, notational os_wait_signal ................................268
conventions .................................... iv os-wait ............................................247
operand, defined .............................332 Output files ...................................... 67
Operands overlap............................................. 34
data page pointer (DPP).............. 22
immediate expression ................. 23
linear address ............................. 26
P
page number............................... 25 page override ................................... 38
regbank ...................................... 25 page relative..................................... 62
special function register PAGELENGTH ............................... 86
(SFR)....................................... 25 PAGELENGTH, control .................. 86
system names (SFR) ................... 25 PAGEWIDTH.................................. 87
Operands and Expressions ............... 11 PAGEWIDTH, control..................... 87
operator, defined .............................332 PAGING.......................................... 88
Operators ......................................... 17 PAGING, control ............................. 88
Operators parameter, defined ..........................332
Addition ..................................... 18 parameterless macro........................108
BOF ........................................... 27 PEC channels................................... 26
DATAn ...................................... 23 PECADDRESSABLE ...................... 33
Division...................................... 19 PECDEF .......................................... 42
DOT........................................... 21 Physical Memory Layout.................203
HIGH ......................................... 21 pointers, defined .............................332
logical ........................................ 20 pragma, defined ..............................332
LOW .......................................... 21 predefined names ............................151
Modulo....................................... 19 predefined symbols
Multiplication............................. 19 reserved words............................ 15
PAG ........................................... 25 Preemptive Task Switching.............248
page override.............................. 22 PRINT ........................................67, 89
POF............................................ 26 PRINT, control ................................ 89
PTR............................................ 22 Printed text, notational
relational .................................... 20 conventions .................................... iv
342 Index

Priority of Operators .........................17 RTX166T.H.................................... 257


PRIVATE.........................................34 Running A166 ..................................65
PROC ...............................................43 runtime stack....................................34
PUBLIC...................................... 34, 57
S
R sans serif typeface, use of...................iv
REGBANK.......................................41 SAVE...............................................92
REGDEF ..........................................41 SAVE, control ..................................92
REGUSE ..........................................90 scalar types, defined........................ 332
REGUSE, control .............................90 scope, defined ................................. 333
relative offset ....................................12 SECTION................................... 31, 32
relocatable ..........................................9 multiple definition.......................35
Relocatable nested..........................................36
Expression ..................................16 Section Alignment.......................... 156
Operands.....................................19 Sections .......................................... 156
Section ........................................16 segment relative................................62
relocatable, defined......................... 332 segmented................................... 32, 93
replacement-text ............................. 109 SEGMENTED, control.....................93
reserve memory ................................59 SET ................................................ 101
reserved words................................ 149 SET, control ................................... 101
RESET ........................................... 101 Siemens
RESET, control .............................. 101 LNK166.................................... 208
Resolving External References........ 159 LOC166 .................................... 208
RESTORE ........................................92 Siemens Task Concept.................... 207
RESTORE, control ...........................92 Siemens Tools
Round-Robin .................................. 246 Compatibility to ~ ..................... 208
RTX166.................................. 161, 245 Software instructions ................ 43, 148
Functions .................................. 251 source file, defined.......................... 333
Optimizing................................ 271 SSKDEF...........................................42
Technical Data .......................... 251 stack size ..........................................42
RTX166 Applications ..................... 249 stack, defined.................................. 333
RTX166 Example static, defined ................................. 333
RTX_EX1.C ............................. 273 string literal, defined ...................... 333
RTX_EX2.C ............................. 275 string, defined................................. 333
TRAFFIC.C .............................. 277 Strings..............................................13
RTX166 Full, defined ..................... 332 Symbol ......................................... 8, 14
RTX166 Tiny ......................... 161, 245 changeable ..................................15
Application Examples ............... 273 Scope ..........................................15
Configuration............................ 269 Section ........................................15
Functions .......................... 250, 257 Table.............................................8
Introduction .............................. 245 Type............................................14
Software Requirements.............. 253 Value ..........................................15
Stack Management.................... 270 Symbol
System Debugging .................... 271 special assembly ~.......................16
Technical Data .......................... 250 symbolic debugging ..........................11
RTX166 Tiny, defined .................... 332 symbolic label...................................11
166/167 Assembler and Utilities 343

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

You might also like