SEMICONDUCTOR
ASM 3.0
User’s Guide for HASM 3.0,
the Advanced Optimizing Assembler
for Harr is CDP68HC05 Microcontrollers
RM-003
Preliminary Beta Version
i
Table of Contents
HASM 3.0 User’ s Guide
1Introduction 1
What is HASM? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
What’s New With HASM 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
Definition of Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Licensing Agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
2 Using HASM 3.0 5
Running HASM From the Command Line . . . . . . . . . . . . . . . . . .5
Command Line Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
Setting the standard search path. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Using DOS batch files to manage HASM switches . . . . . . . . . . . . . . . 8
Output File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
He x File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Listing File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Error File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Symbol File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Source File Syntax 17
Comments and Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Numbering Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Expressions and Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Inherent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Immediate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Extended . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Direct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Indexed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Bit test and branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Supported Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Table of Contents
ii
4 Assembler Directives 27
Data Allocation Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
.ascii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
.byte. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
char . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
db . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
ds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
dw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
equ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
fcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
fdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
hex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
rmb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
rmw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
section. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
.word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
word. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
Control Pragmas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
elseif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
endif. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
endmacro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
endrepeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
if. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
ifnot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
include. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
macroend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39
nolist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
noopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
opt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
repeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
iii
Table of Contents
HASM 3.0 User’ s Guide
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
setnot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5 User Defined Macros 43
What is a Macro? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
Defining a Macro. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
Labels and Comments in Macros . . . . . . . . . . . . . . . . . . . . . . . . .44
Passing Arguments to Macros . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Nested and Recursive Macros. . . . . . . . . . . . . . . . . . . . . . . . . . . .47
6 Optimization 49
Optimized Assembly Language? . . . . . . . . . . . . . . . . . . . . . . . . .49
Enabling Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
How Optimization is Done . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
Optimization of Indexed Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Optimization of Extended Jumps/Subroutine Calls . . . . . . . . . . . . . . . 51
A Errors and Warnings A1
Error Messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .A1
Warning Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .A5
Special Err ors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .A6
B HASM 3.0 Quick Reference B1
Command Line Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .B1
Arithmetic, Logic and Comparative Operators . . . . . . . . . . . . . .B2
Assembler Directives and Pragmas . . . . . . . . . . . . . . . . . . . . . . .B3
Table of Contents
iv
1
HASM 3.0 User’ s Guide
1
1
Introduction
What is HASM?
HASM is a DOS based program for IBM PC compatible computers that allows
users to assemble standard 68HC05 assembly language files into machine code
f or the Harris CDP68HC05 f amily of 8 bit microc ontrollers (MCUs). HASM req uires
an IBM compatible PC running DOS 4.0 or later (HASM will run under the MS-
DOS prompt shell in Windows 95), 500kB free memory, and one disk drive.
What’s New With HASM 3.0
HASM 3.0 is the latest version of the free Harris assembler for the CDP68HC05
family of MCUs. HASM 3.0 includes significant enhancements over HASM 2.7,
including:
Optimization for JMPs, JSRs, and indexed addressing
Support for user defined macros, including parameter passing
New "standard search path" directive for code portability
Flexible filenaming convent ion s
Cycle time added to listing file output for easy calculation of processor timing
Comparative operators (<, >, and =) added to arithmetic functions
Additional assembler directives including set, setnot, error, opt, and
noopt.
Support for other types of if-else directives including esleif and ifnot
Support for addition pragma delimiters "$" and "/" in addition to "#"
Support for "$" as the current program location in addition to "*"
Most of the new functions have been added so that HASM 3.0 is capable of
assembling virtually any assembly code source file w ritten for other 68HC 05
assemblers.
De finitio n o f Ter m s
The following terms are used throughout this document and are defined as fol-
lows:
Introduction
Installation
2
1
source code - this is the program, written in the CDP68HC05 mnemonic
assemb ly l anguage , to b e assemb led an d e ven tually s tored in th e memory of a
CDP68HC05 microcontroller. It is an ASCII file that can be created with any
ASCII text editor.
machine code - this is the hexadecimal language executed by the
CDP68HC05 CPU. Machine code is result of assembled source code. Also
kno wn as exec utab le code.
assemble - the process of converting source code into machine code.
mnemonic - three, four o r five let ter "psued owords" that are assigne d dir ectly
to C DP68HC 05 machine instructions. Mnemonics are the basis of all assem-
bly languages.
pragma - pragm as ar e specia l w ords, del imited w ith eith er a "# ", "$" or "/", that
give the assembler instructions on how to assemble the file.
macro - a macro is a user defined sequence of commands to be executed by
the assembler each time the macro name is encountered.
Installation
Distribution for HASM 3.0 is provided by Harris Semiconductor on 3.5 inch high
density (1.44MB) PC compatible diskettes. A copy of HASM 3.0 can also be
obtained via the Internet from the Harris CDP68HC05 web page at http://
www.semi.harris.com/68hc05. The copies distributed on diskette are uncom-
pressed and ready to run. The copies downloaded via the internet are com-
pressed and should be unzipped with PKZIP or compatible software
decompression tools.
It is recommended the HASM 3.0 be installed directly to and run from your com-
puters hard drive. If necessary, HASM may be run from the flopp y drive. HASM is
a sin gle file program; there are no initiali zation or library file associated with it. As
such, the executable file, HASM.EXE, may be installed to your computer’s hard
drive in any directory appropriate.
Licensing Agreement
HASM 3.0 is a free application produced by Harris Semiconductor, a division of
Harris Corporation, for the express use of it’s customers and those interested in
the Harris CDP68HC05 family of microcontrollers. Since it is freeware, this soft-
ware may not be sold but may be distributed freely for the express purpose of
developing software for CDP68HC05 MCUs.
3
Introduction
Questions
HASM 3.0 User’ s Guide
HASM 3.0 is the pr operty of Harris Corporatio n an d is prot ected b y cop y right la ws
of the U nited States. The user may not alter or in anyway change the functionality
or source code o f HASM 3.0 an d are prohibited from disassembling the HASM
source code into a human readable form for any purpose.
Questions
As with any product, users at times have questions about functionality and other
aspects of HASM. If question arise, please feel free to contact us at Harris Semi-
conductor by phone at 1-800-4HARRIS or send email to
digiApps@harris.com
.
Introduction
Questions
4
1
5
HASM 3.0 User’ s Guide
2
2
Using HASM 3.0
HASM 3.0 provides a develo pment platform for creating software for the Harris
CDP68HC05 family of microcontrollers. This chapter explains the basic workings
of HASM, including how t o assemb le so urce files , input a nd output fi le f ormats, file
naming conventions, and command line switches.
HASM is a full, symbolic command line assembler for the 68HC05. It supports a
wide ra nge of styles for inpu t f ormats and ge nerat es listing type out put (sourc e file
merged with hex output), ‘S-record’ style hex file output, symbol files for use with
Harris development tools and error files for easier debugging. The S-record hex
file format is compatible with all Harris 68HC05 development systems.
Running HASM From the Command Line
HASM is i nvoked to asse mb le fi les di rectly fro m the DOS prom pt. The input file for
HASM should b e a s t an dard text file. Control codes s ho uld be remo ved and if the
file is generated with a word processor such as WordStar or WordPerfect, the file
should be saved i n TEXT or N O N-D O CUM EN T m ode. An input file can have any
legal DOS (i.e 8.3 format) name. The syntax of invoking HASM is:
HASM <source.s> [/option] [/option] ... [/option]
Where <source.s> is the source file to be assembled and [/option] refers
to an y o f the optio nal c ommand line s wit ch u sed t o con figure HASM. F or example,
if the file mysource.s is in the current directory, it could be assembled with the
following command:
HASM mysource.s /l /o /i=c:\6805
The next section describes the function and usage of the command line switches.
Command Line Switches
When c all ed to as se mble a sourc e file, H ASM ca n be pas se s a s equence of up to
nine optional command line switches to set parameters within the assembler and
affect the way HASM generates ou tput files. N o ne of these switc hes are required;
if omitted HASM will use default values. All command li ne switches should be pre-
ceeded with a forward slash ( / ) and should not contain spaces. A listing of the
HASM command line switches, default values and their functions are shown in
Using HASM 3.0
Command Line Switches
6
2
Table 1. HASM command line switches may be entered in either upper or lower
case.
Note that some switches have parts that are optional. These parts are shown in
the table in square brackets ( [ and ] ).
Table 1. HASM Command Line Switches
Switch Function Default
E[=ext] Controls the generation of the error listing file. If
included, a text file will be created with the file-
name source.erl, where source.s is the
assembled source file. If the optional =ext is
included, the error filename will have the exten-
sion set by ext.
Errors are sent to
the screen.
HTurns off the generation of the S-record hex file. Hex file generated
I=path Sets the standard search path for HASM. This
path is searched whenever files are included in
the source using the #include <file> conven-
tion.
Standard search
path set to
/6805/include
L[=ext] Controls the generation of the listing file. If
included, a listing file will be created with the file-
name source.lst, where source.s is the
assembled source file. If the optional =ext is
included, the listing filename will have the exten-
sion set by ext.
No listing file cre-
ated
MSuppresses the expansion of user defined macros
in the listing file . Macros are
expanded in the
listing file
OEnables HASM’ s mult i-pass optimization of JMPs,
JSRs, and indexed addressing. No optimization is
done
SCreates a symbol file with the filename
source.sym, where source.s is the assemb led
source file.
No symbol file cre-
ated
WSuppresses the generation of warnings in the
error file Warnings are dis-
played
X=ext Used to specify the extension of the S-record hex
file generated b y HASM. The filename of the he x
file will be source.ext, where source.s is the
assembled source file.
Hex file generated
with the .H exten-
sion.
7
Using HASM 3.0
Command Line Switches
HASM 3.0 User’ s Guide
For example, if HASM is called to assemble a file like so:
C:\HASM source.s /e=err /l /o /x=s19 /m /i=\6805
HASM will search t he current workling directory for the file source.s. If found,
HASM will open source.s for assembly. During assembly, HASM will create a
he x fi le, a lis ting file and an error fi le. The s ource file wil l be ass emb led w ith optim i-
zation o n (s ee C h apte r 6), i t w ill not expand macr os i n th e listing fi le ( see Chap ter
5), and the standard search path will be set to C:\6805. Assuming the assembly
was a success, the following files will be created:
source.s19 - S-record hex file
source.lst - listing file (macros not expanded)
source.err - error file listing.
Setting the standard search path
While most of the command line switches used in HASM are very simple and
straight forward, the standard search path switch, /i, can be confusing and
requires a little more explanation.
The purpose of the standard search path in HASM is to allow for code portability.
Often a program may have to move from computer to computer before it is com-
pleted. A lot of 68HC05 programs use the #include pragma (see Chapter 4 for
more details on HASM pragmas) to include a standard files like register mapping
files or math subroutines. For those who do a lot of 68HC05 programming, these
standard files generally reside in one central location on their machine as
oppose d t o ha vi ng a s ingl e copy in each proje ct dir ect ory. As such, the #include
directive pointing to these files usually includes a path to get to these files. If you
try to as se mble the co de o n a dif ferent mach ine and th e the mapping fil es are in a
different path, the assembler will generate errors because it can not find the files.
For example, lets say you have three standard files that you include with most of
you 68HC05 source files. These files are c16b.s, math.s, and io.s. Now, on
you desktop machine at work, thes e files are in the directory D:\6805. Typically,
you would include these files like so:
#include d:\6805\c16b.s
#include d:\6805\math.s
#include d:\6805\io.s
This is fine if this code will only ev er be assembled on your desktop machine. Now ,
say you give the code to a coworker to make some edits. She has all of the same
files on her machine, but there are locat ed in the C:\hc05\files directory. So
now she has to change the #include statements to look like this:
Using HASM 3.0
Command Line Switches
8
2
#include C:\hc05\files\c16b.s
#include C:\hc05\files\math.s
#include C:\hc05\files\io.s
Then , when you get the code ba ck, you hav e to ch ange them ba ck, and so on. To
avoid all of this, the standard search path was invented. When calling HASM to
assemble a file, use the /i=path switch to set the standard search path. Then,
when HASM encounters any files (without pathes) included in angle brackets ( <
and > ), it will sea rch the stan dard se arch path. T hus, i f the e xample code abo v e is
rewritten like so:
#include <c16b.s>
#include <math.s>
#include <io.s>
You can assemble the code wit h /i=d:\6805 and your coworker can assemble
it with /i=c:\hc05\files and both assemblies will be successful (assuming
there are no problems with your code, of course).
In addition to allowing you to move code from computer to computer without
rew riting yo u include di rectiv es , the standard search path al lows y ou to creat e one
central library directory on your machine for all of your 68HC05 include files and
include these files in your programs using the #include <file> directive. No
longer do you have four or five copies of the same file in different project directo-
ries, wh ich leads to prob lems w hen you fi nd an error in one o f the files and ha v e to
revise all of the copies on your hard drive.
The next section describes how to use DOS b atch files to allow you t o set your
standard search path once and not have to type it in every time you assemble a
file with HASM.
Using DOS batch fil es to manage HASM switc hes
HASM has a t otal of nin e pos si ble command li ne switches to be enetered, in addi-
tion t o the so urc e fil e n ame, every time y ou asse mble a file . If you want to change
filename extensions or use the standard search path, the process of invoking the
assembler with the right configuration can become even more cumbersome. For-
tunately, there is a simple solution to this problem build right into the DOS operat-
ing system.
Most programmers have specific ways they like to assemble their source code.
Programmer A might always generate a listing file, an error file with the .err
extension, suppress macros and use optimization. Programmer B might always
want the listing file, optimization, hex file with the .s19 extension, and set the stan-
9
Using HASM 3.0
Command Line Switches
HASM 3.0 User’ s Guide
dard search path. By writing a simple DOS batch file, these programmers can set
up their HASM command line once and use the batch file to call HASM for them.
What is a DOS batch file?
A DOS batch file is a simple text file that contains a list of commands for DOS to
execute. These commands are the same ones that you would type in at the com-
mand prompt. All batch files must have the filename extension .BAT. Parameters
can be p asse d to a ba tch fil e b y usi ng the " %n" op erato r, where n is the n th par a m-
eter p assed. Exam ple 1 sh ows hasm1.bat, a HASM ba tch file f or Progr ammer A.
Note: on Programmer A’s machine HASM is in the 6805 directory on the F:\
drive.
Example 1. Sample HASM batch file - HASM1.BAT
Notice the "%1" after hasm.exe. This is where the name of the source file will be
passed to th e bat ch file . Th e first l ine in the fil e , beginning with rem, is a co mment
line and is not required. To use this file, Programmer A would simply type at the
DOS prompt:
C:\ hasm1 mycode.s
Assuming that the batch file was in his DOS search path, the following would be
executed:
C:\ rem HASM batch file HASM1.BAT
C:\ f:\6805\hasm.exe mycode.s /l /e=err /m /o
And thus HASM would be called with all of Programmer A’s desired switches
added. Likewise, Example 2 shows Programmer B’s batch file, hasm.bat.
Example 2. Sample HASM batch file - HASM.BAT
Again you can see how the command line is set up with all of Programmer B’s
switches. Note the %2 and %3 at the end of the l ine. These are included to allow
for the a ddi tio n more switches t o t he on es u se d f r equ en tly. Thus , if Prog ramme r B
occasionally wants to suppress macro expansion, he could type at the command
prompt:
rem HASM batch file HASM1.BAT
f:\6805\hasm.exe %1 /l /e=err /m /o
rem HASM batch file HASM1.BAT
d:\hasm.exe %1 /l /o /i=d:\harris\hc05\files /x=s19 %2 %3
Using HASM 3.0
Output File
10
2
C:\ hasm code.asm /m
and the following would be executed:
d:\hasm.exe code.asm /l /o /i=d:\harris\6805\progs /x=s19 /m
The %1 was relaced with code.asm and the %2 was replaced with /m. The %3,
which was not passed a value, was simply replaced w ith a space. Some program-
mers also prefer to write several different batch files for different assembly meth-
ods. Thus, DOS batch files can easily manage your HASM command line, no
matter how long and complex they get.
Output File
HASM is capabl e of generating up to four different types of output files during
assembly. These files are the
hex
file
,
listing
file
,
error
file
and the
symbol
file
. A
description of each of these file types is given in this section.
Hex File
The primary output of HASM is the S-record for matted hex file. This file contains
the final assemb le d code i n an ASCII hex (i.e . tw o ASCII char acte rs, like "E" ($45)
and "4" ($34), represent the number $E4) format. The hex file is the file used by
most development systems and programmers as a representation of the final
code.
By default, the name of the hex output file is the base of the source filename with
the .H e xte nsion . F or e x ample , of th e name of th e source fil e is myfile.asm, the
name of the hex file will be myfile.h. Som e p rog rammers and deve lop me nt sy s-
tems pre f er th e use o f other fil ename e xten sions f or the hex file . To instruct H ASM
to use a diff ere nt e x tensio n, use the /X= command line switch. For e xample, if the
file myfile.asm is assembled with the command line sw itch /X=s19, the name
of the hex file will be myfile.s19. If the /H s w itc h is us ed wh en invoking t he
assembler the generation of the hex file will be suppressed, even if the /X com-
mand is incl uded.
HASM creates hex files only in the industry standard "S19" S-record format. This
file is an ASC II t ext file tha t c an b e viewed with any standard text editor (e . g. DO S
edit.com). Each line in the file, referred to as a record, contains specific informa-
tion about the file that was assembled. The first two characters in each record
describe the format of that record; there are three main types of records in the
S19 format. The S0 reco rd i s for header and com m ent s . Al l inf o rmation c onta in ed
after the S0 record is ig nored. T he S1 rec ord is the main data rec ord an d conta ins
11
Using HASM 3.0
Output File
HASM 3.0 User’ s Guide
all of the addressin g a nd ma ch ine code information. Fi nal ly, the S9 re co rd i s u se d
to indicate the end-of-file for S-record files. The format of these lines is as follows:
S0 This is a comment, this text will be ignored
Lines beginning with the S0 characters are comment or header lines. Since pro-
grammers rarely if ever edit hex files directly anymore, these lines are seldom
used. H ASM does no t gener at e an y S0 reco rds; the y ma y b e added to the he x fi le
if desired.
S1091D408AB67B147183D6
S1 records are the main data records. They consist of the following information:
the two character S1 delimiter, a two character byte count, a four character
address, data bytes, and a two character checksum. Note that the byte count,
unlike Intel hex formats, includes the address and checksum. Since these will
always require three bytes, the number of data bytes in a record is three less than
the count. Also keep in mind that the count refers to the number of
bytes
in a
record, not the number of ASCII characters required to represent those bytes. In
the record shown abo v e, the count is $09 (there are six data b ytes ), the address is
$1D40 , the c hec ksu m is $D 6, and the res t are d ata bytes. The maxi mu m leng th of
an S1 record is 78 characters.
S9030000FC
Finally, the S9 record indicates the end of file f o r a he x file. It is alwa ys of th e same
fo rmat -- S9, count, null address ($0000), and the checksum. Example 3 shows a
typical S-record format hex file.
Example 3. Typical HASM Hex File
Listing Fil e
The listing file is one of the most useful files generated by HASM for the program-
mer to use when debugging software. The listing file is a plain ASCII text docu-
ment that consists of the assembly source code merged line by line with the
assembled machine code and other pertinent information like address location,
variable values, cycl e counts and more.
S1233000A60CB70A81B70C0F0BFDB60C8115001400811500140481AD3FAD7BCD309E27FB72
S1233020AD4CAD6CAD52AD5ACD0973AD5FCD098BCD09625A26F51500CC01800D0A5265736E
S1233040756C74732066726F6D204D6F64652033206172653A0D0A00ADB8ADA4ADAFA690E7
S1233060ADA3A62BAD9FA6FFAD9BA6902097AD9DA692AD91A600208DAD93A692AD87A61090
S12330802083AD89A600CD3005AE0881CD300581AE005A26FD81CD300DA613CC3005CD3084
S10730A005A54081BD
S9030000FC
Using HASM 3.0
Output File
12
2
By default, a listing file is not created when a file is assembled with HASM. To
instruct HASM to create a listing file, include the /L command line switch when
invoking the assembler. The default name of the listing file created when the /L
switch is included is source file name with the .LST extension appended. For
e xample , of the na me of the so urce file i s myfile.asm, the name of the listing file
will be myfile.lst. If a diff er ent e xtension is pref erred, add the =ext directiv e t o
E
xamp
l
e
4
.
T
yp
i
ca
l
HASM
li
st
i
ng
fil
e
HARRIS Semiconductor (c)1990 - 1997
68HC05 Assembler Version 3.0.2
Filename: EX1.LST
Source Created:07/28/97, 10:57 am
Assembled: 07/28/97, 10:57 am
00001 * Above is the header information
00002 *
00003 #include <c16b.s> ;including a file
------------------ START OF INCLUDE \6805\include\C16B.S ----------------
00001 #nolist
00144 #list
------------------ END OF INCLUDE \6805\include\C16B.S ------------------
00004
00005
00006 $00A1 = 161 con1 equ $A1 ;these are constant
00007 $0007 = 7 con2 equ 7 ;definitions
00008
00009
00010 0050 section vars, $50
00011 0050 byte ds 1 ;these are memory
00012 0051 word ds 2 ;reservations
00013
00014
00015 0100 section code, $100
00016
00017 [2] 0100 9C rsp ;this is assembled code
00018 [2] 0101 9B sei
00019* [3] 0102 2002 jmp jumpHere ;optimized, note the *
00020 imback
00021 [3] 0104 20FE bra *
00022 jumpHere
00023 [2] 0106 A6A1 lda #con1
00024 [4] 0108 B750 sta byte
00025 [3] 010A B607 lda con2
00026 [4] 010C B751 sta word
00027 [3] 010E 20F4 bra imback
00028
00029 0110 562300 db $56, $23, 0 ;Byte assignment
13
Using HASM 3.0
Output File
HASM 3.0 User’ s Guide
the /L switc h. As a res ult, if the fi le myfile.asm is ass emb led with th e command
line swit ch /L=lsf, the name of the listing file will be myfile.lsf. The =ext
part of the /L switch is optional.
The format of the HASM listing file is very simple. At the beginning of the file is a
standard header that contains copyright information, the assembler version, the
filenam e o f th e l is ting fi le, and the time an d da te w h en the source file was created
and when it was assembled. Next the listing of the source code begins.
The listing file is organized in a column format; different columns of the text indi-
cate different items. The following is an example of a typical source line:
In the fir st columns of each li ne contai n the line n umber of th e current fi le. Th is line
numbe r is no thing more than a simple indicator of p osition within the file and has
nothing to do with the assembled code. For lines of assembled code, the cycle
count is ne xt. C ontai ned betw een sq uar e brac k e ts, this n umber i ndica tes the n um-
ber of 68HC05 CPU cycles required to execute the instruction. An "M" in the
bra ckets ind ica tes that a macro is being invoked. After the cy cl e count is the mem-
ory address where the instruction resi des. Next comes the assembled machine
code for the instruction in the source line. Finally, the source line is displayed in
the same format as in the source file itself. Note: A asterik ( * ) after the line num-
ber indicates that particular line has been optimized.
Source lines with constant definitions, macro expansions, comments, memory
reservati ons, b yte as signmen ts and other " non-code" directiv es are displa y ed with
all pertinent information in the listing file. Example 4 shows a typical HASM listing
file.
Error File
When HASM encounters an error during assembly, it will abort the process and
notify the user. By default, HASM prints all error and warning messages to the
screen. However, if the /E command option is included, HASM will create an
ASCII text file and write all of the errors and warnings there. If an error file is cre-
ated, it is given the same base name as the source file with the .ERL extension.
F or e xample, of the name of the source file is myfile.asm, the name of the error
file will be myfile.erl. If a different extension is preferred, add the =ext direc-
tive to the /E switch. Thus, if the file myfile.asm is assembled with the com-
mand line switch /E=err, the name of the error file will be myfile.err. The
=ext part of the /E switch is optional.
00020 [2] 0101 9B sei
Line Number Cycle Count Address Location Assembled Opcode Source
Using HASM 3.0
Output File
14
2
Error messages in HASM are designed to tell the user the cause of the error,
which file is was in and on what line the error occurred. The following is a typical
error message:
A listing of all HASM errors and warnings is included in Appendix A.
Symbol File
The sy m bol fi le is the last o f th e four file types ge nerated by H ASM . By default, no
symbol file is generated when a source file is assembled. If the /S command
option in included, however, HASM will create the file with the same base file
name as the source file and the .SYM extension appended.
The purpose of the symbol file is to provide a complete listing of all constants,
variables and labels defined in the source file. While this file may not be of much
use to the programmer , it is used by Harris dev elopment tools to allow for symbolic
debugging of source code. Also, is a symbol file from one assembled program is
includ ed i n another, the new p rog ram can mak e j um ps to the labels def ine d in t he
assembled program and use all its variable definitions.
A symbol file consists of a header and the symbol table. A typical symbol file is
shown in Example 5.
Example 5. Typical HASM Symbol File
EXP1.S ( 17) ERROR: Illegal opcode/pragma: RSPS
File with error Line number Error Message
* HARRIS Semiconductor (c)1990 - 1997
* 68HC05 Assembler Version 3.0.2
* Filename: EX1.SYM
* Source created:07/28/97, 12:00 pm
* Assembled: 07/28/97, 12:00 pm
* Table of labels/symbols:
;LABEL/SYMBOL Hex Decimal
;------------------------------------------------- --- -------
BYTE equ $0050 ;V 80
CODE equ $0100 ;V 256
CON1 equ $00A1 ;K 161
CON2 equ $0007 ;K 7
IMBACK equ $0104 ;V 260
JUMPHERE equ $0106 ;V 262
VARS equ $0050 ;V 80
15
Using HASM 3.0
Output File
HASM 3.0 User’ s Guide
Using HASM 3.0
Output File
16
2
17
HASM 3.0 User’ s Guide
3
3
Source File Syntax
As stated in Chapter 2, the input to HASM is a standard text file. Control codes
should be removed and if the file is generated with a word processor such as
WordStar or WordPerfect, the file should be saved in TEXT or NON-DOCUMENT
mode.
There can be up to five main types of information contained on each line in a
source file. They are:
labels
mnemonics
mnemonic operands
comments
assembler directives (see Chapters 4-5)
The first four types are described in this ch apte r. The last type, incl uding assem-
bler pragmas and macros, are explained in Chapters 4 and 5.
Comments and Labels
HASM observes syntax rules similar to many other assemblers. Comments can
be freely placed in the input (source) fil e, provid ed th at they are either:
1. are preceeded by a semicolon ( ; ), or
2. begin with an asterik ( * ) in the first column
Comments demarcated with a semicolon can begin in any column. Additional for-
matting can be achieved with free use of blank lines. Tabs can also be used and
are expanded to standard 8th column tab stops.
Any s tring of c haracte rs which begins in fi rst co lumn on a lin e on a line is gene rally
interpreted as a label or a symbol. There are a few exceptions to this rule -- the
asterik ( * ) and semicolon ( ; ) comments already discussed and assembler prag-
NOTE: HASM is CASE INSENSITIVE in its interpretation of filenames, com-
mand line switches, symbols, labels, opcodes, and directives. The treatment of
text other than comments depends on its position on a line.
Source File Syntax
Mnemonics
18
3
mas. Pragmas are a set of predefined keywords, delimited with either a "#", a "$"
or a "/" that give HASM special instructions on how to assemble the source file.
These wi ll be dis cu ssed in detail in the next chapter.
Valid label names ma y beg in w ith an y letter of the alpha bet, a q uestio n mark ( ? ),
or an underscore ( _ ). Names ca nnot in clude arithmetic/logical operators ( + - * /
& | ^ ~ ! < > = ), nor can they include a semicolon ( ; ), nor can they be a valid
nume ric exp ression (i .e. $AF ). Labels are v alid to 50 charac ters and are in ternally
conver ted to uppercase - the label/symbol can be defined with upper and lower
case characters freely mixed to improve readability, but two labels/symbols which
differ only in case may cause errors (i.e. - RunFile and runfile will both be inter-
preted as the same item, if that’s the intent, O.K.). If a colon is used during label
definition it is interpreted as a label operator and not apart of the label itself.
Example 6 shows the usage of comments and labels.
Example 6. Using Comments and Labels
Mnemonics
The first string (often ref erred to as t oken s) which doesn’t begin in column one and
is not pre ce ede d by a semicolon ( ; ) is i nterpreted as eit her a 68H C05 ins tructi on
mnemonic or as an assembler directive. Instruction mnemonics are directly trans-
lated into the proper hex value for execution by a 68HC05 processor.
Assembler directives, on the other hand, do not generate instructions for the
68HC05 - instead they allow creation of constants (for use during assembly),
affect the memory location where the opcodes are placed and assign memory
address values to symbols (variables and constants).
The next token on a line is assumed to be the argument to the instruction/direc-
tive. If the argument count is incorrect, an error is generated. Any number of
spaces/tabs (at le ast on e i s requ ired) are a llowed betw ee n c ol umn o ne (or a label
which begins in colum n one) an d the ins truction/dire ctiv e. Similarly any n umber o f
spaces (at least one) are allowed between the instruction/ directive and its argu-
ments . Fo llowing the argum ents onl y co mm en ts pre ce ede d wi th a se mi co lon ( ; )
******************** This is a comment
; So is this ; and this is another comment, and the following
; blank line is fine
Label_here ; this is a label, and a comment on the same line
Symbol_here EQU 8 ; this is a symbol - a symbolic constant
19
Sour ce File Syntax
Numbering Formats
HASM 3.0 User’ s Guide
are allowed. Maximum line length is 200 characters! As with all HASM strings,
mnemo nic s and direc tives are case insen sit ive.
Example 7. Mnemonic and Argument Formatting
Numbering Formats
The default base of HASM is 10 (decimal). To express numbers in other form ats,
delimiters are requ ired . H ASM i s c apa ble of interpreting decim al , bin ary, hexadec-
imal and character (ASCII) numbering formats. Delimiting the different bases is
as follows:
Binary numbers must begin with either a "%", a "0B" or end with a "B"
Hexadecimal numbers must begin with a "$", a "0x" or end with an "H"
Characters must be enclosed in either single or double quotes.
Table 2 show s a comparison and the usage of the valid numeric forms for each
type.
Begin_here lda #225 ; this is a label with a command and
; an argument
sta 25 ; a command plus argument without a
; label
lda counter ; lower case and upper case
Lda Counter ; can be mixed with no affect
LDA COUNTER ; on interpretation. Use case
; to improve readability
End_here rts ;this is an instruction which takes no arguments and is tough
;to read.
A_good_one brclr 7,var,quit ; use white space to improve
; legibility !!!
Table 2. Valid Numeric Forms in HASM
Number (Decimal) Binary Hexadecimal Character
68 %1001000 $44 "D"
125 0B1111010 0x7D ‘z’
230 11100110B 0E6H
Source File Syntax
Expressions and Operators
20
3
Expres sions and Operato rs
HASM supports arithmetic, logical and comparative expressions as arguments to
opcodes and directives. Valid operators are shown in Table 3.
Note that the result of a comparative expression (those including <, >, or =) is
either "1" if the comp arison is true or a "0" if it is false. General ly comparative
operators are used only with "if" directives to control assembly.
Arguments in the ex pressions can be labels/symbols, the special current location
characters ( * or $ ), or any valid numb er. Valid labels/symbols formats have
already b een defi ne d. Forw ard re ferences of lab els is p ermitted, but symbo li c co n-
stants must be defined before being referenced. Arguments to the EQU directive
cannot be forward referenc es.
Table 3. Arithmetic, Logical and Comparative Operators in HASM
Symbol Function
+ addition and unary plus
- subtraction and unary minus
* multiplication
/ division
! exponentiation
& bitwise AND
| bitwise inclusive OR
^ bitwise exclusive OR
~ bitwise invert
> greater than
< less than
= equal to
IMPORTANT: No spaces are allowed in expressions. Parenthesis can be
used for setting precedence. Intermediate results can reach 4M, but final
results must meet the appropriate range of the instruction or directive. All
numbers are considered decimal unless denoted by binary, hex or charac-
ter operators
21
Sour ce File Syntax
Addressing Mode s
HASM 3.0 User’ s Guide
The minus sign ( - ) can be used as the first character of an expression (unary
negate) to generate a negative result. Within an expression the minus sign
requires both a l eft a nd a right op erand . Examp le 8 sh ow s some v alid H ASM arith-
metic, logical and comparative expressions.
Example 8. Valid Expressions
Addressing Modes
The addressing mode for most 68HC05 instructions can be selected by the user
through programming. HASM determines the intended address mode based on
the argument type or magnitude. The valid address modes are as follows.
Inherent
In the inherent addressing mode, all of the information needed for instruction exe-
cution is inherently known to the CPU. The only operands available for inherent
instruct ions ar e CPU regis ters (ac cum ulato r , index, stac k point er, condition co de).
This type of addressing is determined by the mnemonic.
Example of an inherent addressing instruction:
00031 [2] 0113 9C rsp
Konstant EQU ((‘F’-’A’)*16+(5*(3-2)/2)*0xffff)&0xffff
Hi_byte lda label/256 ;convenient expressions for splitting
Lo_byte ldx label&255 ;an address to upper/lower bytes
bra * ;an endless loop
bra 2** ;first star is a multiply op the 2nd
;is the current program location
ora #2!3 ;set bit 3 of A (Note: 2!3 == $08)
#if *=$100 ;tests is current location is $100
lda #$20
#endif and -3*(0-8) ;valid use of ‘-’
#if *>$1F00 ;comparative expression to test current
#error "Out of memory" ;memory location
#endif
Source File Syntax
Addressing Modes
22
3
Immediate
In the immediate addressing mode, the operand is a data byte contained in the
program memory immediately following the opcode. This type of addressing is
used when the working with constant values that are known at assembly time.
Immedi ate opera nds are denoted by pl acing a "# " in front of the m. Only integers in
the range of -127 to +255 ($00 to $FF) are valid operands for immediate address-
ing.
Example of an immediate addressing instruction:
00032 [2] 0114 A626 lda #$26
Extended
In the extended addressing mode, the address of the operand is contained in the
two bytes of program memory immediately following the opcode. With this mode,
any memory in the 68HC05 address space is addressable, including RAM, ROM
and I/O. Valid operands are integers in the range of -32768 to +65535 ($0000 to
$FFFF). The instruction lda $1025 is an extended addressing instruction.
Example of an extended addressing instruction:
00034 [4] 0118 C61223 lda $1223
Direct
The direc t addressing mode is a space and time saving version of th e extended
addressing mode. In the direct mode, the upper byte of the operand address is
assumed to be $00, thus allowing direct addressing only access to Page 0 (mem-
ory locations from $00 to $FF) . Direct mode i nstructions are one b yte sh orter tha n
extend mode ones and execute in one CPU cycle less. Since all of the main I/O
and RAM (these are the m ost frequently addressed pa rts of the 68HC0 5 memory)
this addressing mode can result in quite a time and code savings. Some instruc-
tions, are direct mode instruction only. These are the bit manipulation opcode
(BRSET, BRCLR, BSET, and BCLR). They have no extended addressing counter-
part.
Example of an extended addressing instruction:
00033 [3] 0116 B626 lda $26.
NOTE: One common problem with programmers who are new to 68HC05
assembly code is omitting the "#" in an immediate instruction. The instruction
lda #$55 will put the value $55 into the accumulator. The instruction
lda $55 will put the value in memory location $55 into the accumulator.
23
Sour ce File Syntax
Addressing Mode s
HASM 3.0 User’ s Guide
Indexed
In indexed addressing, the address of the operand is calculated by the CPU by
adding the va lue in the X register (i.e. the index register) with the immediate oper-
and(s) following the opcode in program memory, refer to as the
offset
. Up to two
bytes may be included as an offset, and as a result there are three types of
indexed addressing available in the 68HC05 architecture.
Indexed, no offset
If no offset is specified then the effective offset is $00. Thus, the operand of the
instruction is simply the value in the X register. This type of addressing can only
access the lo wer 256 b ytes of 68H C05 memory, or Page 0. Note th at there a re two
standard ways of writing the indexed, no offset mnemonic in 68HC05 assembly
source code. The first way is to simply include "x" as the argument to a valid
indexed opcode. The second method is similar except that a comma is placed
before the "x". HASM supports both styles and assembles them identically.
Examples of indexed, no offset, addressing:
00035 [3] 011B F6 lda x
00036 [3] 011C F6 lda ,x
Indexed, 1 byte offset
This indexed mode includes on immediate byte after the opcode in program mem-
ory as the offs et to the v alue in the X register. The offset and X register are added
together to get the address of the operand. This type of addressing can access
memory from $0000 to $01FE.
Example of indexed, 1 byte offset, addressing:
00037 [4] 011D E633 lda $33,x
NOTE: If the operand of a memory addressing instruction is a variable, HASM
will ca lculate the val ue of the v ariable an d use the approp riate address ing mode .
However, if the va riable is forward referenced, HA SM does not know its value at
assemble time and therefore reserve the most space available -- two by tes --
and thus uses extended addressing. Once the variable value is know, HASM
goes back and fills the value in. If the variable is a Page 0 reference, the upper
byte is filled with $00 and extended addressing is used. An exception to this is
when optimization is turned on. Then HASM knows all variable values before
assembly and will always use the correct addressing mode. See Chapter 6 for
more details on optimization.
Source File Syntax
Addressing Modes
24
3
Indexed, 2 byte offset
Indexed, 2 byte offset, addressing works similar to indexed, 1 byte offset except
that the two bytes immediately following the opcode are used as the offset. This
type of addressing can access memory from $0000 to $FFFF.
Example of indexed, 2 byte addressing:
00038 [5] 011F D61223 lda $1223,x
Relative
The relative branch instruction is only used for branch instructions. Most branch
instructions are two byte opcodes (bit test and branch instructions are contain
three bytes) -- the first byte is the opcode byte and the second byte is the relative
branch offset. This offset is a twos-compliment signed byte and is added to the
program counter to calculate the branch address. For example, if the offset is $F0,
the program will branch 16 location backwards. Since the offset is a signed byte,
the result is that branch instructions can jump 128 location backward and 127
locations forward.
All branch locations in 68HC05 source code require the address of location to
jump to. This address is almost always given in the form of a label. HASM calcu-
lates the relative branch offset from the address and will generate an error if the
jump location is beyond the -128 to 127 location range allowed by relative b ranch
instructions.
Example of relative branch addressing:
00037 [3] 011D 2EE6 bil location
Bit test and branch
Bit test and branch instructions address mem ory locations thro ugh direc t add res s-
ing (and as such can only test bits on page zero ($00-$FF) and branch using rela-
tive addressing. These instructions are generally classified under direct
addressing.
NOTE: Similar to the situation with direct and extended addressing modes,
when a variable is used as the offset to an indexed addressing instruction,
HASM will calculate the value of the variable and use the appropriate mode. If
that label is a forward reference, HASM will reserve the maximum amount of
space necessary and will always use indexed, two byte offset addressing. How-
ever, if optimization is on the correct mode will always be chosen since the label
values are known at the time of assembly. See Chapter 6 for more details.
25
Sour ce File Syntax
Supported Opcodes
HASM 3.0 User’ s Guide
Example of bit test and branch (direct) addressing:
00037 [5] 011D 060120 brset 3,portb,location
Supported Opcodes
All standard 68HC05 opcodes are supported by HASM. Opcodes exclusive to
68HC 05 cl one MCUs, like the de cimal a djust accumul a tor ins t ructi on, are not sup-
ported.
Source File Syntax
Supported Opcodes
26
3
27
HASM 3.0 User’ s Guide
4
4
Assembler Directives
Assembler directives are instructions included in the source code that are not
translated directly into machine code for the 68HC05. Instead, HASM interprets
these directives and assembles the source file accordingly. These instructions
control data allo cation , co nditio nal code as sembly, and can g enera te user de fined
errors.
There are thre e main ty pes of a ssemb ler di rectives that are recogn iz ed b y HASM:
data allocation directives
assembler control directives (often referred to as pragmas)
macro directives
This cha pter discus ses the use of the data alloc ation direc tiv es and the assem ble r
control pragmas. Macro directives are discussed in Chapter 5.
Data Allocation Directives
Data all oc atio n dire cti ves control the way HASM assem bles the source cod e into
the 68HC05 memory map. These di rectives can reserve memory space, define
data bytes, and start the code assembly at a specific address.
.ascii
Syntax:
.ascii "{ascii string}"
.ascii ’{ascii string}’
NOTE: values in curly braces ( { and } ) in the list below contain descriptive text
for the syntax description. Curly braces are not used in HASM and sould not
appear as apart of these directives.
Assembler Directives
Data Allocation Directives
28
4
Description:
The .ASCII directive is used to define ASCII text strings in memory. The text
string is located in memory at the current address where the .ASCII directive is
encountered by HASM. The argument to the .ASCII directive is a text string
delimited with either single or double quotes.
See also: DB, HEX, .BYTE, and FCB
Example:
label .ASCII "Double Quotes"
.ASCII ’Single Quotes’
boolean
See
ds
.
byte
See
ds
.
.byte
See
db.
char
See
ds.
db
Syntax:
db {byte}, [{byte}, {byte} ... ]
hex {byte} [{byte} {byte} ... ]
.byte {byte}, [{byte}, {byte} ... ]
fcb {byte} [{byte} {byte} ... ]
Description:
DB, HEX, .BYTE, and FCB are all synonyms for allocating and initializing mem-
ory locations, in byte sized portions. If no argument is given, a single byte is allo-
cated but not initialized. (This make the directives equivalent to a ds 1
29
Assembler Directives
Data Allocation Directives
HASM 3.0 User’ s Guide
directive). A series of arguments can be given, provided each argument equates
to a byte (range $00 to $FF) or is an ASCII string. Arguments can be separated
by space(s) or commas or a comma followed by space(s). The directive must
begin after column 1.
Examples:
label db $20, 2;two bytes defined
hex ’X’ ’Z’ ’S’ $55
fcb "Another string"
label2 .byte $20 %110100
ds
Syntax:
ds {value}
rmb {value}
byte {value}
char {value}
integer {value}
boolean {value}
Description:
The ds directive is one of a set of six interchangeable directives (RMB, BYTE,
CHAR, INTEGER, and BOOLEAN are the others) whose purpose is to reserve
memory in single byte increments. Like mnemonics, these directives require an
argument that defines the total number of data bytes to reserve. Note that no
value is assigned to the reserved memory. Labels can be included with these
directives and are assigned the value of the first byte allocated by the directive.
These are generally used allocating RAM space.
Examples:
label ds 2 ;two byte variable "label"
rmb 1 ;no label but 1 byte is still reserved
byte 5 ;5 bytes defined
label2 integer 10 ;10 byte array
boolean 80 ;80 byte array
Assembler Directives
Data Allocation Directives
30
4
dw
Syntax:
dw {word}, [{word}, {word} ... ]
fdb {word}, [{word}, {word} ... ]
.word {word} [{word} {word} ... ]
Description:
DW, FDB, an d .WORD are all synonyms f or allocating and initializing memory loca-
tions i n wo rd (16 bit) size d portions . Thes e direct ive work si milar to the DB, HEX,
.BYTE, and FCB directives. If no argument is given, two bytes are alloc ated but
not initialized. A series of arguments can be given, provided each argument
equates to a word (range $0000 to $FFFF). Arguments can be separated by
space(s) or commas or a comma followed by space(s). The directive must begin
after column 1.
Examples:
label dw $2022 ;1 word defined
fdb $155, $00, $1 ;3 words defined
.word "Yet Another string"
end
Syntax:
end
Description:
The END statement is used to define the end of a b loc k of s ource co de . HASM will
ignore all text from the END statement until the end of the current file.
Example:
section vectors, $1FF8
dw timer_vector
dw irq_vector
dw swi_vector
dw reset_vector
end
31
Assembler Directives
Data Allocation Directives
HASM 3.0 User’ s Guide
equ
Syntax:
{label} equ {value}
Description:
The EQU statement is used to define constant values for use in the source file. EQU
takes two arguments -- a valid label name before the directive (and beginning in
column one) and a number or numerical expression after the directive. When
asse mbling t he source file, HASM replaces all occurrences of the la bel with the
value assigned to it. Constants defined with the EQU statement can be used as
argumen ts to opcode s, in "IF" statemen ts and an yw here el se a num erical e x pres-
sion is accept ed. Nume rical argument s of the EQU statemen t CANNO T be f orw ard
references.
Examples:
label equ $34 ;label = $34
label2 equ label ;valid; label2 = label1 = $34
fcb
See
db.
fdb
See
dw.
hex
See
db.
integer
See
ds
.
org
Syntax:
org {16 bit value}
Assembler Directives
Data Allocation Directives
32
4
Description:
ORG sets the current program location; the following instructions and data are
compiled into memory beginning with that location. ORG must begin after the first
column. Valid arguments for ORG are integers between $0000 and $FFFF.
See also: SECTION
Examples:
org $100 ;program location set to $100
org start ;program location defined by "start"
rmb
See
ds
.
rmw
Syntax:
rmw {value}
word {value}
Description:
The RMW directiv e is one of a se t of directi v es (al ong wi th WORD) whos e purpose is
to reserve memory in single word increments. Like mnemonics, these directives
require an argument that defines the total number of data bytes to reserve. Note
that no value is assigned to the reserved memory. Labels can be included with
these dir ectiv e s and are as signed th e v alue of the first wo rd alloc ated b y the dire c-
tive. These are generally used allocating RAM space.
Examples:
label rmw 3 ;three word (six byte) variable "label"
word 1 ;no label but 2 bytes are still reserved
section
Syntax:
section {label}, {16 bit value}
33
Assembler Directives
Control Pragmas
HASM 3.0 User’ s Guide
Description:
The SECTION directive is very similar to the ORG statem ent in that it is used to se t
the current program location. SECTION, however, takes two arguments -- a label
and the new program location. In this way sections of code can easily be defined
with a label and location in one statement. The SECTION directive must begin
after column one.
See also: org
Example:
section code, $100 ;code = $100
.word
See
dw.
word
See
rmw.
Control Pragmas
Control directives, or pragmas, are used to control the way HASM assembles the
sour ce code . All v alid assemb ler pr agmas b egin wit h a pragm a delim iter -- eithe r a
"#", a "$" or a "/". These symbols can be used interchangeably. For the examples
shown below, the "#" is used. The "$" or the "/" could be substituted for the same
effect.
The following are all valid HASM 3.0 assembler pragmas.
else
Syntax:
#else
IMPOR TANT: All pragm as MUST be gin in colum n 1. Pragm as in an y othe r
column will be considered errors. All pragmas MUST begin with a pragma
delimiter.
Assembler Directives
Control Pragmas
34
4
#elseif
Description:
ELSE and ELSEIF are used in conjunction with the IF pragma to provide alter-
native events in the case the IF evaluat es false (or, true in the case of the IFNOT
directive). These pragmas are interpreted identically by HASM and can be used
interchangeably. The ELSE statement must come after either an IF or IFNOT
statement. Unlike the IF and IFNOT pragmas, ELSE and ELSEIF do NOT evalu-
ate an expression and do not require arguments. As a result, there can be only
one ELSE statement in a IF-ENDIF block.
See also: if, ifnot, elseif, endif
Example:
#if *>$100 ;if current location > $100
org $200 ;start new block at $200
#else org $100 ;else start new block at $100
#endif
#if label ;use label to control assembly
org $1000
#elseif
org $2000
#endif
elseif
See
else
.
endif
Syntax:
#endif
NOTE: Note: the ELSEIF pragma is included in HASM for compatibility with
other ass embl ers . Its name w ould imp ly that it, too , evaluat es argum ents li k e the
IF statements. This can be confusing, especially to those new at 68HC05 pro-
gramming. Our suggestion is to stick to the use of the ELSE statem en t.
35
Assembler Directives
Control Pragmas
HASM 3.0 User’ s Guide
Description:
The ENDIF pragma is used to mark the end of a conditional assembly IF block.
Every IF and IFNOT statement must be accompanied by a closing ENDIF to
define the conditional block.
See also: if, ifnot, else, esleif
Example:
#if *>$100 ;if current location > $100
org $200 ;start new block at $200
#endif
endmacro
Syntax:
#endmacro
Description:
The ENDMACRO pragma is used to indicate the end of a macro definition. Refer to
Chapter 5 for deatils on using macros.
endrepeat
Syntax:
#endrepeat
Description:
ENDREPEAT marks the end of a repeated block of code. See
REPEAT
for more
details.
See also: repeat
error
Syntax:
#error "{error message}"
Assembler Directives
Control Pragmas
36
4
Description:
The ERROR pragma is used to cause HASM to abort assembly. When the assem-
bly is aborted, the error message is displayed in the error output. Generally this
pragma would be used with a IF statement to guard against certain conditions
occurring during assembly.
Example:
#if *>$1EFF ;$1EFF is upper limit of ROM
#error "Out of ROM!"
#endif
if
Syntax:
#if {expression}
Description:
The IF statement begins a block of conditionally assembled code. The IF direc-
tive evaluates the expression and, if "true", assembles the source code between
the IF and a m atchi ng ELSE, ELSEIF or ENDIF prag ma. In HASM, an ex pression
is considered "true" if it exists and evaluates to a non-zero number. Likewise, an
expression is "false" if it does not exist or evaluates to zero. An y block of condition
assem bly code, begin nin g wit h an IF pragma, MUST be terminated with an
ENDIF statement.
IF stat ement s can be nested with in othe r IF statements up to 20 lev els deep. DO
NOT USE FORWARD REFERENCES. If a forward reference is used it will evalu-
ate as false the first pass and as true on successive passes.
See also: else, elseif, endif, ifnot
Example:
test1 equ 0
test2 equ 1
#if test1 ;1st IF level, this one is false
db "This part will not be assembled"
#else ;else for 1st level IF
#if test2 ;nested 2nd level IF
db "This part will be assembled"
37
Assembler Directives
Control Pragmas
HASM 3.0 User’ s Guide
#endif ;endif for 2nd level IF
#endif ;endif for 1st level IF
ifnot
Syntax:
#ifnot {expression}
or
#if not {expression}
Description:
The IFNOT pragma works in the same wa y as the IF statement , e xcep t that it has
the effect of negating the result of the evaluated expression. Thus, if the expres-
sion e valuated i s "f al se" (i.e . un de fined or zer o), the co de betw ee n the IFNOT and
matchi ng ELSE or ENDIF will be assembled. If there is an ELSE s tatement afte r an
IFNOT that e v alu ated to " fal se", the code be tween the ELSE an d ENDIF will be not
assembled. Conversely, if the IFNOT evaluates to "true", the following code up to
a ELSE or ENDIF will not be assembled. The pragmas IFNOT and IF NOT are
equivalent and may be used interchangeably.
HASM evaluates IFNOT and IF statements in a similar fashions; as such they
ma y be neste d w i thin ea ch other up to 20 l evels de ep. As wit h IF s tatements, DO
NOT USE FORWARD REFERENCES.
See also: if, else, elseif, endif
Example:
test1 equ 1
test2 equ 1
test3 equ 0
#ifnot test1
db "This will not be assembled"
#else
#if not test3
#if test2
db "This will be assembled"
#endif
#elseif
db "This will not"
#endif
#endif
Assembler Directives
Control Pragmas
38
4
include
Syntax:
#include{filename}
#include "{filename}"
#include ’{filename}’
#include <filename>
Description:
The INCLUDE pragma allows the insertion the contents of one source file into a
second file. The argument of the INCLUDE directive should be a valid DOS
path\filename for the file to be included. If single, double, or no quotes are used
around the filename, HASM searches the current working directory or the path
specified (including drive letters) for the file. However, if the filename is sur-
rounded by angle bra ck ets ( < and > ), HASM se arc hes the stan dard inclu de p ath
as sp ecified by the /I=path command line switch. See Chapter 2 for more infor-
mation on the standard search path.
Examples:
(Note: Source assembled with the switch: /i=C:\6805\ )
#include <file> ;this searches for C:\6805\<file>, the
;standard path set by the /i switch
#include "\path\file";this searches the path beginning at
;the root directory (DOS construct)
#include ’file’ ;this searches the current working
;directory
#include path\file ;this searches the path specified
list
Syntax:
#list
Description:
The LIST pragma has the function of enabling the output to the listing file. This
command is often used with the NOLIST function to "hide" blocks of code from
being displayed in the listing file.
See also: nolist
39
Assembler Directives
Control Pragmas
HASM 3.0 User’ s Guide
Example:
#nolist
db "This code is assembled but not shown"
db "in the listing file"
#list
macro
Syntax:
#macro {label}
Description:
The MACRO pragma is used to indicate the beginning of a macro definition. Refer
to Chapter 5 for deatils on using macros.
macroend
Syntax:
#macroend
Description:
The MACROEND pragma is used to indicate the end of a macro definition. Refer to
Chapter 5 for deatils on using macros.
nolist
Syntax:
#nolist
Description:
The NOLIST pragma is used to disable the output to the listing file. The command
is often used with the list directive to "hide" blocks of code.
See also: LIST
Assembler Directives
Control Pragmas
40
4
noopt
Syntax:
#noopt
Description:
The NOOPT pragma is used to disable optimization of the source code from that
point on. See Chapter 6 fo r more details.
See also: OPT
opt
Syntax:
#opt
Description:
The OPT pragma i s us ed to enable optimi za tio n of the s ou r ce c ode from that point
on. See Chapter 6 for more details.
See also: NOOPT
page
Syntax:
#page
Description:
PAGE is used to insert a form-feed character in the lis ting file.
repeat
Syntax:
#repeat {value}
41
Assembler Directives
Control Pragmas
HASM 3.0 User’ s Guide
Description:
REPEAT allows a section of code to be repeated multiple times. The source code
between the repeat and matching ENDREPEAT are assembled as many times as
defined by {value}. Each REPEAT section of code requires a closing
ENDREPEAT.
This directive is most commonly used to fill unused por tions of memory with NOP
or SWI instructions. When filling with NOPs the last several open locations are
commonly used for a JMP Begin, where Begin is the label f or the program start.
Note that listing files only contain one copy of the repeated code to conserve
space. If a complete listing is desired add a list statement as the fi rst line in t he
repeated block.
See also: ENDREPEAT
Example:
; This code will fill the rest of memory (to $1F00) with
; SWI instructions
#repeat $1F00-*
swi
#endrepeat
set
Syntax:
#set {label}
Description:
The SET pragma is used to set a label or variable to a known, "true" state. This
label will evaluate to "true" in all IF and IFNOT statements. Typically, the label is
assigned the number 1, but since "true" is defined as any non-zero number, this
should not be used to define as a constant as 1.
This pragma is typically used only in setting up conditional assembly variables at
the beginning of a source file.
See also: SETNOT
Assembler Directives
Control Pragmas
42
4
Example:
#set test1
#if test1
db "This will be assembled"
#elseif
db "This will not"
#endif
setnot
Syntax:
#setnot {label}
Description:
The SETNOT pragma is used to set a label or variable to a known, "false" state.
This label will evaluate to "false" in all IF and IFNOT statements. Essentially, the
label is assigned the nu mber 0.
This pragma is typically used only in setting up conditional assembly variables at
the beginning of a source file.
See also: SET
Example:
#setnot test1
#ifnot test1
db "This will be assembled"
#elseif
db "This will not"
#endif
43
HASM 3.0 User’ s Guide
5
5
User Defined Macros
What is a Macro?
Macros are sets of directives and assembly i nstructions that are dire ctly in serted
into the source code when they are invoked. Macros have many advantages --
simpl ified debu gging, reduc tion of code writing for rec ursiv e routines , and a highe r
lev el of abstraction improves code readibility and understanding. Also, parameters
can be passed to macros, making them even more flexible.
Defining a Macro
A macro is simply a collection of source code that is inserted into the source file
whenever the macro is invoked. Unlike subroutines which are defined in the
source program and called by the 68HC05, macros are evaluated by the assem-
bler ONLY. The machine code is generated as if the contents of the macro were
typed into the source file everywhere the macro label is found.
Before macros can be invoked in the source code, however, they must first be
defined. Forward referencing of macros is not allowed. Macros are defined using
the #macro, #macroend, and #endmacro directives.
The #macro and #endmacro (Note: #endmacro and #macroend are inter-
prete d the same b y the assemb ler and can be us ed interc hangeab ly) pr agma s are
used to define m acros w ithin the source file . T he macro definitio n pragm a #macro
tak es the n ame of the macro a s an ar gument. W hene v er a macr o is being d efined ,
HASM will not assemble the source code between the #macro and #endmacro
pragmas. The syntax of macro definitions follows:
#macro {label}
{macro source code goes here}
#endmacro ;#macroend can also be used
To inv ok e a define d macro in th e source code, s imply place the macro nam e in the
source as if it were a mnemonic. This will cause HASM to start the expansion of
the macro. The expanded macro is exactly what was defined in the macro defini-
tion, comments and all, except everything has been converted to uppercase. See
Example 9.
User Defined Macros
Labels and Comments in Macros
44
5
Example 9. Defining and In voking a Simple Macro in HASM
Note the "M" in the cycle count brackets on the source line where the macro is
invoked. This indicates that HASM has recognized the macro and is expanding it.
Labels and Comments in Macros
Labels are allo wed to be defi ne d an d re ferenced within ma cros. Label nam es tha t
are defined within macros are appended with an "_n" suffix by HASM, where n is
an incremental decimal value. In this way the assembler can make sure all labels
within macros remain local to that macro and unique within the source file. The
sour ce co de out si de of a mac ro can NOT jump to an y label with in a m acro. On th e
00001 #macro testmac ;define a macro called "testmac"
00002
00003 lda #$FF ;make a simple delay loop
00004 loop1
00005 deca
00006 bne loop1 ;this label is local
00007
00008 #endmacro
00009
00010 0100 section code, $100
00011
00012 [2] 0100 9C rsp
00013 [2] 0101 9B sei
00014 [M] 0102 testmac ;invoke macro
>> expanding macro TESTMAC ( )
00001
00002 [2] 0102 A6FF LDA #$FF ;MAKE A SIMPLE DELAY LOOP
00003 LOOP1
00004 [3] 0104 4A DECA
00005 [3] 0105 26FD BNE LOOP1 ;THIS LABEL IS LOCAL
00006
>> end of macro TESTMAC
00015 [3] 0107 20FE bra * ;loop forever
NOTE: If you use a lot of macros and are confident that the function properly,
HASM can be directed to turn of macro expansion in the listing file to "clean up"
the code. To do this, include the /M command line switch when HASM is called.
When HASM encounters a macro, the code will still be expanded and assem-
bled, however all that will appear in the listing file is line where the macro was
invoked.
45
User Defined Macros
Labels and Comments in Macros
HASM 3.0 User’ s Guide
other hand, jumps can be made from within a macro to labels out side the macro
(also, jumps can NOT be made to labels inside other macros). It s hould be noted
that when HASM encounter s a label reference within a macro, it checks to se e if
the label is "global" (i.e. defined outside the macro) before it looks for the label
within the macro definition. If a label is both global and local to a macro definition,
HASM will "shadow" the local macro labe l with the global label. Thus, if there is a
label in a macro called "jumpto" and a label outside the macro called "jumpto",
all references to "jumpto" will refer to the label o utside the macro. This is, of
course, bad form and should be avoided. HASM will generate a warning if this
conditio n occurs. Refer to Example 10 for details.
Example 10. Global and Local Variables in Macros
Note t hat in this example t here are two branche s in the mac ro tes tmac -- on e to
LOOP1 and one to LOOP2. Since the label LOOP1 in not de fine outsi de the mac r o,
this branch will alw ays jump to th e LOOP1 inside the CURRENT expansion of that
macro. Howev er, since LOOP2 is defined ou tsi de the ma cro (on line 000 17 at loca-
00001 #macro testmac ;define a macro called "testmac"
00002
00003 loop2
00004 lda #$FF ;make a simple delay loop
00005 loop1
00006 deca
00007 bne loop1 ;this label is local
00008 jmp loop2 ;will jump to global label
00009
00010 #endmacro
00011
00012 0100 section code, $100
00013
00014 [2] 0100 9C rsp
00015 [2] 0101 9B sei
00016 [M] 0102 testmac ;invoke macro
>> expanding macro TESTMAC ( )
00001
00002 LOOP2
00003 [2] 0102 A6FF LDA #$FF ;MAKE A SIMPLE DELAY LOOP
00004 LOOP1
00005 [3] 0104 4A DECA
00006 [3] 0105 26FD BNE LOOP1 ;THIS LABEL IS LOCAL
00007 [3] 0107 CC010A JMP LOOP2 ;WILL JUMP TO GLOBAL LABEL
00008
>> end of macro TESTMAC
00017 loop2 ;define global label
00018 [3] 010A 20FE bra * ;loop forever
User Defined Macros
Passing Arguments to Macros
46
5
tion $01 0A) as w ell as i nside (on l ine 00004 at locati on $0102), all jump s to LOOP2
will refer to the global label LOOP2 at $10A.
As seen in the Examples 9 and 10, comments may be included with the macro
and are expanded in the listing file (if the /M switch is not used) each time the
macro is invoked. The only change in the comments is that they are converted to
uppercase like the rest of the text in the macro.
Passing Arguments to Macros
Argument s may be passe d to a ma cro whe n ca lli ng it . T hes e arg ume nts are refer-
enced within the macro definition by the "%" character followed by the argument
number (See Example 11). HASM will generate an error if too few arguments are
passed to the macro; extra arguments are ignored.
In Exam pl e 1 1, two parameters are passed to the ma cro - $FF an d $50 . N o te tha t
these values are shown in the heading of the macro expansion. HASM does not
directly substitute the macro reference test (i.e %1, %2, etc.) with the parameter
pass ed. Instead the r eferences are treated as labels with the passed values
assigned to them. Thus, the parameter references within the macro are not
replaced with the parameters themselves. However, if you look at line 00001 of
the macro expansion, you can see the opcode LDA #%1 was assembled as
A6FF, indicative that the parameter was passed correctly. Since parameter refer-
ences are treated as labels in macro expansions, they follow the same syntax
rules as labels and c an be us ed in mathem atical expressions.
Finally, note that the "%" operator is also the binary radix operator. Outside a
macro tokens such as %1 and %10 will evaluate to the decimal numbers 1 and 2,
respec tively. In a macro , how ev er , %1 and %10 ma y repr esent parame ters passed
when invoking the macro. When assembling macros, HASM gives the "%" opera-
tor priority as a macro parameter over a b inary radix delimiter. For example, if
assembling a macro HASM reads a #%10, it will check to see if there were ten
parameters passed to the macro. If there were, %10 will evaluate to be the tenth
param eter pa ssed. If f e w er tha n ten par amete rs w ere pass ed, %10 will evaluate to
a decimal 2.
NOTE: When a macro is defined, all text (including comments) within that
macro is copied into memory for later expansion. Keep this in mind if your PC is
short on memory or you use many and/or larg e macros.
47
User Defined Macros
Nested and Recursive Macros
HASM 3.0 User’ s Guide
Example 11. Passing Arguments to Macros
Nested and Recursive Macros
HASM 3.0 does not support nested or recursive macros. No macro may be
invoked in the definition of another macro.
00001 #macro testmac ;define a macro called "testmac"
00002
00003 lda #%1 ;make a simple delay loop using
00004 loop1 ;the 1st passed parameter
00005 deca
00006 bne loop1 ;this label is local
00007 lda #%2 ;return with A=2nd parameter
00008
00009 #endmacro
00010
00011 0100 section code, $100
00012
00013 [2] 0100 9C rsp
00014 [2] 0101 9B sei
00015 [M] 0102 testmac $FF, $50 ;invoke macro
>> expanding macro TESTMAC ( $FF[255] $50[80] )
00001
00002 [2] 0102 A6FF LDA #%1 ;MAKE A SIMPLE DELAY LOOP USING
00003 LOOP1 ;THE 1ST PASSED PARAMETER
00004 [3] 0104 4A DECA
00005 [3] 0105 26FD BNE LOOP1 ;THIS LABEL IS LOCAL
00006 [2] 0107 A650 LDA #%2 ;RETURN WITH A=2ND PARAMETER
00007
>> end of macro TESTMAC
00016 [3] 0109 20FE bra * ;loop forever
User Defined Macros
Nested and Recursive Macros
48
5
49
HASM 3.0 User’ s Guide
6
6
Optimization
HASM 3.0 includes a new optimization features to help the programmer reduce
code by substituting functionally identical 68HC05 opcodes for those instructions
that take up more memory.
Optimized Assembly Language?
Assembly code, by nature, is the most efficient method of software programming.
Since all 6 8HC05 mne monic s are map ped t o mac hine code 1:1, there is n ot m uch
room for optimization. However, there are some cases when certain instructions
could be substituted with smaller (in terms of opcode bytes), functionally equiva-
lent ones. This is the case wi th following ins tances:
indexed addressing with a zero offset
extended jumps to locations within -128 and 127 locations of the current pro-
gram counter
extended subroutine calls to locations within -128 and 127 locations of the cur-
rent program counter
If opt imiza tion is enabled, HASM will search for th ese co nditions an d make the
necessary changes.
Enabling Optimization
Optimization is turned on when assembling a source file with HASM by using the
/O command line switch or whenever HASM encounters the #OPT pragma in the
source file. If on, optimization may be turned off by the #NOOPT pragm a.
How Optimization is Done
Like most mnemonic assemblers, HA SM 3.0 is a two pass assemble r. In the first
pass HASM calculates all program locations and variable values. In the second
pass the s ource c ode is as se mbled with these va riables. However, when op tim iz a-
tion is on, HASM recursively assembles the source code as many times as
needed to c om pre ss a ll instruction c apab le o f bei ng optimized. While op tim iz ati on
can s ave many byte s of ROM in a large program, it does have the drawback that
Optimization
How Optimization is Done
50
6
the extra assembly passes required by optimization increase the total assembly
time.
Optimization of Indexed Addressing
Indexed addres sing i s the metho d of us ing th e X regi ster of the 68 HC05 to acc ess
data in memory (see Chapter 3). This type of addressing is especially useful for
transferring data to and from tables in memory. If offsets are supplied with an
indexed instruction, the 68HC05 adds the offset value to the X register and uses
the resul t f or th e memo ry acces s . The offse t f or these ins tructions can be $0 0. If it
is, the one and two byte offset instructions will execute in the same way as a no
offset instruction. With op timization on, HASM will evaluate the offset of an
indexed instruction and substitute the indexed, no offset opcode if it evaluates to
$00. Example 10 shows the same bit of code assembled with and without optimi-
zation.
Example 12. Indexed Addressing Optimization
As shown in this example, the two load accumulator (LDA) instructions in the non-
optimized section of code require more ROM bytes than necessary. On line
00006, the op co de is a ss em bled as the indexed, one b y te offset i nstruction E600.
On line 00007, since the label fwdref is a forward reference, the opc ode is
asse mbled as the indexed, two byte offset i nstruction D60000. The same instruc -
tions, however, in the optimized section of code have been replaced with the
indexed, no offs et ins tructi on F6 in both c ases . Here op timizati on sa v e d 3 bytes of
NOTE: HASM will indicate that a line has been optimized in the listing file by
placin g an asterik ( * ) after the s ource fi le line numb er on the line where the op ti-
mization occurred. See Example 10 for details.
00001 $0000 = 0 label equ 0
00002
00003 0100 org $100
00004
00005 #noopt ;optimization off
00006 [4] 0100 E600 lda label,x ;these instructions are not
00007 [5] 0102 D60000 lda fwdref,x ;optimized
00008
00009 #opt ;optimization on
00010* [3] 0105 F6 lda label,x ;these instructions are
00011* [3] 0106 F6 lda fwdref,x ;optimized
00012
00013 $0000 = 0 fwdref equ 0
51
Optimization
How Optimization is Done
HASM 3.0 User’ s Guide
ROM. Savings like this can be significant especially when working with 68HC05
devices with small ROM size s like the CDP68HC05P1B. Note the optimization
asteriks on lines 00010 and 00011.
Optimization of Extended Jumps/Subroutine Calls
Another way HASM can optimize 68HC05 code is in the area of program jumps
and subroutine calls. The 68HC05 has two methods of changing the current pro-
gram lo catio n: relative branche s and direct jumps. With relative branches, a one
byte, signed twos compliment number is added to the current program counter to
get the new program location. As a result, the 68HC05 can jump -128 locations
bac kward an d 127 location s forw ard. In direct jump instructions , the address of the
new program locati on is containe d i n two bytes f ollo wi ng the op co de (the 68HC05
architecture has a maximum address space of 64kB) . This two byte address is
loaded into the program counter and the jump is made. Relative branch instruc-
tions use two bytes of memory; direct jump instructions use three. If a direct jump
is mad e to a loca tio n within -128 o r +1 27 lo cation s of t he cur rent prog ram count er,
that direct jump can be replaced with a relative branch. If optimization is on and a
direct J MP or JSR i nstruction is e ncountere d, HASM wi ll calc ulate the range of the
jump and, if they are within the relative branch range, substitute the relative
branch opcode instead. Note, however, that HASM does not convert relative
branch instructions (BRA and BSR) to direct jumps instructions. If a b ranch loca-
tion is encountered that is out of range, an error is generated. Optimization of
JMPs and JSRs is shown below in Examples 13 and 14.
Example 13. Optimization of Extended JMPs and JSRs - Non-optimized code
00001 0100 section code, $100
00002
00003 [2] 0100 A6FF lda #$FF
00004 [6] 0102 CD0108 jsr delay ;JSR in close range
00005 [3] 0105 CC0400 jmp toofar ;JMP > 127 forward
00006
00007
00008 delay ;delay subroutine
00009 [3] 0108 4A deca
00010 [3] 0109 26FD bne delay
00011 [6] 010B 81 rts
00012
00013 0400 section toofar, $400
00014 [2] 0400 A6F5 lda #$F5
00015 [6] 0402 CD0108 jsr delay ;JSR > 128 backward
00016 [3] 0405 CC0400 jmp toofar ;JMP in close range
Optimization
How Optimization is Done
52
6
Example 14. Optimization of Extended JMPs and JSRs - Optimized code
In these two examples, the same sections of code were assembled with optimiza-
tion off (Example 11) and on (Example 12). The effects of optimization can be
seen on lines 00004 and 00016 of the listing file. In Example 11, these branch
instruction were within the "relative brach" range of the 68HC05, i.e. within 127
locations forward and 128 location backward. In Example 11, HASM assembled
the mnemonic exactly as shown -- JSR DELAY was assembled as CD0108 and
JMP TOOFAR was assembled as CC0400. How e ve r , in the opt imiz ed code , these
HASM assembled these instructions as if they were written as BSR DELAY
(AD03) and BRA TOOFAR (20F9), thus saving two bytes of ROM. Note the
optimization asteriks.
00001 0100 section code, $100
00002
00003 [2] 0100 A6FF lda #$FF
00004* [6] 0102 AD03 jsr delay ;JSR in close range
00005 [3] 0104 CC0400 jmp toofar ;JMP > 127 forward
00006
00007
00008 delay ;delay subroutine
00009 [3] 0107 4A deca
00010 [3] 0108 26FD bne delay
00011 [6] 010A 81 rts
00012
00013 0400 section toofar, $400
00014 [2] 0400 A6F5 lda #$F5
00015 [6] 0402 CD0107 jsr delay ;JSR > 128 backward
00016* [3] 0405 20F9 jmp toofar ;JMP in close range
A-1
Manual Title
A
Appendix
A
Errors and W arnings
This chapter contains a listing and explanation of the error and warning message
generated by HASM 3.0. These errors will either be printed on the screen during
assembly or, if the /E command switch has been used, written to an error file.
Error and warning messages do not appear in the listing file.
Error Messages
Error messages are generated whenever HASM encounters a condition in the
source file that makes complete a s sembly of the file impossible. HASM will abort
assembly upon the detection of such errors.
{Expression} is not on page zero
The 68HC05 bit operations (BSET, BCLR, BRSET, BRCLR) all require operands
that are memory addresses located on page zero (addresses $00 - $FF). This
commonly occurs when trying to modify or test RAM locations that are above
memory location $FF.
Branch location out of range
You are trying to make a relative branch to a program location outside of the -128
to 127 locations allowed. If the cause of the error is a BRA or BSR opcode,
replace with JMP or JSR instructions, respectively. For other relative branch
instruction s , the c ode need s t o be re written to bring th e loc ation within range . T his
error will also occur if a branch is made to a label that has not been defined.
Can’t allocate space to store label {label}
HASM has used all of the free memory available in the PC. Try closing unused
prog r am s and reass em bling.
NO TE: HASM sta rts the gener ation of a listing and he x file o n the FINAL pa ss of
assemb ly. If HASM finds errors i n the sourc e file bef ore th e final pass , ne w listing
and hex files will not be generated.
Errors and Warnings
Error Messages
A-2
A
Can’t open {filename}
HASM can not open the specified file. Check to see if the file is being used by
another program.
Duplicate label name: {label}
You have used the same label name at two different location in the source file.
Labels in HASM cannot be redefined and must be unique within the source code.
Duplicate macro name: {label}
You hav e def ined tw o macros w ith the sa me name . All ma cros m ust be ass igned a
unique macro name; these names mu st not duplicate labels and variable names.
Duplicate section name: {label}
You have tried to redefine a section name with a label that already exists. Section
names, like labels, must be unique.
Error in switch
You have supplied HASM with either an invalid or duplicate command line switch.
Valid switches are listed in Appendix B.
#EQU statement has changed values during optimization
You have tried to redefine a constant during optimization. While HASM will allow
the redefinition of constants during normal assembly, during optimization this
practice is prohibited. Constants should be defined once and only once in the
source code to be optimized.
Forward reference or illegal argument for {pragma}
Certain assembler directives, like REPEAT, IF, IFNOT, and EQU do not allow
fo rward references (i.e., the label is defined in the source code AFTER its appear-
ance in the pragma construct) as apart of their argument.
Illegal address mode
The addressing mode you have written for a given opcode is illegal or not sup-
ported by the 68HC05 instruction se t. This comm only o ccurs with misplaced "#"
symbols.
A-3
Errors and Warnings
Error Messages
Manual Title
Illegal argument count
You have specified too few or too many arguments for the given opcode or
pragma. Check the construct syntax. Refer to Chapter 3 for the syntax of all
HASM assembler directives.
Illegal argument for {opcode/pragma}
You have given an assem bler directive or opc ode an unexpected or un reco gnized
argument. Refer to Chapter 4 for the syntax of all HASM assembler directives.
Illegal bit number: {number}
The 68HC05 bit ope rations (BSET, BCLR, BRSET, BRCLR) all requi re th at th e b it
number be specified as a part of the opcode. This bit number must be an integer
between 0 and 7, inclusive. Numbers outside of this range will cause this error.
Illegal index {value}, should be X
You have specified the index to an indexed addressing instruction as something
other than the X register. See Chapter 4 for details on indexed addressing.
Illegal label name: {label}
You have ref erenc ed a label that has n ot bee n def ined. To def ine a label it m ust be
apart of a SECTION directiv e o r appear in the s ource in column o ne. Se e Chapters
2 and 4 for details.
Illegal number of arguments f or {opcode/pragma}
You have specified too few or too many arguments for the given opcode or
pragma. Check the construct syntax. Refer to Chapter 4 for the syntax of all
HASM assembler directives.
Illegal PRAGMA: {pragma}
HASM could not identify the pragma listed in the error message. Check the spell-
ing of the di rective and v erify that i t is a valid HASM 3.0 pr agma . A comp lete li st of
asse mbler direct ives in shown in Chapter 4.
Illegal opcode/pragma: {opcode/pragma}
HASM coul d not i dentify the op code or pra gma list ed i n the error m essage . Chec k
the spelling of the instruction di rective and verify that it is a valid HASM 3.0
pragma or 68HC05 mnemonic. A complete list of assembler directives in shown in
Chapter 4. This error is also cause when label names are not placed in column
one.
Errors and Warnings
Error Messages
A-4
A
Illegal or out of range value
You hav e s pecifi ed a n umb er as the argume nt of a n opc ode tha t is eith er too l arge
f or the g ive n instruction or undefin ed. This c ommonl y occurs w hen 16-bit number s
are given as arguments for 8-bit expressions, especially in immediate addressing
instructions. Chapter 3 details all addressing modes and valid ranges associated
with each mode.
Illegal value {value} in statement {statement}
You have constructed an assembler directive or 68HC05 assembly opcode incor-
rectly. Refer to Chapter 4 for the syntax of all HASM assembler directives.
Missing argument for {opcode/pragma}
The 6 8HC05 opco de or HASM asse mb ler pr a gma spec if ied in the erro r statem ent
has not received all of the arguments (operands) required. Check your 68HC05
programming manual for details on the 68HC05 mnemon ic assembly la nguag e.
Chapter 4 details the usage of all HASM assembler pragmas.
More than 20 nested #IF statements
HASM allows a maximum of 20 IF and IFNOT statements to be nested within
each other.
Nested macro
You have tried to call one macro within another macro. HASM 3.0 does not sup-
port the nesting or recursion of macros. Refer to Chapt er 5 for more details.
Range error in argument: {argument}
You have specified a number as the argument of an opcode or pragma that is too
large of small for the given instruction. This commonly occurs when 16-bit num-
bers are given as arguments for 8-bit expressions, especially in immediate
addressing instructions. Chapter 3 details all addressing modes and valid ranges
associated with each mode; refer to Chapter 4 for the syntax of al l HASM assem-
bler directives.
Unmatched #ELSE (#ELSEIF) statement
HASM has either detected an ELSE (or ELSEIF) statement outside of an IF-
ENDIF construct or it has detected two consecutiv e #ELSE state ments . Ther e can
be one and o nly one #ELSE statement in an IF-ENDIF construct.
A-5
Errors and Warnings
Warning Messages
Manual Title
Unmatched #ENDIF statement
HASM ha s detec ted an ENDIF statement without an IF conditio nal as semb ly con-
struct. T her e m u st be exactly one ENDIF for each IF and IFNOT statem en t in the
source file.
Unmatched #ENDMACRO (#MACROEND) statement
HASM has detected an ENDMACRO (or MACROEND) statement outside of a macro
definition. See Chapter 5 fo r details on macro construction.
Warning Messages
HASM will also generate warning messages to inform the progr ammer that a
something has happened during assembly that, while n ot prohibitive to assembly
of the source file, still may be an undesired condition. Unlike errors, warning mes-
sages will not prevent the source file from being assembled.
JMP location in close range
You have used an extended JMP instruction in a location where it could be
replace d wi th th e relative addressing BRA opcode. This warning will not be issued
when optimization is on since HASM will substitute the BRA opcode automatically.
JSR location in close range
You have used an extended JSR instruction in a location where it could be
replace d wi th th e relative addressing BSR opcode. This warning will not be issued
when optimization is on since HASM will substitute the BSR opcode automatically.
Macro label {label} is hidden by external label
You hav e define d tw o labe ls with t he sam e nam e, o ne ins ide a mac ro an d one o ut-
side. While this is legal, any references to the identical label name, whether inside
the macro or not, will reference the "global" (i.e. the label defined outside the
macro) and not the "local" label. Refer to Chapter 5 for more details.
NOTE: Generatio n of w arning m essages can be turned o ff be usin g th e /W co m-
mand line switch .
Errors and Warnings
Special Errors
A-6
A
Redefinition of {variable}
A variable definition has been redefined in the source code. This can cause
unpredic table effects in the final assembly and should b e avoid ed.
Speci al Errors
In addition to the error messages listed here, HASM also has a complete list of
"program" errors th at occur when HASM i tself has problems assembling the
source file. These errors usually concern allocation of memory and the "hash"
look-up table generated during assembly. These errors occur quite infrequently
and are almost never seen by the users of HASM. If one of these errors does
occur, howe v er , pl ease note th e cause o f the error (i.e. computer s etup , sourc e file
syntax, etc.) and notify us by phone at 1-800-4HARRIS or by e-mail at
digiApps@harris.com
. This will allow us to resolve these errors as quickly as pos-
sible.
A-7
Errors and Warnings
Special Errors
Manual Title
Errors and Warnings
Special Errors
A-8
A
B-1
Manual Title
B
Appendix
B
HASM 3.0 Quick Reference
This chapter is included as a handy quick reference for the most commonly used
HASM and 68HC05 commands.
Command Line Switches
Table 4. Valid HASM 3.0 Command Line Switches
Switch Function Example
E[=ext] Enable error file generation, set extension name /E
/E=ERR
HSuppress generation of hex file /H
I=path Set standard search path for #include<file> direc-
tive /i=c:\6805
L[=ext] Enable listing file generation, set extension name /L
/L=LSS
MSuppress macro expansion in listing file /M
OEnable optimization /O
SEnable generation of symbol file with .SYM exten-
sion /S
WSuppress generation of warnings /W
X=ext Set filename extensi on for he x fil e /X=s19
HASM 3.0 Quick Reference
Arithmetic, Logic and Comparative Operators
B-2
B
Arithmetic, Logic and Comparative Operators
This page contain s tables showin g valid arithmetic , logic al , and compar ative oper-
ators and the valid forms of number representation in HASM 3.0
Table 5. Arithmetic, Logic and Comparative Operators
Operator Example
(Left parenthesis 64*(label-4)
)Right parenthesis (value/5)-(6+value)
+addition and unary plus 1+label
-subtraction and unary minus value-$FF
*multiplication address*$100
/division address/$100
!exponentiation 2!bit_number
&bitwise AND value&$FF
|bitwise inclusive OR value|0x45
^bitwise exclusive OR label^$05
~bitwise invert ~(2!7)
>greater than label>$100
<less than label<$100
=equal to label=$100
Table 6. Valid Numeric Forms in HASM
Number (Decimal) Binary Hexadecimal Character
68 %1001000 $44 “D”
125 0B1111010 0x7D ‘z’
230 11100110B 0E6H
B-3
HASM 3.0 Quick Reference
Assembler Directives and Pragmas
Manual Title
Assembler Directives and Pragmas
Table 7. HASM 3.0 Assembler directives
Directive Description Syntax
.ascii Defines ASCII strings in memory .ascii “{string}”
.ascii ‘{string}’
boolean Reserves n bytes of memory boolean {n}
byte Reserves n bytes of memory byte {n}
.byte Defines one byte of memory .byte {byte}, [{byte}, {byte} ..]
char Reserves n bytes of memory char {n}
db Defines one byte of memory db {byte}, [{byte}, {byte}..]
db {byte} [{byte} {byte}..]
db “Text string”
db ‘Text String’
ds Reserves n bytes of memory ds {n}
dw Defines one word of memory dw {word}, [{word}, {word}..]
dw {word} [{word} {word}..]
dw “Text string”
dw ‘Text String’
end End bloc k of assembled code end
equ Define a constant {label} equ {value}
fcb Defines one byte of memory {byte}, [{byte}, {byte}..]
fdb
hex Defines one byte of memory hex {byte}, [{byte}, {byte} ..]
integer Reserves n bytes of memory integer {n}
org Sets program location org {address}
rmb Reserves n bytes of memory rmb {n}
rmw Reserves n words of memory rmw {n}
section Sets and labels program location section {label}, {address}
word Reserves n words of memory word {n}
.word Defines one word of memory {word}, [{word}, {word}..]
HASM 3.0 Quick Reference
Assembler Directives and Pragmas
B-4
B
Table 8. HASM 3.0 Assembler Pragmas
Pragma Description Syntax
ELSE Begin alternative assembly bloc k to IF or IFNOT #else
ELSEIF Begin alternative assembly bloc k to IF or IFNOT #elseif
ENDIF End conditional IF block assembly #endif
ENDMACRO End macro definition #endmacro
ENDREPEAT End block of repeated code #endrepeat
ERROR Generate user defined error, stop assembly #error “{message}”
IF Begin conditional assembled block of code #if {expression}
IFNOT Begin conditional assembled block of code #ifnot {expression}
INCLUDE Include additional source files for assembly. If enclosed in
angle brack ets , HASM uses standard search path defined
b y the /I=path command line switch.
#include {file}
#include “{file}”
#include ‘{file}’
#include <{file}>
LIST Enable output to listing file #list
MACRO Begin macro definition #macro {label}
MACROEND End macro definition #macroend
NOLIST Disable output to listing file #nolist
NOOPT Disable optimization #noopt
OPT Enable optimization #opt
PAGE Insert form-feed into listing file #page
REPEAT Begin block of repeated code #repeat {value}
SET Define variable as TRUE #set {label}
SETNOT Define variable as FALSE #setnot {label}
NOTE: For all of the assembler pragmas listed ab ove, the pragma delimit er “#”
can be replaced with the “$” or “/” symbols interchangeably.
B-5
HASM 3.0 Quick Reference
Assembler Directives and Pragmas
Manual Title
HASM 3.0 Quick Reference
Assembler Directives and Pragmas
B-6
B
7
Index
HASM 3.0 User’ s Guide
Symbols
.ascii 27
.BYTE 28
.WORD 33
.word 33
A
addressing modes 21
direct 22
extended 22
immediate 22
indexed 23
indexed, 1 byte offset 23
indexed, 2 byte offset 24
indexed, no offset 23
inherent 21
allocation directives 27–33
tab le of B3
assembler directives 27–42
B
batch files 8
boolean 28
byte 28
C
char 28
command li ne
running HASM from 5
switches 5
usin g bat c h files with 8
comments 17
custom er sup port 3
D
db 28
directives 27–42
data allocation 27–33
pragmas 33–42
tables of B3–B4
ds 29
dw 30
E
else 33
elseif 34
end 30
endif 34
endmacro 35
endrepeat 35
equ 31
error 35
error messages A1–A5
special A6
expressions
arithmetic 20, B2
comparative 20, B2
logical 20, B2
F
fbd 31
fcb 31
H
hex 31
hex file 10
I
if 36
ifnot 37
include 38
installation 2
integer 31
L
labels 17
licensing agreement 2
list 38
listing file 11
M
macro 39
macroend 39
macros
comments in 46
defining in HASM 43
definiton of 2, 43
labels in 44
nesting 47
passing arguments to 46
pragma dire ctives 43, B4
recursive 47
messages
error A1–A5
special error A6
warning A5–A6
mnemonics 18
N
nolist 39
noopt 40
numbe ri ng formats 19, B2
O
opcodes
supported by HASM 25
operators
arithmetic 20, B2
comparative 20, B2
logical 20, B2
tab le of B2
opt 40
optimization 49–52
definition 49
enabling 49
extend ed jum ps 51
extended subroutine calls 51
indexed add res si ng 50
org 31
output files 10
error file 13
hex file 10
listing file 11
Index
8
symbol file 14
P
page 40
pragmas 33–42
definiton of 2
tab le of B4
R
repeat 40
rmb 32
rmw 32
S
section 32
set 41
setnot 42
source file
format of 17
switches, command line 5, B1
symbol file 14
Syntax 42
T
terms, definition of
assemble 2
machine code 2
macro 2
mnemonic 2
pragma 2
source code 2
W
wa rning mess age s A5–A6
disabling A5
word 33
All Ha rr is Semi con du cto r prod uct s ar e manufactured , as sembled an d te ste d und er ISO9000 quality sys te ms certific atio n.
Harr is Semiconductor products ar e sold by description only. Harri s Semiconductor reser ves the right to ma ke changes in circuit design and/o r specifications at
any time without notice. Accordingly, the reader is cautioned to verify that data sheets are current before placing orders. Information furnished by Harris is
believed to be accurate and reliable. However, no responsibil ity is assumed by Harr is or its subsidiar ies for its use; nor for any infringements of pa tents or other
rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of Harris or its subsidiaries.
Sales Office Headquarters
For general information regarding Harris Semiconductor and its products, call 1-800-4-HARRIS
NORTH AMERICA
Harris Semiconductor
P. O. Box 883, Mail Stop 53-210
Melbourne, FL 32902
TEL: 1-800-442-7747
(407) 729-4984
FAX: (407) 729-5321
EUROPE
Harris Semiconductor
Mercure Center
100, Rue de la Fusee
1130 Brussels, Belgium
TEL: (32) 2.724.2111
FAX: (32) 2.724.22.05
ASIA
Harris Semiconductor PTE Ltd.
No. 1 Tannery Road
Cencon 1, #09-01
Singapore 1334
TEL: (65) 748-4200
FAX: (65) 748-0400
SEMICONDUCTOR