Atari Macro Assembler UM PDF
Atari Macro Assembler UM PDF
MACRO ASSEMBLER
JI\_
ATARI®
(IA Warner Communications Company
Every effort has been made to ensure that this manual accurately documents this product of the ATARI Home Computer Division.
However, because of the ongoing improvement and update of the computer software and hardware, ATARI, INC. cannot guarantee the
accuracy of printed material after the date of publication and cannot accept responsibility for errors .::>r omissions.
Reproduction is forbidden without the specific written permission of ATARI, INC., Sunnyvale, CA 94086. No right to reproduce this docu
ment, nor the subject matter thereof, is granted unless by written agreement with, or written permission from the Corporation.
1 INTRODUCTION 1
3 FILE U S AG E 9
Statements 15
Label Field 15
Operation Field 15
Variable Field 15
Contents iii
Statement Termination 16
Comments 16
Definitions 16
Symbols and Names 16
Numbers 17
Character Strings 17
Expressions 18
Operands 18
5 M ACRO FACILITY 21
Macro Definition 21
Macro Call 21
Code Duplication 22
Nesting 22
6 PS EU DO-O P ERATIONS 23
ASSERT 23
DB 24
DC 24
OS 24
ow 25
ECHO ... ENDM 25
EJECT 26
END 26
EQU or= 27
ERR 27
IF ... ENDIF, IF ... ELSE ... ENDIF 27
INCLUDE 28
LINK 29
LIST 31
LOC 32
MACRO ... ENDM 33
ORG 35
PROC ... EPROC 35
REAL6 36
SET 36
SPACE 36
SUBTTL 37
TITLE 37
USE 38
VFD 38
iv Contents
7 PS EU DO-O P QU ICK R EFER ENC E 41
10 ERROR COD ES 51
Contents v
1
INTRODUCTION
The ATARI® Macro Assembler is a software deve lopment tool for writing 6502
assembly la ngu age programs for the ATARI 800™ Home Computer The featu res of
this assem bler i n c l ude mac ros, cond itio nal assembly, code du p l i cation, access to
l i bra ry defi nitions, program- l i st i n g control, a nd c ross-reference tabl es. I t offers fast
compil ation and uses standard 6502 m nemonics.
FEATURES OF MACROS
THIS PACKAGE
The m a c ro featu re a l l ows you to define code words to represent m u l t i p l e instruc
tions. I t makes it easy for you to use a seq uence of code many times i n a progra m .
SYSTEXT FILES
Often you w i l l want to c reate and store sym bols and macro def i n itions on a l i brary
f i l e . O nce c reated , the sym bols can be referenced by any of you r sou rce programs.
S u c h a library f i l e can ease yo u r program d evelopment effort.
The L I ST pseudo-op l ets you tailor and an notate programs to fit you r exact needs.
The pseudo-op m akes doc u mentation eas ier by a l l owing l i sti ng control and page
headings.
CROSS-REFERENCE TABLES
The Macro Asse m b l e r a l so i n c l udes a n optional c ross-refe rence table so that you
can reference labels and variables in the sou rce program quickly.
I n troduction 1
STANDARD ATARI COMPUTER AN D 6502 MN EMONICS
A fi le conta i n i ng the ATA R I Home Computer Hardware Reg ister add resses and O S
S hadow Register add resses is i n c l uded on you r M a c r o Assembler d i s kette . You may
reference standard AT A R I Com puter m nemon ics i n your programs u s i ng this fi le.
See Systext reference i n "Command L i n e Options" in Section 2.
Sta ndard MOS Tec hnol ogy 6502 m ic roprocessor cod i n g format is u sed in this
assem b l er. The formation of expressions a l so fo l l ows the standard conventions.
1. Connect the ATA R I 800 Home Computer to a te levis ion set and to a wa l l
outlet as instructed i n the operators m a n u a l .
2. Connect the ATARI 810™ Disk Drive t o the com puter console a n d t o a wal l
outlet as instructed i n the ATARI 810 Disk Drive Operators Manual. Verify
that the d i s k d r ive is set to D R I V E CODE 1 as i nstru cted in the operators
manual.
3. Open the cartridge door on the top of the computer console. Remove a l l
cartridges from the top front cartri dge s l ots. C l ose the cartridge door.
6. When the B U SY l ight goes o u t, open the disk d r ive door by press i n g the door
hand l e release lever.
7. I nsert the d i skette conta i n i ng the Macro Assembler and P rogram-Text E d itor
programs i nto disk drive 1.
2 I n troduction
After you c reate your source program, exit the Progra m-Text E d itor u s i n g the com
m a nds that wi l l return you to DOS:
1. P ress lmmll
2. Type EXIT and press (Th i s retu rns you to DOS.)
Then, to asse m b l e you r sou rce program:
1. Type the l etter L and press
2. Type AMAC a n d press
PURPOS E OF T h i s m a n u a l is i ntended to s how you how to use the Macro Assembler. I f you p l a n
t o use the Progra m-Text E d itor for c reat i n g you r source program , it is suggested
THIS MANUAL
that you read the ATARI Program-Text Editor Manual, then practice c reat i n g f i les.
A k nowledge of asse m b l y l angu age and AT ARI DOS 11 is a l so necessary. The texts
l isted below w i l l assist in your study of asse m b l y la ngu age. I f you wish to become
fam i l i a r with the spec i a l featu res of the AT A R I Home Computer, a copy of the
ATARI Technical Users Notes wi l l be needed.
AT A R I pu b l i cations:
Introduction 3
2
ASSEMBLER EXECUTION
COMMAND LINE The Macro Asse m b l er is ac cessed by the AT ARI DOS 11 Menu option L. W hen DOS
SYNTAX asks for a f i l ename to load, type:
AMAC mm1a
Once AMAC is loaded into memory, it w i l l ask you to "E nter sou rce f i l ename and
opti ons." The sou rce f i l ename m u st a lways be specif ied. Any options you wish to
use shou l d fol low the f i l ename, sepa rated by e i ther a com ma or space. The com
m and l ine is te rm inated by a carri age retu rn. The comm and l ine cannot be edited
u s ing the c u rsor control keys.
The gene ral form of the com mand l ine is: < f i l espec > opt1 , . . optn. W here
< f i l espec > is the source f i l e to be ass e m b l ed and is of the form
< dev i ce > : < f i lename > . < extension > . The above command l ine cou ld have
been typed with any m ixture of u pper- or lowercase c haracters. The asse m b l er wi l l
convert a l l comm and l ine characters to uppercase before interpretation.
COMMAND LINE The 'opt1 , . . optn' are optiona l paramete rs (in any order) c hosen from this l i st:
OPTIONS
H = Dn: G enerate object output f i l e to the specif ied disk drive
(Defau l t is H Dn:
= where n may be 1 , 2 , 3, or 4. I f no f i l ename is spec ified, the
where n is the object f i l e wi l l be named with the input source f i l ename
same disk drive as and the extension, OBJ .
the sou rce f i le)
L = P: L i st output to printer.
Assembler Execution 5
PS = n (Defa u l t is Set page s ize to < n > sou rce l i nes per page. Page s i ze
PS = 63) must be l ess than 1 27 . When page size is l ess than 1 0, no
title or s u btitle l i nes nor page ejects are printed i n the l ist
f i le, and a fu 11 c ross-refere nce is d i sa l l owed.
S = < f i l espec > Spec ify systext f i le. The S option may be repeated. The
user may specify as many systexts as des i red, so long as
combi ned number of systexts and l i nk f i les does not ex
ceed the f i l e l imit of 40 .
D : T E ST I T.ASM H = O R = F L = S:
w i l l assemble D1 : T E S T I T.ASM, suppress object f i le generation, and send a l isting
with f u l l reference map to the s c reen.
6 Assembler Execution
02 : T E S T I T.ASM S S = D 2 : M SY S . AST L = P: R = F H = O: 0 = $1 700
The assem b l e r w i l l process the two systext f i les 01 : S Y S T E XT. AST and
02:MSYS. AST, assemb le the file 02:TEST I T .ASM, produce the object f i l e
0 1 : T E S T I T . O B J w i t h a run add ress o f $1 700, a n d p r i n t a l isting w i t h fu l l refe rence
map on the pri nter.
U S ER INT ERFACE The assemb ler execution may be prematu rely termin ated by press i n g the
key . When output l isting is d i rected to the screen, its execution can be tempora ri
ha lted by simu ltaneously press i n g the key and the 1 key. Press i n g those two
keys aga i n w i l l restart exec ution.
I f a d isk-write error happens (usua l ly d isk or d i rectory fu l l) , the offe n d i n g file (ob
ject or I ist f i l e) is erased, an error message is issued to the screen, and f u rther at
tempts to write to the f i l e are suppressed. Assemb ly then cont i n ues norma l l y.
Assembly time errors are pri nted to the screen as we l l as to the l ist f i l e.
Assembler Execution 7
3
FILE USAGE
SYST EM A system text f i l e (systext) is a n assemb ly l a ngu age f i le of symbols and macro
T EXT FILES def i n itions. The programmer can predef i n e symbols here for many d ifferent pro
grams. Some examp les are:
OBJECT The object output f i l e ge nerated by the assemb l e r has a defau lt f i l e exte n s i o n of
0 BJ and is in AT A R I b i na ry format. Refer to the ATARI DOS II Reference Manual
OUT PUT FILE
for deta i l spec i f i cations of b i n a ry format.
LISTING FILE The output l i sti ng of the source prog ram gene rated by the assem b l e r has a
defa u lt exte n s i o n of P R N .
The Macro Assemb ler has a f lexible set o f l i sti n g control pseudo-ops wh i ch a l l ows
the user to generate o n l y the desired program content.
Page head i n g (u n l ess su ppressed via PS = 0) conta ins the assembler vers i o n and
page n umber as we l l as optional u ser-spec if ied title information (see T I T L E and
S U BTT L pseudo-ops).
The L I ST pseudo-op (or L command l i ne argument) controls whi ch source l i nes are
l isted. E ach code l i ne l isted beg i n s w ith 20 col umns of i n formation generated by
the assembl er.
Col umn 1 of the l isti n g output is reserved exc l u s ively for errors; a l isti n g free of
assembly errors w i l l not have any printing in col umn 1 . A n error c o u nt is reported
at the end of the assembly. (See Section 1 0, E rror Codes.")
"
File Usage 9
SOURCE LISTING 1 2
Column Description
1 E rror flag or b l a n k . See Section 1 0 for the mea n ing of error f l ags.
2 Blank.
3-6 Address l ocation of this i nstruction (va l u e of the l ocation cou nter).
9-1 8 hhhhhhhhhh is the resu ltant code. Up to f ive bytes are listed. If L I ST
G or D is i n effect, m u l t i p l e l i nes w i l l be l isted w ith u p to f ive bytes
on each.
1 1 -1 4 vvvv = v a l u e of express i o n .
1 9-20 Always b l a n k .
SAMPLE LISTING 1 /0 E Q U AT E S
= 009B EOL = $9B
= 0030 I OC B 3 = $30
= 0340 ICH I D = $0340
= 0341 I C DN O = I CH I D + 1
= 0342 I CCOM = I C DN0 + 1
= 0343 I C STA = I CCOM+1
= 0344 I C BA L = I C STA + 1
= 0345 I C BAH = I C BA L + 1
= 0346 I C PT L = I C BA H + 1
= 0347 I C PT H = I C PT L +1
= 0348 ICBLL = I C PT H +1
= 0349 ICBLH = ICBLL + 1
= 034A I CAX1 ICBLH + 1
= 034B I CAX2 = I CAX1 +1
10 File Usage
= 0003 O PEN = $03
= 0005 CETREC = $05
= 0009 PUT REC = $09
= OOOC C LOSE = $0C
= 0004 O REA D = $04
= 0008 OW R I T = $08
= 0088 EOF = $88
= E456 C I OV = $E456
= 0040 I OC B4 = $40
'
;DATA REG I O N
5000 4432 3A5445 ;N AME1 DB 'D2 :TEST1 ',EO L
= 0050 BUF1 SZ 80
= 5009 BUF1 *
;"OPEN" THE D I S K
File Usage 11
'
;ERROR - J U ST B R K
; P R I NT A RECORD
12 File Usage
51 04 A90C L2 L OA #C LOSE
51 06 904203 STA I CCOM,X
51 09 2056 E 4 J SR C I OY
51 0C A90C LOA #C L O S E
51 0 E A230 L OX # I OC B3
51 1 0 904203 STA ICCOM,X
51 1 3 2056 E 4 J SR C I OV
51 1 6 00 BRK
51 1 7 E ND
File Usage 13
SYM BOL When R S is sel ected, the short symbol map is printed at the end of the p rogram
=
MAP FORMAT l isting. For each symbol name in the program, the fol lowing is pri n ted:
n = not referenced.
< symbo l > is the name of the symbo l .
< hhhh > is the symbol v a l u e i n hexadec i m a l , or " m ac" if the n a m e is a macro.
Four symbo ls are p r i n ted on each l i ne, u s i ng the defau l t l i ne l e ngth.
Whe n R F is sel ected, the fu l l c ross-reference map f o l l ows the sou rce l isting. O n
=
ppp/11
where < ppp > equals page nu mber and < II > equals l i ne n u mber. For a defin ition
reference, the I is rep l a ced by #.
Symbo l s def ined i n a systext f i l e appear in the c ross-reference only if they are used
d u ri n g the assembly; they a re f l agged w ith an s.
14 File Usage
4
LANGUAGE STRUCTURE
A Macro Assembler sou rce program consists of a seq uence of statements, com
ments, and def i n itions. Statements are the fu ndamental units of assembly. Com
ments do not affect assembler operat ion or object output. Def i n itions may be con
d ition a l l y asse mbled, saved for later assembly, or repeated.
STAT EM ENTS A statement is d iv ided i nto three f i e l ds: a labe l f i e l d , a n operation f i e l d , and a
variable f i e l d .
LABEL FIELD
The l abel f i e l d beg i ns w i th the f i rst chara cter of the statement and is term i n ated by
a b l a n k or an end of statement. If a c o l o n (:) is the l ast character of the l abe l f ield, i t
is d isc arded . For exa m p l e:
OPERATION FIELD
The operation f i e l d beg i ns w i th the f i rst nonbl ank character after the l abe l f i e l d
and te rm i nates w i th the next b l a n k character. Machine op codes, pseudo-ops, a n d
macro c a l ls a l l o c c u r i n the ope ration f i e l d . I f this f i e l d is em pty, the variable f ield
m ust be em pty al so. For exa m p l e:
VARIABLE FIELD
The variab l e f i e l d beg i ns w i th the f i rst character after the operation f i e l d and is ter
m i nated by an end of statement. Variab les, expressions, and other argu ments used
by the operation f i e l d appear in this f i e l d . For exa m p l e:
Language Structure 15
STAT EM ENT A statement is ter m i n ated by:
T ERMINATION
Beg i n n i ng of comment (;), or
E nd-of- L i ne, or
Logical end of statement mark (!).
In the last exa m p l e (SYM BZ), one source l i ne conta ins four statements. Three of
them are ter m i nated w ith an !, the l ast by a ;. I dentical object code wou l d be
generated if the ! were repl aced by E nd-of- L i n e < E O L > . When an ! and a ; o c c u r
i ns i de q u ota tion marks, they do n o t fu nction as sep arators.
COMM ENTS A comment beg i n s w ith a ; fol l ow i n g the variable f i e l d of a statement. A com ment
affects ne ither the assembler operation nor the obj ect code generated .
Com ments that beg i n i n c o l u m n 1 are fu l l-l ine comments; they beg i n with a ; or an
* . ( P l ease note that a n * s ignif ies a comment only when found in c o l u m n 1 - col
umn 1 of i n put is l isted at col u m n 21 on an output l i sting.) A comment is ter
m i n ated by E O L .
DEFINITIONS Def i n itions beg i n with spec i f i c types of statements (MACRO, E CHO, I F). The end of
a def i n ition is dependent on what sta rted the def i n ition, for exam p l e, E N DM is
used to ter m i nate MACRO and E C H O def i n itions, whi l e E N D I F term i n ates a n I F
range.
SYM BOLS AND A symbol is a seq u ence of characters that identifies a v a l u e o r a m a c ro. The f i rst
character c a n not be a d igit. Symbols may be any length, but they m u st be u n iq u e i n
NAM ES
the f i rst s i x characters. The fol lowing characters may b e used in a symbol name:
16 Language Structure
The underl ine c haracter (_) may oc cur i n a name as written but is d i scarded.
Lowercase l etters are mapped i nto the corres pond i ng upperc ase. When a colon oc
curs as the first c h aracter in a name, it denotes a name local to the current PROC
(see PROC pseudo-op in Section 6). A colon at the end of a name in the l abel field is
i n terpreted as a ter m i n ator but in any other position, it is ignored .
Examples:
Prefix Base
% 2 B i n ary
@ 8 Octal
$ 16 H exade c i m a l
D igits greater than the radix are not a l l owed. The under l i ne character (_) is
ignored .
The Macro Assembler prov ides constant convers ion formatt i ng for 6-byte real
numbers as specif ied in the current AT A R I BAS I C Real numbers are not v a l i d ex
pression argume nts i n variable f i e l ds. (See " REA L6," pseudo-op i n Section 6).
Examples:
B l NV A L EQU %1 0 001 01 0
OCTVA L EQU @ 21 2
H EXVAL EQU $8A
CHARACT ER The assembler accepts AT ASC I I characters $20-$7E as valid characters. A char
acter string cons ists of any sequence of c haracters surrounded by s i ngle quotation
STRINGS
marks ('n . . . n'). W i t h i n a stri ng, a s i ngle quotation m a rk c h aracter is represented by
two success ive s i ngle quotation marks.
The LSTR operator returns the l ength of a character string (see "Express ions" i n this
section).
Language Structure 17
Examples:
EXPRESSIONS A n expression cons ists of operands combi ned with operators to produce a va lue.
Operators of equa l precedence are evaluated l eft to right. B rackets can be used to
override the order of eva luation, s i n ce 6502 i nstructions use parentheses for i n
d i rect address i ng. E xpress ions a re eva luated us i ng 1 6-bit twos c o m p lement (un
signed) arithmetic. Overf l ow is ignored.
Examples:
See LOC and ORC pseudo-ops for further d iscuss ion of * L and * O. Refer to the
VFD pseudo-op for deta i l s on * P.
The com parison operators return a value of zero for false and $ F F F F for true.
Numeric tests treat va lues as uns igned, so that [ -1 < 0 ] w i l l produce the a nswer
f a l se. Character string tests use the AT ASC 11 col l a t i ng sequence.
18 Language Structure
Operators
Precedence Levels
Highest B rackets
HIGH LOW DEF REV LSTR
I MOD SHL SHR
*
+ unary
+ b i n a ry
<> < <= > >= NE EQ LT LE CT CE
NOT
& AND
Lowest OR XOR
MACRO FACILITY
A macro is a seq uence of source statements that are saved and then assembled
through a m a c ro c a l l . A macro c a l l cons ists of a reference to a ma cro name in the
operation f i eld of a statement. It often i n c l udes actual para meters to be
subst ituted for formal parameters in the macro code seq u e nce, so that code
generated can vary with each assembly of the def i n ition.
Use of a macro req u ires two steps: def i n ition of the macro and reference to the
macro.
MACRO A macro definition cons ists of th ree parts: head i ng, body, and term inator.
DEFINITION
Heading A macro definition starts with the name of the macro and the
substitute parameter names in the variable f ie l d .
%1 f irst parameter
%2 second
%9 n i nth parameter
%K 4 hex d ig i ts, represe nting the serial nu mber
of this macro c a l l
%L the labe l f i e l d of the macro ca l l
% M = the name o f the m a c ro
%% repl aced by a s i ngle percent
=
Terminator A macro def i n ition is term i nated by a n E N DM pseu d o-i nstru ction.
The assembler cou nts the nesting l evel of MAC RO/ E C H O and
E N DM pairs occurring i n a macro body, so that the definition is
term i nated o n ly by the correspond i ng E N DM.
Macro Facility 21
MACRO CALL A prev i ously def ined macro is c a l l ed when its name occurs i n the operation f i e l d of
a statement. If actua l parameters appear i n the cal l , they are substituted for the
correspo n d i n g formal parameter in the macro body w ithout eva luation. O n l y after
the e n t i re body has been expanded does assembly resume. T hus the statements
generated by the macro may themselves contain further macro c a l l s or def i n itions,
with the nesting l i m ited only by ava i l able memory.
Note: When writing recurs ive m a c ros, take care in the cod i ng of the term i n ation
condition(s). A macro that repeated l y c a l ls itse l f w i l l cause the assembler to ter
m i nate (eventual l y) with the message "Memory Overf l ow ."
NESTING E C H O , MACRO, and I F blocks m ay be nested in compl etely arbitrary fashion, sub
ject o n l y to the constraint that it be properly nested; i.e., each block must be con
tai ned w i t h i n the surround i n g block.
22 Macro Facility
6
PSEUDO-OPERATIONS
The Macro Assembler prov ides a comprehens ive set of pseu do-operations (pseudo
ops) that perm its you to control the assembly process.
{exp} means that the item i n side the braces { } may appear zero or
m ore t i mes
A SS E RT a l l ows you to c heck for and f l ag i l logical assembly cond itions such as i n
correct parameter v a l u es, programs that are too l arge, and u ndef i ned symbo l s .
The expression is not exam i ned in Pass 1 of the assembl er, so A SSERT can correctly
check any condition. Forward referen ces i n the expression are eva l u ated correctly.
Examples:
To c heck that the location cou nter i n a given piece of code is w i t h i n bou nds, i n this
case be l ow $2000, add the fol lowing l i ne at the end of the assembly:
If you are writing a u t i l ity subroutine and wish to c heck that a req u ired symbo l ic
defin ition has been s u p p l ied by the user of the subroutine, you m ight code:
Pseudo-Operations 23
A S S E RT D E F [SYM B1 ]
I f the req uired symbol SYMB1 is not defined by the user wit h i n the assemb ly, a P er
ror w i l l be generated. N ote that the c heck for symbol definition is postponed u nt i l 1I
after Pass 1 , a l lowing you t o define SYMB1 a nywhere i n t h e source code.
DB DEFINE BYTE
A string wil l generate as many bytes as it has characters; the f i rst character wil l be
the first byte generated. Characters in the string generate their 7-bit ATA S C I I codes
without parity.
DB is used to i n ters perse code w ith text strings and for data tables.
The l abel field is signif i cant; it wil l address the first byte generated.
Examples:
DB $80
DB LA B, LA B2 ,3,$46,$0A F,'xX',1 7 + QVA L * 4,'coffee'
DC DEFINE CHARACTER
DC operates l ike DB, but the h i gh-order bit (parity bit) of the last byte of each ex
pression is set.
DC is used j u st l ike D B . The o n l y difference is the pa rity bit of the l ast byte of each
term.
Examples:
OS DEFINE SPACE �
OS a l l ows you to reserve l a rge b l oc k s of memory. The expression < exp1 6 > wil l be
eva l u ated as a n u n signed 1 6-bit v a l u e, and that v a l u e w i l l be used to inc remen t the
assembler's inte rnal o rig i n and location cou nters.
24 Pseudo-Operations
Mem ory a l l ocated is not init i a l ized, and w i l l conta i n u n k nown va l u es at program
execu tion time. The l a bel f i e l d is s i g n i f i cant; it w i l l add ress the f i rst memory byte
al l ocated.
DS reserves space for use at execution ti me; it can be used to "s kip over" a n ex
isting piece of ROM or prov ide for u n i n i t i a l ized data storage.
Example:
ow DEFINE WORD
DW defines the contents of b l ocks of mem ory. Val ues and exp ressio ns in the
operand fie ld a re computed as u ns igned 16-bit va l u es and pl aced in memory as a
m a c h i n e word; the asse m b l e r p l a ces the Least S i g nif icant Byte (LS B) f i rst, fol l owed
by the Most S i gnificant Byte (MSB).
The l abel f ie l d is s i gnificant; it w i l l add ress the first byte gene rated .
Examples:
Tab l e of Add resses
DW PWRON ; Power on
DW MSTRST ;Master reset
DW SYSCAL ;System cal i b rate
DW RE CAL ;Reca librat ion
DW PWRDN ; Power down
DW BUTTON ; Button press
DW E M E RG ;E mergency shutdown
DW ACTN1 ,ACTN2,ACTN3 ;Action n u m bers 1,2,3
DW 0 ;E nd of tab l e
E N DM
The l abel f i e l d is s i g n ifica nt; it add resses the v a l u e of * O w hen the E C H O pseudo
op is encou ntered.
Pseudo-Operations 25
An E C H O . . . E N DM construct may not exceed 255 repetitions; 0 (ze ro) repetitions
mea ns the ECHO . E N DM code is s k i pped. E C H O . . . E N DM is convenient for
repetitious cod i n g problems. A n E C H O E N DM seq u ence is much easier to
create and ma i ntain than, say, 1 27 repetitions of a 6-l i ne proced u re.
Example:
iglab E JE CT
ig l a b = ignored label fie l d
E J E CT forces a page eject i n the assembly listing if the listi ng is c u r rently tu rned on.
The T I T L E pseudo-op sets the internal tit le string and forces an E J E CT.
Example:
E J E CT
END EN D PROGRAM
LA B E L: E N D [exp]
E N D te l l s the assemb ler where to stop assemb ly and beg i n the c ross-reference
map. The optio n a l address f i e l d express ion specif ies the ru n address for a n object
program.
The l abel f i e l d is significant, and add resses the v a l u e of the i ntern a l *O cou nter
when the E N D is processed.
Example:
26 Pseudo-Operations
EQU or EQUATE VALUE TO SYMBOL
LA B E L : EQU < exp1 6 >
LA B E L : < exp1 6 >
EQU defi nes the symbol on the l eft as the value of the 1 6-bit expression in the
operand f i e l d .
The operand < exp1 6 > must be an abso l u te v a l u e at the time of eva l u ati on; any
symbols used i n the expression must have been prev iously defined .
Examples:
E R R a l l ows you to force an assemb ly error. The add ress f i e l d is ignored. When the
assemb l e r detects an imposs i b l e or u ndesira b l e condition at assemb ly time, E R R
a l l ows this to be f l agged .
Examples:
I F * > 4000h
E RR ; Program too long
ENDIF
Pseudo-Operations 27
I F . . . E N D I F and I F .. . E L S E . . . E N D I F control textual i n put to the assembler. At
assembly time, <exp > is eva l u ated and the res u l t determines w here the assembler
w i l l resume assemb l i ng the input file.
W henever a s i n g l e program shou ld be configured as two (or more) d istinct versio ns,
I F . . . E N D I F and I F . . . E LS E . . . E N D I F can test assembly-time v a l u es and assemble
only the appropriate sou rce l i nes.
E x press ion <exp > va l u es for an I F must be numeric; strings greater than two
c ha racters a re not a l l owed.
Any " l abel" in the l a bel f i e l d is ignored; a desc r i ptive name can be p l aced here to
he l p associate an I F w ith its E LS E (if u sed) and E N D I F .
Examples:
I N C L U D E a l l ows you to d ivide l a rge programs into manageable p ieces for ease of
ed iting, common use of librar ies, f i l e man i p u l ations, and so forth.
Example:
28 Pseudo-Operations
< D: L1 contents >
LOA L1 VAL
; * * * E nd L1 . ASM
The L I N K pseudo-op is sim i l a r to the I N C L U D E facil ity, except that link f i les are not
assem b l ed until the assemb ler reaches the end of the current i n put f i l e. W henever
a L I N K pseudo-op is found, it is stored away for processing a l ong with any other
L I N K statements encountered when the current file is f i nished processing.
A, Q, S, T, U, X.
If the < fi l espec > extension is missing, it defaults to the exten s i o n used in the cur
rent i n put file; i.e., the f i l e that contains the L I N K pseudo-op.
Pseudo-Operations 29
Examples:
L I N K a l l ows you to d ivide l a rge programs i nto managea ble p ieces for ease of
editi ng, common use of l i braries, f i l e manipu l ations, and so forth. The L I N K fac i l ity
supports l i n k i ng a c ross d i skettes, so the entire source program does not have to be
conta i n ed on the same d i skette.
Example:
The comma nd l i ne
AMAC D : L I N K E C . ASM
30 Pseudo-Operations
LIST OUTPUT LISTING CONTROL
iglab L I ST *
iglab L I ST < opt > . . , < opt >
w here: < opt > = optional minus sign fo l l owed by one of the fo l l ow i ng.
C L ist l ist i n g controls: EJ ECT, PAGE, S PACE, S U BTTL, and T I TLE l i nes (Defau l t
OFF )
D L ist detailed code: i . e . , l ist every byte gene rated by D B , DW, VF D, mu l ti-l i n e
statements, a n d s o forth.
G List all generated code: i.e., l ist every byte p l a ced i n the output object f i le,
regard l ess of origin. Ove rrides -L. (Defa u l t OFF.)
The LI ST pseudo-op ope rates on a sta c k : each e l ement of the stack is a set of op
tion f l ags. The f l ag on top of the stack controls the content of the l isti n g produced.
Eac h c a l l to the L I ST pseudo-op w i l l push, or pop, a f l ag on or from the stack.
" L I ST M" means make a copy of t h e c u r rent f l ag, sett i n g t h e M-f lag t o O N , a n d
p u s h t h e new f l a g sett ing onto t h e stack.
L I ST has obvious ap pl i c ations for detai led l isting of new l y wr itten code, deta i l ed
of u n tested macro expansions, and suppress i n g the I ist i n g of I i brary code.
I ist i n g
Example:
A common code l i brary may conta i n a set of routi nes a l l having the fol lowing I F
b l oc k a t the begi n n i n g:
Pseudo-Operations 31
Assume that the g l obal symbol I L I ST eq u a l s zero. A new f l ag sett i n g is pushed onto
the L I ST o ption stack; the options (-L, -R) specify no l i sting is to be pri nted, and no
c ross-reference accumu l ation is to be done.
N ow that the common code routine has been assemb l ed, the L I ST optio n stack w i l l
b e popped. T h i s retu rns the L I ST option stack t o its condition before the libra ry was
assembled.
L O C sets t h e location cou nter. The expression i s eva l u ated as a n u n sig ned 1 6-bit
va l u e and assigned to the Macro Assemb l e r's i nternal location cou nter ( * L).
Code gene rated while the internal LOC cou nter (* L or * ) does not eq u a l the internal
ORC cou nter ( * 0) w i l l be f l agged with # in c o l umn 7 of the list i ng.
The l abel field is s i gnificant; the l abel def ined there wi l l be set to the va l u e of *L
before * L is changed to < exp1 6 > .
LOC assists you i n generating self-over l ay i n g programs. Code generated that way
can be positi oned anywhere in memory (using O RC), and the code w i l l assemble as
if it was l ocated at the add ress expressed in the LOC statement. Of cou rse, the code
must be moved at ru n time to the address spec ified in its LOC statement before it
can be exec uted.
Code assem b l ed in one p l ace for exec u tion e l sewhere can be especia l ly handy for
ROM-resident software, when pieces of code a re copied f rom ROM to RAM before
execution.
LOC is a l so usef u l for enhancing the readabil ity of data tab les for code conversion .
T h e fo l l owing examp l e is a tab l e o f external B C D codes. T h e location cou nter is set
to the ATASCll v a l u e of the first c ha racter in the table. I n that way, the location
field of the assembly listing contains an AT ASC I I v a l u e and the generated code
field contains its associ ated external BCD v a l u e .
Examples:
; E xample of using LOC to enhance readabil ity of
;l istings. The location cou nte r wil l be set to
;the ATASC l l v a l u e that corresponds to the first
;entry of a ta b l e of external BCD val ues.
32 Pseudo-Operations
0041 # 61 E BC T B L : DB $61 ;The LOC f i e l d of the l i sting
0042# 62 DB $62 ;conta ins the ATASC l l v a l u e
0043# 63 DB $63 ;wh i c h corresponds to the
0044# 64 DB $64 ;exte rnal BCD v a l u e in the
0045# 65 DB $65 ;gene rated code fie l d .
END
n E BC T B L 0041 1# 8
COU N T 0500 1# 4 1/ 8 1 /1 2
L1 FOOA 1/ 9 1 #.1 2
w here: < body > = any des i red text w h i c h may i n c l ude:
%1 . . %9 parameters number 1 . . . 9
%K hexadecimal number of this macro c a l l
%L l abel f ie l d of macro c a l l
%M name of the macro
The symbo l s in the variab l e field represent su bstituta b l e paramete rs. The symbol
names are for doc umentation purposes o n l y and may not appear in the body of the
macro.
Pa rameters w ithin the macro are represented by %x, where x is rep l aced with a
d e c imal digit (1 -9). %K with i n the body wil l be repl aced with the serial number of
the macro c a l l as f o u r hexadecimal d igits. %L with i n the body w i l l be repl aced
with the label f ie l d of the macro c a l l . %M w ithin the body wil l be rep l aced with the
macro c a l l .
Pseudo-Operations 33
The l abel f i e l d is si gnificant; it denotes the name of the macro d u r i n g an assembly.
Macros can be u sed to gene rate many copies of a proced u re with different internal
consta nts, o r in conju nction with VF D to assemble fancy mac h i n e op c odes (see
V F D pseudo-op). There a re many other potential uses for macros; these examples
are o n l y i ntended to demonstrate some of these uses.
Example:
Example:
Example:
34 Pseudo-Operations
ORC ORIGIN COUNTER
where: < exp1 6 > any abso l u te, prev i o u s l y defined 1 6-bit
v a l u e or expression
O RG sets the add ress of the f i rst byte of a piece of code (or data) to a physical loca
tion in memory.
The label f i eld is sig n i f i cant; it wil l address the v a l u e of * L, before < exp1 6 > is
eva l u ated .
O RG is a lmost a l ways used a t t h e begin ning of a n assembly t o def ine the starting
pos ition in memory of the res u l tant code. If not exp l i cit ly set by ORG (or the 0 =
comma nd- line parameter), the defa u l t v a l u e of the origin and location cou nters is
zero.
Example:
LA B E L : PROC
< body >
E PROC
PROC te l l s the assembler that the fol lowing code is a proced u re that may contain
local symbols. A l o c a l symbol is a symbol that begins with a c o l o n (:). It does not
appear in the c ross-reference map and c a n n ot be referenced ou tside of the PROC
range.
The l a be l field is significant; it addresses the value of the * O cou nter when the
PROC statement is processed.
PROC shou l d be the first instruction of any proced u re that contains l oc a l symbol s .
When assembling l a rge programs w here symbol table space is at a premi um, l ocal
symbo l s can be used w henever appropriate to red u c e memory req uirements.
Example:
I N I T: PROC ;proced u re
LOA #0 ; let A = O
LOY #0 ; Y indexes t h rough memory
: Loop: STA ( B E G M E M),Y ; : Loop: is l o c a l symbol
I NY ;-won't appear in c ross- reference
BN E : LOOP ;Write 256 l ocations
Pseudo-Operations 35
REAL6 DEFINE REAL NUMBER VALUE
R E AL6 prov ides c onstant conversion into 6-byte real numbers as supported by the
AT A R I operating system.
The l a bel is s ig n i f i cant because it denotes the starting location of 6 bytes of the
converted number.
Example:
The expression i n the variable fie ld must be an absolute value at the time of
eva luation . Any symbols used must have been previous ly def i ned.
Example:
DB TSTVAL
where: < exp1 > , < exp2 > = unsigned, numeric expressions
S PA C E p l aces blank lines in a listi ng. I f S PA C E has one argument, it wil l output that
many b l a n k lines o n l y if doing so w i l l not exceed the length of the current page. I f
< exp1 > l i nes wil l not f i t on the current page, SPACE wil l force a n E J E CT.
36 Pseudo-Operations
If S PAC E has two arguments, they a re both eva luated and < exp1 > b l a n k l i nes w i l l
be p l aced i n the (currently on) list ing only if the current page wil I have < exp2 >
l i nes l eft afterwards. I f the current page does not have that suff ic ient room, S PA C E
wil l force a n E J E CT.
S PAC E is useful when inserted just before a sma l l procedure if X i s the l ength of the
p rocedure (X lines),
S PAC E 4,X
< procedure >
w i l l output 4 l i nes to the l isting if the procedure w i l l sti l l fit on the current page. I f
the spac i ng a n d the p rocedure wil l not f i t on the current page, S PA C E w i l l force a n
EJ ECT.
S U BTT L al l ows you to s pecify second ary tit l e information. S U BTTL without a
< string > a rgume nt is ignored. To erase the current subtitle, use an empty string.
Example:
T I T L E a l l ows you to set/reset the assemb l er's internal page-head ing string. T I T L E
w ith a string argument wil l place that str i ng i n the page header (see "Sample
Listi ng," Section 3). If the str i ng contains zero c h a racters, the page header is reset
to empty. T I T L E without a string a rgument does not a l ter the current page header.
The f i rst c a l l to T I T L E * wil l not eject a listi ng page; suc cess ive c a l l s w i l l always
force an E J E CT after any arguments are processed .
Example:
Pseudo-Operat ions 37
USE DEFINE BLOCK AREA
U S E esta b l ishes a new " U S E b l ock" or res u m es use of a prev i o u s l y esta b l ished
b l o c k . The block in use is the block i nto w h i c h code is su bsequently assemb led. A
p rogram may conta i n u p to 60 d i fferent U S E blocks. The assem b l e r is respo n s i b l e
for computing t h e length and actu al o r i g i n o f e a c h b l o c k . O r i g i n s a r e assigned to
each b l oc k in the order they are f i rst encountered.
Asso c i ated with each USE block are regi sters to m a i ntain the last v a l ues of the
o r i g i n and pos ition counters ( * 0 and * P). See O RC and VFD for a description of
those cou nters. I n it i a l ly, the va l u es of these cou nters defa u l t to zero for each U S E
b l oc k . T h e v a l u e of t he location c o u n ter (* L) is not saved, b u t set eq u a l t o the v a l u e
of the o r i g i n cou nter. I f a L O C h a d been i n effect prev i o u s ly, resett i n g of the loca
tion cou nter to prod u ce the desired res u l ts is the respon s i b i l i ty of the programmer.
USE a l l ows the programmer to specify consecu tive pieces of code i n d i scontiguous
source segments. It i s more conven ient than using ORC .
Example:
NXLAB: L OX Someth i n g
USE BTA B L
DW NXLAB ;add address to j u m p vector
USE *
STX Addr ; more
LA B E L: VFD < Fexp > \ < exp > , . . . , < Fexp > \ < exp >
VFD defi nes variable f ields. E ac h < Fexp > denotes a f i e l d width. E ac h < exp >
denotes an express ion to be p l aced i nto that f ie l d; < exp > val u es that exceed the i r
asso c i ate < Fexp > f ie l d w i d t h va l u es a r e tru n cated t o m a t c h t h e < Fexp > v a l ue.
N egative v a l ues a re eva l u ated w ith u n s i gned twos-comp lement arithmetic. For ex
a m p l e , -32768 is 32768 and -1 w i l l be represented by 65 535 . The resu ltant val ues are
tru n cated to match the < Fexp > f i e l d width.
38 Pseudo-Operations
V F D m a n ipu l ates the pos ition cou nter (* Pl to keep track of the bits rem a i n i ng i n a
byte at the end of a V F D pseudo-op. I f the next pseudo-op en c o u n tered is a nother
V F D , the next f i e l d generated w i l l beg i n with the u n used b its left in the c u rrent
byte. If the next code-generat ing pseudo-op is not V F D, the assem b l e r w i l l pad out
the u n u sed byte f ield with zeros.
V F D a l l ows you to specify arb itrar i l y c o m p l ex data fields without regard to byte or
word boundaries.
Example:
M V I N ST : V F D 2 \01 , 3 \ D DD,3\SSS
VFD can be used t h i s way i nside MACRO-E N DM constru cts to assem b l e code for
unusual processors, spec i a l peri pheral c h i ps, and so forth.
Example:
S P E C is a l a bel point to a 29-b it field def i n ition. The f i rst 7 b its conta i n the va l u e 43
octa l . The next 9 b its conta i n the tru n cated string &&. The next 1 3 b its conta i n the
va l u e 429 hexadec i m a l . The * P cou nter c u rrently poi nts i nto the fourth byte after
S P E C , with 3 bits l eft in the c u rrent byte .
Pseudo-Operations 39
7
INSTRUCTION MNEMONICS
Examples:
AMAC MOS
CMP #' ? ' CMP #' ?
L OX #high E X P LOX # > EXP
L OY # l ow E X P LOY # < EXP
Notation
DATA MOV E M E N T
Instruction Mnemonics 43
Load regi ster from memory.
AS LOA zz
BS L OA zz,X
A1 LOA (zz,X)
B1 L OA (zz),Y
AD LOA mmmm
BO LOA m m m m,X
B9 LOA mmmm,Y
A6 LOX zz
B6 L OX zz,Y
AE L OX mmmm
BE LOX m m m m,Y
A4 L OY zz
B4 LOY zz,X
AC LOY mmmm
BC L OY mm mm,X
Stack l oad/stores.
4B PHA ; Pu s h acc u m u l ator
OB PHP ; P u s h processor status
6B PLA ; Pop a c cu m u l ator
2B PLP ; Pop processor status
DYA D I C A R I T H M E T I C
A d d operand a n d carry.
69 ADC #nn
6S ADC zz
7S ADC zz,X
61 ADC (zz,X)
71 ADC (zz),Y
60 ADC mmmm
70 ADC m m m m, X
79 ADC mm mm,Y
44 Instruction Mnemonics
S u btract operand and borrow.
E9 S BC #nn
ES S BC zz
FS S BC zz,X
E1 S BC (zz,X)
F1 S BC (z z),Y
ED S BC mmmm
FD S BC mmmm,X
F9 S BC m m m m ,Y
MONAD I C ARITHMETIC
Decrement b y 1.
C6 DEC zz
D6 DEC zz,X
CE DEC mmmm
DE DEC mmmm,X
CA DEX
BB DEY
I nc rement b y 1.
E6 I NC zz
F6 I NC zz,X
EE I NC mmmm
FE I NC mmmm,X
EB I NX
CB I NY
Arithmetic contro l .
1B CLC ;C lear carry f l ag
DB CLD ;C lear dec i ma l m ode
BB CLY ; Set overf l ow f l ag
3B SEC ; Set c a r ry f l ag
F8 SED ; Set d e c i m a l mode
24 BIT zz
2C BIT mmmm
ROTAT E A N D S H I FT
46 Instruction Mnemonics
Log ical s h ift right.
4A LSR A
46 LSR zz
56 LSR zz,X
4E LSR mmmm
SE LSR mmmm,X
Rotate left.
2A ROL A
26 ROL zz
36 ROL zz,X
2E ROL mmmm
3E ROL mmmm,X
Rotate right.
6A RO R A
66 RO R zz
76 ROR zz,X
6E ROR mmmm
7E ROR mmmm,X
J U M PS
90 BCC ;If ca rry c l ear
BO BCS ;If carry set
FO BEQ ;If eq u a l ( = O)
30 BMI ;If m inus
DO BN E ;If n o t eq u a l ( < > 0)
10 BPL ;If plus
50 BVC ;If overf l ow c l ear
70 BVS ;If overflow set
4C JMP mmmm
6C JMP ( m m mm)
C A L L S U BROU T I N E
00 BRK ; Software i nterru pt
20 JSR mmmm ; J u m p su brou t i n e
R E T U R N FROM S U BROU T I N E
40 RTI ; Retu rn f rom i nterrupt
60 RTS ; R et u r n f rom s u b routi ne
M I SC E L L A N E O U S C P U CONTROL
58 CLI ;Clear interrupt mask ( E I )
EA NOP
78 SE I ; Set i n terrupt mask ( D I )
Instruction Mnemonics 47
9
I f you have a source p rogram that has been devel oped u s i n g the AT A R I Asse m b l e r
E d i to r c a rtridge, and y o u w a n t t o use t h e Macro Asse m b l e r t o assem b l e i t , y o u w i l l
have t o b e aware o f the f o l l ow i n g d ifferen ces:
Using the A TA R I Macro Assembler with the A TAR I Assembler Editor Source Files 49
10
ER RO R CODES
E rrors a re f l agged by a s i ng l e-letter code i n c o l u m n one of the output l isti ng. L i nes
conta i n i ng errors are a lways wri tten to the screen, regard l ess of the output sel ec
tion.
A Add ress error. I nstru ction spec if ied does not su pport the addres s i n g m ode
specif ied.
E E xpress ion error. An express ion on the sou rce l i ne i n the add ress f ield is
u n recogn izable.
I nstru ction f ield not recogn ized. T h ree N O P bytes a re gene rated .
N E rror in n u m ber: d igit exceeds rad ix; v a l u e exceeds 1 6 b its, and so forth.
Error Codes 51
LIMITED 90-DAY WARRANTY
ON ATARI® HOME COMPUTE R PRODUCTS
ATARI, INC ("ATA R I " ) warrants to the original consumer purchaser that this ATA RI Home Computer Product (not i nc l ud i n g computer pro
grams) shall be free from any defects in material or workmansh i p for a period of 90 days from the date of purchase. If any such defect is
d i scovered wit h i n the warranty period, ATA R l ' s sole obligation w i l l be to repa i r or replace, at its election, the Computer Product free of
charge on receipt of the unit (charges prepaid, if mai led or s h i pped) with proof of date of purchase sati sfactory to ATAR I at any authorized
ATARI Computer Service Center. For the location of an authorized ATA RI Computer Service Center nea rest you,
call toll-free: In California (800) 672-1 430 or write to: Atari, I nc.
Continental U . S . (800) 538-8737 Customer Service/Field Su pport
1 340 Bordeaux Drive
S u n nyvale, CA 94086
YOU MUST RETURN DEFECTIVE COMPUTER PRODUCTS TO AN AUTHORIZED ATARI COMPUTER S E RV I C E C E NTER FOR I N
WARRANTY REPA I R.
This warranty shall not apply if the Computer Product: (i) has been m i sused or shows signs of excessive wear, (i i ) has been damaged by be
i ng used with any products not supplied by ATA R I , or ( i i i ) has been damaged by being serviced or modified by anyone other than a n
authorized ATARI Computer Service Center.
ANY APPLICABLE I M P L I E D WARRANTIES, I N C LU D I NG WARRANTI ES OF M E RC H A NTA B I L ITY A N D FITNESS FOR A PARTICU LAR PU R
POSE, ARE H EREBY LIMITED TO N I N ETY DAYS FROM T H E DATE OF PU RCHASE. CON S EQU ENTIAL OR I NC I D E NTAL DAMAG ES
RESULTING FROM A BREACH OF ANY APPLICABLE EXPRESS O R I M P L I E D WARRANTIES ARE H E REBY EXC L U D E D . Some states do not
a l low l i m itations on how long an i m p l i ed warranty lasts or do not a l l ow the exclusion or l i m itation of i ncidental or consequential damages,
so the above l i m itations or exclusions may not apply to you.
This warranty gives you specific legal rights and you may also have other rights which vary from state to state.
DISCLAIME R OR WARRANTY
ON ATARI COMPUTER PROGRAMS
A l l ATARI computer programs are d i stri buted on an "as is" basis without warranty of any ki n d . The entire risk as to the qual ity and perfor
mance of such programs is with the purchaser. Should the programs prove defective following t he i r p u rchase, the purchaser and not the
man ufacturer, distributor, or reta i l er assumes the entire cost of a l l necessary servicing or repa i r .
ATARI shall have no liabi l ity or responsi bil ity to a p u rchaser, customer, or any other person or entity with respect to any l i abil ity, loss, o r
damage caused d i rectly or i n d i rectly b y computer programs sold b y ATA R I . T h i s d i sc l a i m e r i nc l udes b u t i s not l i m ited to any i nterruption of
service, loss of busi ness or antici patory profits, or consequential damages resulting from the use or operation of such computer programs.
RE PA I R SERVICE
If your ATARI Home Computer Product req ui res repa i r other than under warranty, please contact your local authorized ATAR I Computer
Service Center for repa i r i nformation.
IMPORTANT: If you ship your ATA RI Home Computer Prod uct, package it securely and ship it, cha rges prepaid and i ns u red, by parcel post
or U n ited Parcel Service.