home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG093.ARC
/
Z80MR.DOC
< prev
Wrap
Text File
|
1979-12-31
|
26KB
|
689 lines
Documentatioε fo≥ Z80MR
Introduction
Z80M╥ i≤ ß Z8░ macr∩ assemble≥ witΦ synta° closel∙ followinτ RMA├ anΣá MAC« ì
I⌠ assemble≤ standarΣ Z8░ mnemonic≤ int∩ aε Inte∞ He° format« Thσ resultinτ ì
filσá (whicΦá ha≤ ß .HE╪ extension⌐ caε bσ translateΣ t∩ ß .CO═á filσá witΦ ì
LOAD.CO═á (oεá you≥ CP/═ disδ tha⌠ yo⌡ receiveΣ witΦ you≥ Microbee⌐á iµá i⌠ ì
ORG'≤á a⌠ 10░ (hex)«á Iµ i⌠ ORG'≤ elsewherσ thσ .HE╪ filσ ma∙ bσ reaΣá int∩ ì
memor∙ anΣ manipulateΣ witΦ DDT.COM.
Runninτ Z80MR
Thσá filσ t∩ bσ assembleΣ mus⌠ havσ thσ exten⌠ *.AZM«á Thσ synta° t∩á loaΣ ì
thσ assemble≥ i≤ Z80M╥ <filename╛ withou⌠ thσ extent.
Wh∙ Z80
Thσá assemble≥á yo⌡á receiveΣá witΦá you≥ Microbeσá (ASM.COM⌐á i≤á aεá 808░ ì
assembler«á Thσá Microbeσá actuall∙ run≤ ß Z8░ c.p.u«á Thσ reasoεá thi≤á i≤ ì
possiblσ i≤ tha⌠ thσ Z8░ actuall∙ run≤ al∞ oµ thσ 808░ instruction≤ bu⌠á iε ì
additioεá therσá arσá morσá instruction≤ unknowε t∩á thσá 8080«á Thσá extrß ì
instruction≤á werσ designeΣ fo≥ increaseΣ speed¼á easie≥á programming¼á anΣ ì
morσ compac⌠ code«á Fo≥ thi≤ reasoε i⌠ i≤ t∩ you≥ bes⌠ advantagσ t∩ prograφ ì
iε Z8░ codσ fo≥ thσ Microbee.
Z8░ Mnemonics
Z8░á mnemonic≤á arσá ß grea⌠ improvemen⌠ t∩á 8080«á Though⌠á wa≤á giveεá t∩ ì
logical¼á universa∞á mnemonic≤ tha⌠ arσ mucΦ easie≥ t∩ remembe≥ anΣ use«á ╔ ì
learneΣá assembl∙á languagσ oε thσ 808░ anΣ resisteΣ thσ changσ t∩á Z8░á a⌠ ì
first«á Bu⌠á afte≥á usinτá Z8░ mnemonic≤ fo≥ ß shor⌠á timσá ╔á becamσá ver∙ ì
unwillinτá t∩á d∩á anythinτ witΦ 808░ code«á No≈ ╔ ruε almos⌠á ever∙á 808░ ì
prograφáá tha⌠á come≤á iεá througΦá ßá 808░á t∩á Z8░á translatinτáá prograφ ì
(XLATE2.COM)« Eveε iµ yo⌡ arσ writinτ program≤ fo≥ thσ 808░ i⌠ i≤ stil∞ fa≥ ì
easie≥ t∩ writσ iε Z8░ mnemonics«á Therσ i≤ ß specia∞ listinτ commanΣ tha⌠ ì
flag≤ Z80- onl∙ instruction≤ fo≥ thi≤ ver∙ reasoε (describeΣ later)«
Macros
Macro≤á arσá ßá wa∙ oµ writinτ subroutine≤ iε assembl∙á languagσá anΣá theε ì
callinτá thσ subroutinσ b∙ enterinτ thσ 'macr∩ nameº int∩ thσá source«á Thσ ì
macr∩á ma∙á bσ calleΣ a≤ man∙ time≤ a≤ necessar∙ anywherσ iεá thσá program« ì
Wheε thσ assemble≥ i≤ operated¼á thσ line≤ oµ sourcσ codσ tha⌠ makσ u≡á thσ ì
macr∩á wil∞ bσ inserteΣ int∩ thσ filσ b∙ thσ assembler«á Notσ tha⌠ usinτá ß ì
macr∩á doe≤á no⌠ reducσ thσ sizσ oµ thσ objec⌠ codσ tha⌠ i≤ produceΣá sincσ ì
al∞ thσ line≤ oµ codσ tha⌠ makσ u≡ thσ macr∩ definitioε arσ assembleΣá int∩ ì
thσá objec⌠ filσ a⌠ assembl∙ time«á Thi≤ i≤ calleΣ expandinτ thσ macro«á B∙ ì
usinτ thσ *MACLIS╘ O╬ option¼á thσ line≤ oµ codσ produceΣ b∙ thσá expansioε ì
oµá ß macr∩ arσ listeΣ iε thσ .PR╬ file«á Theε thσ codσ caε bσ examineΣ anΣ ì
a⌠ time≤ optimizeΣ iε certaiε locations«
Assemble≥ Syntax
Component≤ anΣ Genera∞ Forφ oµ Assembl∙ Languagσ Programs
èThσá structurσá oµá aε assembl∙ languagσ prograφ i≤ morσá importan⌠á t∩á aε ì
assemble≥ thaε thσ actua∞ instruction≤ yo⌡ write«á ┴ prograφ tha⌠ woulΣ ruε ì
beautifull∙á caε fai∞ t∩ assemblσ iµ thσ synta° i≤ no⌠ correct«á ┴á prograφ ì
witΦ n∩ error≤ a⌠ assembl∙ timσ i≤ no⌠ guaranteeΣ t∩ ruε correctl∙ ¿ o≥á a≤ ì
expecteΣ )«á Thσ assembler≤ repor⌠ oµ ░ error≤ mean≤ tha⌠ i⌠ understooΣ al∞ ì
oµá thσá instruction≤á yo⌡á entered¼á no⌠ tha⌠ you≥á prograφá i≤á logicall∙ ì
correct.
Fields
Assembler≤á arσ almos⌠ alway≤ fielΣ orienteΣ somσ t∩ ß greate≥ degreσá thaε ì
others«á ┴ fielΣ i≤ ß flexiblσ positioε iε thσ linσ oµ codσ witΦ respec⌠ t∩ ì
thσá righ⌠á margin«á Thi≤á assemble≥ recognize≤ ┤á field≤á iεá aεá assembl∙ ì
languagσ sourcσ line.
labe∞ operatioε operanΣ comment
Thσá assemble≥ know≤ wheε i⌠ ha≤ reacheΣ thσ enΣ oµ ß fielΣ wheε i⌠ see≤á ß ì
'fielΣá delimiter'«á Thi≤ caε bσ ß spacσ o≥ ß taΓ fo≥ thi≤ assemble≥ thougΦ ì
somσá requirσá tab≤ s∩ i⌠ i≤ ß gooΣ habi⌠ t∩ alway≤ usσ taΓá character≤á a≤ ì
delimiters.
Labe∞ Field
┴á symbo∞á i≤á ß worΣ useΣ t∩ represen⌠ ß number«á Symbol≤á tha⌠á refe≥á t∩ ì
addresse≤á arσá calleΣ labels«á Thσ assignmen⌠ oµ ß numbe≥ t∩ ßá labe∞á caε ì
eithe≥ bσ defineΣ a≤ thσ line≤ below
TE╬ EQ╒ 10
STAR╘ EQ╒ 100H
o≥ calculateΣ b∙ thσ assemble≥ a≤ aε addres≤ fo≥ branchinτ instructions.
START║ J╨ FINISH
NOP
NOP
FINISH║ J╨ START
Als∩á noticσá tha⌠ thσ labe∞ i≤ optiona∞ anΣ i≤ onl∙á fo≥á thσá programmer≤ ì
conveniance.
Label≤ mus⌠ appea≥ iε thσ labe∞ field«á Somσ assembler≤ allo≈ yo⌡ t∩ inden⌠ ì
label≤ bu⌠ thi≤ onσ won't.
STAR╘ EQ╒ 100H
START║ J╨ FINIS╚
Wil∞á givσá yo⌡ ß problem«á Thσ EQ╒ mus⌠ bσ iε thσ operatioε fielΣ anΣá thσ ì
labe∞ iε thσ labe∞ field.
Mos⌠á assembler≤ requirσ tha⌠ thσ undefineΣ label≤ bσ terminateΣ iε ß coloε ì
bu⌠ thi≤ assemble≥ doe≤ no⌠ requirσ ß coloε fo≥ symbol≤ iε columε 1.
STAR╘ J╨ FINISH
wil∞ no⌠ generatσ aε erro≥ bu⌠ colon≤ arσ anothe≥ gooΣ habi⌠ anΣ als∩á makσ ìèyou≥ codσ morσ readable.
Thi≤á assemble≥á onl∙á examine≤ thσ firs⌠ si° character≤ oµá an∙á labe∞á o≥ ì
symbo∞ s∩ tha⌠ iµ thσ followinτ label≤ werσ useΣ iε thσ samσ program
FINISH▒ EQ╒ 1000H
FINISH▓ EQ╒ 2000H
┴ 'Dº erro≥ (duplicatσ symbols⌐ woulΣ bσ generated.
Operatioε anΣ OperanΣ Fields
Thσ operatioε fielΣ follow≤ thσ labe∞ fielΣ anΣ ma∙ eithe≥ contaiε ß Z8░ o≡ ì
codσá mnemonic¼á aεá assemble≥ directivσ (o≥ pseud∩ op)¼á o≥ ß macr∩á call« ì
Assemble≥á directive≤á anΣ macro≤ arσ describeΣ late≥ iεá thi≤á file«á Thi≤ ì
fielΣá wil∞á usall∙ contaiε thσ mnemoniπ fo≥ ß Z8░á instruction«á Somσá Z8░ ì
instruction≤ onl∙ usσ thi≤ fielΣ whilσ other≤ contaiε aε operanΣ whicΦ wil∞ ì
bσ locateΣ iε thσ operanΣ field.
GOBACK║ O╥ A
RE╘ Z
LD A,0FFH
RET
Thσá wa∙á Z8░á mnemonic≤ werσ designed¼á thσ numbe≥á oµá nmenonic≤á iεá thσ ì
operatioεá portioε oµ instruction≤ i≤ kep⌠ t∩ ß minimuφ sincσ thσá operand≤ ì
reall∙ distinguisΦ thσ difference≤ betweeε simila≥ instructions«á Thσ firs⌠ ì
linσ abovσ i≤ ß gooΣ examplσ oµ this« Thσ operatioε i≤ aε 'ORº operatioε oε ì
thσá numbe≥á iε thσ accumulato≥ (implied⌐ witΦ anothe≥ register«á I⌠á make≤ ì
sensσá tha⌠ thσ operanΣ shoulΣ bσ thσ registe≥ containinτ thσ othe≥á numbe≥ ì
iε thσ 'ORº operation« Iε Z8░ assembl∙ languagσ thi≤ i≤ thσ case« Thσ firs⌠ ì
linσá OR'≤á thσá accumulato≥á witΦ thσ accumualato≥ (useΣá t∩á seσá iµá thσ ì
accumulato≥á contain≤ ß 0)«á Noticσ tha⌠ thσ seconΣ linσ use≤á thσá operanΣ ì
fielΣá t∩á contaiε thσ conditioε fo≥ ß conditiona∞ jum≡ (iε thi≤á casσá thσ ì
zer∩á flag)«á Thσá thirΣá linσ use≤ thσ operanΣ fielΣ t∩ contaiεá botΦá thσ ì
targe⌠á registe≥á fo≥ ß loaΣ anΣ thσ numbe≥ t∩ load«á Thσ las⌠ linσá i≤á aε ì
unconditiona∞ returε whicΦ use≤ thσ samσ operato≥ (RET⌐ a≤ thσá conditiona∞ ì
returε bu⌠ doe≤ no⌠ usσ thσ operanΣ fielΣ becausσ therσ arσ n∩ conditon≤ t∩ ì
placσ there« Thi≤ structurσ make≤ Z8░ program≤ mucΦ morσ readablσ thaε 808░ ì
program≤á a≤á wel∞á a≤á makinτ thσ instruction≤á easie≥á t∩á remember«á Thσ ì
followinτá i≤á thσá samσá codσ writteεá witΦá 808░á mnemonics«á Noticσá thσ ì
differen⌠ philosoph∙ oε thσ usσ oµ thσ fields.
GOBACK: ORA
RETZ
MVI A,0FFH
RET
Als∩ thσ L─ commanΣ iε thσ Z8░ i≤ useΣ fo≥ al∞ datß move≤ whilσ 808░á user≤ ì
mus⌠ remembe≥ ß differen⌠ mnemoniπ fo≥ differen⌠ type≤ oµ moves.
8080 Z80
MOV H,A LD H,A
MVI H,00 LD H,00
LXI H,0000 LD HL,0000
èThe Comment Field
Comment≤á arσá no⌠á limiteΣ t∩ thσ commen⌠ fielΣ anΣ caεá actuall∙á bσá thσ ì
entirσá line«á Al∞ assembler≤ recognizσ thσ semicoloε a≤ thσ beginninτ oµ ß ì
commen⌠á anΣ mos⌠ ignorσ thσ res⌠ oµ thσ line«á Fo≥á compatabilit∙á betweeε ì
assembler≤á i⌠ i≤ ß gooΣ t∩ begiε comment≤ witΦ ß semicolon«á Bu⌠ fo≥á thi≤ ì
assemble≥ thσ followinτ method≤ oµ insertinτ comment≤ arσ gooΣ syntax.
1«á Beginninτá ßá linσá witΦ aε '*º iε columε onσ cause≤ thσá assemble≥á t∩ ì
ignorσá theres⌠á oµá thσá linσ excep⌠ iµá onσá oµá thσá assemble≥á command≤ ì
(describeΣ below⌐ immediatel∙ follow≤ thσ asterisδ (n∩ embeddeΣ spaces).
2« ┴ semicoloε wil∞ causσ thσ assemble≥ t∩ conside≥ everythinτ followinτ i⌠ ì
t∩ bσ considereΣ ß comment.
3« Thσ firs⌠ blanδ encountereΣ followinτ thσ beginninτ oµ thσ operanΣ fielΣ ì
wil∞á causσ thσ assemble≥ t∩ conside≥ thσ res⌠ oµ thσ linσ t∩ bσ considereΣ ì
ß comment.
******************************************
;An adventure in Comments
* A short tale
START: JP FINISH ; finish this story
NOP ASM can't handle this
FINISH: RET Thats all folks
Would assemble with no errors. Comments do not appear in the object code.
Numbers and Bases
Thσá assemble≥á wil∞á accep⌠ number≤ iε HE╪ (basσ 16⌐ BINAR┘á (basσá 2⌐á o≥ ì
DECIMAL« He° number≤ mus⌠ enΣ witΦ aε ╚ anΣ binar∙ number≤ mus⌠ enΣ iε ß B« ì
Decima∞ number≤ shoulΣ havσ n∩ suffi° letter«á Wheε ß HE╪ digi⌠ begin≤ witΦ ì
ß letter¼ thσ lette≥ shoulΣ bσ precedeΣ witΦ ß 0.
LD A,0F3H
OR 01001000B
LD HL,4000H+28
Commanding the Assembler
Thσá primar∙ responsibilit∙ oµ thσ assemble≥ i≤ t∩ translatσ Z8░á mnemonic≤ ì
int∩á objec⌠á code«á Thσá assemble≥ als∩ recognize≤á certaiεá command≤á anΣ ì
directive≤á tha⌠á thσá programme≥ caε usσá t∩á manipulatσá thσá assembler'≤ ì
output«á Thesσá arσá ofteεá referreΣ t∩á a≤á 'pseudo-ops'«á Thi≤á assemble≥ ì
require≤á thesσá pseudo-op≤ t∩ bσ iε uppe≥ case«á ┴ descriptioεá oµá thesσ ì
command≤ follows:
ORG <expr> ; Sets the origin of the code or section of code. Actually
; it sets the reference number that the assembler uses to
; generate addresses for labels and instructions.
; <expr> could be a number or a previously defined symbol.
; e.g. ORG 0
; ORG STARTè
END <symb> ; Determines the end of an assembly language program. <symb>
; if present describes the first executable instruction of
; the program.
DW wordlist
DEFW wordlist
; Both of these have identical meanings. In assembly language
; programs, 8 bit values are called bytes and 16 bit
; values are called words. Addresses are assembled with the
; most significant byte (MSB) following the least significant
; byte (LSB) because this is how the microprocessor handles
; these values. The DW pseudo-op allows us to describe these
; values in the way we are used to (MSB first) and still
; assemble correctly for the processor.
; DW 8000H
; will assemble the same as
; DB 00H
; DB 80H
;
; If more than one word is to follow a DW following values
; should be seperated by commas
; e.g. DW 8000H,0F000H,0000H
; The wordlist can also be symbols
; e.g. START: JP FINISH
; DW START,FINISH
; FINISH: JP START
DDB wordlist
; This pseudo-op is a way of assembling 16 bit values with
; the MSB first (opposite of DW).
; DDB 8000H
; will assemble the same as
; DB 80H
; DB 00H
DB bytelist
DEFB bytelist
DEFM bytelist
DATA bytelist
; These four pseudo-ops have identical meanings. The bytelist
; can be one byte or multiple bytes seperated with commas.
; The bytes can be any mix of symbols, ascii characters in
; quotes, or numbers on the same line. This is familiar
; code in Microbee programs:
;
;ESC EQU 1BH
;CLRSCR EQU 1AH
;CRLF DDB 0D0AH
;
; ORG 100H
;
; LD DE,MES
; LD C,9
; CALL 5
; RET
;
;MES: DB CLRSCR
; DB ESC,'=',12+20H,12+20Hè ; DB '*Your Message Here *',CRLF
; DB '*Or Here*','$'
;
; END
;
; If you've been waiting for an example to enter assemble
; and run, try this one out. Just enter it (with out the
; semicolons of course) assemble it and run it as described
; in AZM-COM.DOC.
;
; The program clears the screen, positions the cursor at
; row 12 column 12 and prints the message using the BDOS
; function 9 (print string).
;
; The symbol CLRSCR is defined by an EQU to the hex code to
; clear the screen on the Microbee (^Z).
;
; The cursor positioning sequence on the Microbee consists of
; the two lead-in characters (escape and an equals sign) and
; then the row+20H and the column+20H.
;
; Since the next bytes are just a carriage return, line feed
; pair the second part of the message will appear at the
; left side of the screen. We could include extra DB's to
; position the cursor anywhere on the screen if we like.
;
; BDOS function 9 (summoned by loading a 9 in the C register
; and calling 0005H) prints the characters it finds at the
; address in the DE registers until it sees a '$'.
DS n
DEFS n ; Reserve data space ( n bytes ). This is used to position
; allocate or label data storage space in a program. n is
; a number describing the number of bytes reserved.
; DS 16
; Reserves 16 bytes. The next instruction will be located
; 16 bytes from the location counter when the DS was
; encountered.
label EQU <expr>
;
; The EQU sets the label equal to the expression. The
; label should not be terminated with a colon when used
; with an EQU pseudo-op. The label can be any symbol
; (byte or word) and the <expr> a number in any of the
; following forms:
; SWEET EQU 16 ;decimal
; SWEET EQU 10H ;hex
; SWEET EQU 00010000B ;binary
;
; With this assembler the EQU must be located in the
; operation field.
; A label defined with an EQU cannot be redefined later
; in the program.
label DEFL <expr>
;
; This assigns the value of the <expr> to the label like
; the EQU pseudo-op but a label defined with a DEFL canè ; be redefined later in the program.
*INCLUDE <filename>
*INCLUDE <filename>
; This pseudo-op causes the assembler to stop assembling
; lines in the file it is presently in and read in the
; file <filename>. It then begins assembling lines in this
; included file until it reaches the end of the file when
; it returns to the original file and resumes assembling
; lines in it once more. The <filename> can be any CPM
; filename.ext though if the extent is left off it looks
; for the given filename with an extent of .LIB. The asterisk
; must appear in column 1 with the word INCLUDE immediately
; following with no embedded spaces.
;
;*INCLUDE DRIVER.AZM ; will begin assembly on
; the file DRIVER.AZM
;*INCLUDE Z80MACRO ; will begin assembly on
; the file Z80MACRO.LIB
;
Conditional Assembly Pseudo-Ops............................................
IF <expr>
ELSE
ENDIF
Conditiona∞á assembl∙ i≤ ß wa∙ oµ writinτ ß singlσ prograφ s∩á tha⌠ ì
áááááááái⌠á caεá bσ assembleΣ differen⌠ way≤ o≥ witΦ differen⌠á option≤á b∙ ì
ááááááááonl∙á changinτá ßá couplσ oµ line≤ oµá codes«á Wheεá thσá assemble≥ ì
ááááááááencounter≤á aεá I╞á pseudo-o≡ i⌠ evaluate≤ thσá symbo∞á <expr>«á I╞ ì
áááááááá<expr╛á i≤á non-zer∩á i⌠ assemble≤ thσá followinτá line≤á unti∞á i⌠ ì
ááááááááreache≤á aε ELS┼ o≥ aε ENDIF«á Iµ <expr╛ i≤ ░ thσ line≤ arσ ignoreΣ ì
ááááááááunti∞ thσ assemble≥ encounter≤ aε ELS┼ o≥ aε ENDIF«á Iµ thσ ELS┼ i≤ ì
ááááááááencounte≥á thσ assemble≥ begin≤ assemblinτ line≤ again«á Thσá ENDI╞ ì
áááááááápseudo-o≡ cause≤ thσ assemble≥ t∩ resumσ assemblinτ al∞ lines«á Yo⌡ ì
áááááááácaε no⌠ havσ aε I╞ withou⌠ aε ENDIF.
Any of these pseudo-ops must appear in the operation field.
TRUE EQU 0FFH
FALSE EQU 0
KPRO2 EQU TRUE
KPRO10 EQU FALSE
IF KPRO2
BITPRT EQU 1CH
ELSE
BITPRT EQU 14H
ENDIF
Operators..................................................................
Operator≤á allo≈á thσ programme≥ t∩ makσ thσ assemble≥á d∩á arithmetiπá anΣ ì
logica∞á operations«á The∙á arσá usuall∙á useΣ t∩á manipulatσá operand≤á o≥ ìègeneratσá symbols«á Somσ oµ theφ arσ useΣ t∩ creatσ test≤á fo≥á conditiona∞ ì
assembly«á Therσ shoulΣ bσ n∩ embeddeΣ space≤ wheε usinτ thesσ operator≤ a≤ ì
thσ firs⌠ blanδ encountereΣ terminate≤ thσ operanΣ field«á Thσ operand≤ ma∙ ì
bσ symbol≤ o≥ number≤ iε an∙ oµ thσ bases«á Thσ operator≤ supporteΣ b∙ thi≤ ì
assemble≥ are:
Arithmetic Operators
+ ; arithmetic addition.
- ; arithmetic subtraction
* ; arithmetic multiplication
/ ; arithmetic division (truncating the result)
Logical Operators (Bit Manipulation)
&
( or .AND. ) ; logical AND operation
^
( or .OR. ) ; logical OR operation
.XOR. ; logical exclusive OR operation
\
( or .NOT. ) ; logical inversion
.SHR. ; shift left operand to right by right operand
.SHL. ; shift left operand to left by right operand
.HIGH. ; byte value is assigned the high byte of a
; 16 bit value
.LOW. ; byte value is assigned the low byte of a 16
; bit value
Conditional Assembly Operators ( return TRUE or FALSE to IF )
=
( or .EQU. ) ; logical equivalence
>
( or .GT. ) ; greater than
.UGT. ; unsigned greater than
<
( or .LT. ) ; less than
.ULT. ; unsigned less than
Listing Options Pseudo-Ops.................................................
Therσ arσ ß numbe≥ oµ listinτ options« Al∞ oµ thesσ option≤ onl∙ effec⌠ thσ ì
prin⌠á filσ (.PRN)«á Thσ option≤ includσ somσ fo≥ debugginτ a≤ wel∞ a≤ somσ ìèfo≥ thσ actua∞ forma⌠ oµ thσ filσ oε thσ page«á Thσ .PR╬ filσ i≤ thσá basiπ ì
too∞á assembl∙á languagσ programmer≤ havσ fo≥ examininτ thσ outpu⌠á oµá thσ ì
assembler«á Thσá pseudo-op≤ beginninτ witΦ aε asterisδ mus⌠ begiε iε columε ì
1.
*EJECT
( or EJEC ) ; The next line of the listing should be placed at the top
; of the next page.
*HEADING ; Place the text ( following this command ) on the top of
; each page. Usually used to date the listing file.
TITLE 'text' ; Place the text in the quotation marks (either double or
; single on the top of each page in the listing file.
SPAC n ; Leave n blank lines in the listing. Used to leave white
; space in the file with out using a page break.
*LIST ON
*LIST OFF ; Turn the listing on or off. This is usually used to omit
; long comments or certain sections from the .PRN file.
*MACLIST ON
*MACLIST OFF ; Turn the expansion of macros on or off. Seeing how the
; macros are being expanded is handy for optimizing code
; but can waste paper when that is no longer the area of
; interest.
LIST options
NLIST options ; These pseudo-ops allow you to turn any of the supported
; listing file options on (LIST) or off (NLIST) without
; changing the other options. Both of these pseudo-ops
; must be followed with one or more of the following option
; letters. If these pseudo-ops is used some options are
; on by default ( marked with (on) in the following list.
;
; A ; List all bytes in DB, DW, DDB, etc. Otherwise
; ; only the bytes that can fit in one line are
; ; included in the listing ( others are implied ).
; B ; Place symbol table into object file.
; G ; Place system generated symbols into object files
; I (on); List lines of conditional code following a false
; ; conditional. If off only the code actually
; ; assembled is listed.
; M (on); Expand macros in listing files
; O (on); Produce an object module. That is show the bytes
; ; being generated by the assembler otherwise just
; ; the source and (optionally) macro expansions.
; R ; use absolute displacement for JR and DJNZ
; S (on); List source code in listing file
; T (on); List symbol table in listing file
; X ; Generate and list cross references in listing file
; Z ; Generate an error for Z80 only opcodes. Allows you
; ; to write in Z80 mnemonics for an 8080 processor.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Error Reporting
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
èWheεá thσ assemble≥ i≤ unablσ t∩ understanΣ wha⌠ yo⌡ arσ instructinτ i⌠á t∩ ì
d∩ i⌠ generate≤ aε erro≥ message«á Thesσ arσ almos⌠ alway≤ duσ t∩ typo'≤ o≥ ì
baΣ form« I⌠ display≤ thσ erro≥ codσ belo≈ anΣ thσ linσ thσ erro≥ wa≤ founΣ ì
oε t∩ thσ consolσ anΣ als∩ display≤ thσ erro≥ code≤ iε thσ listinτ file«
D ; Duplicate symbol definition. You will see this error
; message if you do any of the following:
; Use the same symbol twice.
; FORMATX
; FORMATC
; will generate an error (only 6 significant
; characters).
; Upper and lower case symbols with the same letters
; FORMAT:
; format:
; are identical to the assembler.
; Assigning a different value to a symbol that was
; previously defined with a EQU pseudo-op.
; If you are going to reassign use DEFL.
E ; Relocation error. I believe this occurs if the assembler
; cannot reassign an address as expected.
F ; Format Error. You will see this if you break any of the
; rules regarding field use and macro format.
K ; Keyword error. This means you tried to use one of the
; assemblers reserved words or pseudo-ops as a symbol.
; ORG: JP END
; NOP
; END: JP ORG
; is in very bad taste.
L ; Label error. The attempt to assign a value to a lable was
; unsuccessful. Also remember that labels do not end in a
; colon when preceding EQU.
; START: EQU 100H ; is bad news
; START EQU 100H ; is perfect
M ; Missing label. The symbol you are using was never defined.
N ; Macro nesting error. Macros can be nested (that is a macro
; can call another macro) but if the nesting gets to deep
; the assembler will quit and give you one of these. Also,
; you can only call macros that were previously defined.
O ; Op code error. If you see this, look in the operation and
; operand fields. Consult the mnemonic table. People
; switching over from 8080 will see a few of these.
P ; Phase error. A 2 pass assembler builds a symbol table on
; the first pass and generates the object code on the second.
; If a number that it calculates for a symbol on the first
; pass does not agree with a number it generates in the
; pass this error is shown check the symbols in the line
; the error appeared.
Q ; Questionable operand. Actually theres no question about it
; it is a bad operand. Typo's give you these as well as è ; blowing op code format. Usally easy to find your mistake.
S ; Syntax error. You broke one of the syntax rules described
; above.
T ; Symbol table full. Not much you can do with this except
; pare down the code.
U ; Undefined symbol. You used a symbol but forgot to define
; it in with an EQU.
V ; Value error. Usually means you are trying to do a 16
; bit operation with an 8 bit number or the other way
; around.
Macros
Thσá macr∩ i≤ ß powerfu∞ methoΣ oµ writinτ assembl∙ languagσá programs«á I⌠ ì
make≤á i⌠á possiblσá t∩á writσ assembl∙ languagσ program≤á iεá ßá wa∙á tha⌠ ì
resemble≤ highe≥ leve∞ languages«á Iε fac⌠ b∙ creatinτ ß librar∙ oµá macro≤ ì
yo⌡ arσ iε essencσ creatinτ you≥ owε language¼ anΣ you≥ owε compiler.
Ofteεá time≤á iεá assembl∙ languagσ (particularl∙ writinτá fo≥á CP/M⌐á eacΦ ì
prograφá contain≤á sourcσá line≤á tha⌠ arσ useΣ agaiε anΣá agaiεá iεá othe≥ ì
programs«á B∙á usinτ macro≤ thσ routine≤ onl∙ neeΣ t∩ bσ writteεá oncσá anΣ ì
theε ma∙ bσ calleΣ iε an∙ program«á Thσ bes⌠ thinτ abou⌠ ß macr∩ librar∙ i≤ ì
tha⌠á onl∙ thσ macro≤ tha⌠ arσ calleΣ producσ objec⌠ code«á S∩ therσ i≤á n∩ ì
penalt∙á iεá havinτ ß macr∩ librar∙ tha⌠ i≤ largσ anΣ completσ eveε iµá yo⌡ ì
arσ onl∙ goinτ t∩ cal∞ onσ macro.
Macro≤ havσ ß forφ tha⌠ i≤ uniquσ anΣ mus⌠ bσ followeΣ closel∙ fo≥á correc⌠ ì
results« Thσ genera∞ forφ oµ ß macr∩ is
name MACRO #parameter1,#parameter2,....
instruction
instruction
instruction
.
.
.
ENDM
Thσá namσ i≤ thσ symbo∞ tha⌠ wil∞ bσ useΣ t∩ invokσ thσ macro«á MACR╧ i≤á ß ì
keyworΣá tha⌠ wil∞ indicatσ t∩ thσ assemble≥ tha⌠ ß macr∩ i≤ beinτ defined« ì
Thσá parameter≤á alway≤ mus⌠ begiε witΦ ß '#º sigε iε macro≤ anΣá the∙á arσ ì
seperateΣ b∙ commas« Thσ instructioε caε bσ Z8░ instructions¼ o≥ an∙ oµ thσ ì
assemble≥ command≤ listeΣ abovσ incudinτ conditionals«á Thσ instructioε caε ì
als∩á bσ anothe≥ macr∩ cal∞ (calleΣ nesteΣ macros⌐ bu⌠ onl∙ iµá thσá nesteΣ ì
macr∩á ha≤ beeε alread∙ defined«á Thσ END═ keyworΣ tell≤ thσ assemble≥ tha⌠ ì
i⌠á ha≤ reacheΣ thσ enΣ oµ thσ codσ tha⌠ mus⌠ bσ assembleΣ wheε thi≤á macr∩ ì
i≤ called« D∩ no⌠ usσ ß coloε behinΣ thσ macr∩ name.
Thσá previou≤á messagσ prograφ examplσ caε bσ rewritteε t∩ looδá likσá thi≤ ì
witΦ macros.
ORG 100H
*INCLUDE Z80MACROè
BDOS PRNSTR,MES
RET
MES: DB ESC,'=',12+20H,12+20H
DB '*Your message here*'
DDB CRLF
DB '*Or here*'
END
With the following macro library called Z80MACRO.LIB
;Call Bdos function #FUNCT using paramater contained in #DE
ESC EQU 1BH ; ascii escape
CRLF EQU 0D0AH ; ascii carriage return line feed
PRNSTR EQU 9
BDOS MACRO #FUNCT,#DE
LD C,#FUNCT ; FUNCTION NUMBER GOES TO C
LD DE,#DE ; GET PARAMETER
CALL 5 ; CALL BDOS
ENDM
Wσá coulΣ als∩ rewritσ thσ curso≥ positioninτ sequencσ int∩ ßá macro«á Notσ ì
ho≈ jus⌠ thi≤ smal∞ examplσ caε savσ u≤ timσ iε futurσ programs«á Also¼ thσ ì
macr∩ librar∙ i≤ ß grea⌠ placσ t∩ kee≡ frequentl∙ useΣ symbol≤ likσ ES├ anΣ ì
CRLF.
Bu⌠á wha⌠ abou⌠ usinτ addres≤ symbol≤ iε macros┐á Ho≈ caε wσ avoiΣ thσá 'Dº ì
erro≥á iµá wσ cal∞ thσ macr∩ morσ thaε once«á Thσ othe≥ keyworΣá uniquσá t∩ ì
macro≤á i≤ LOCAL«á Thi≤ make≤ thσ assemble≥ generatσ it≤ owεá uniquσá labe∞ ì
ever∙á timσ thσ macr∩ i≤ expandeΣ iε ß program«á Followinτ thσ worΣ LOCA╠ ¿ ì
whicΦ mus⌠ bσ oε thσ seconΣ linσ oµ thσ macr∩ ⌐ arσ thσ symbol≤ wσ wan⌠ thσ ì
compile≥ t∩ generatσ uniquσ label≤ for« Thesσ symbol≤ mus⌠ als∩ bσ procedeΣ ì
witΦ ß '#º sign.
AJUMP MACRO
LOCAL #ADR_Z,#BACK
OR A
JR Z,#ADR_Z
LD A,40H
JR #BACK
#ADR_Z: LD A,04H
#BACK: LD DE,0
ENDM
Thσá macr∩ itselµ i≤ no⌠ reall∙ usefu∞ bu⌠ i⌠ i≤ correc⌠ anΣ show≤ thσá usσ ì
oµ loca∞ labels.