Changes

Z80 Assembler Reference Manual

391 bytes added, 10:32, 31 July 2017
no edit summary
The assembler is named zas, and is invoked as follows:
ZAS options files ...
of any length, and all characters are significant. The characters used to form a symbol may be chosen from the upper
and lower case alphabetics, the digits 0-9, and the special
 
symbols underscore ('_'), dollar ('$') and question mark
('?'). The first character may not be numeric. Upper and
entry_point: ;This is referenced from far away
ld b,10
1: dec c
jr nz,2f ;if zero, branch forward to 2: ld c,8 djnz 1b ;decrement and branch back to 1: jr 1f ;this does not branch to the ;same label as the djnz
2: call fred ;get here from the jr nz,2f
1: ret ;get here from the jr 1f
{|
|+!Character|| !! Radix|| !! Name
|-
!|B|| 2|| binary
|-
!|O|| 8|| octal
|-
!|Q|| 8|| octal
|-
!|o|| 8|| octal
|-
!|q|| 8|| octal
|-
!|H|| 16|| hexadecimal
|-
!|h|| 16|| hexadecimal
|}
{|
|+!Operator|| !! Meaning
|-
!|&|| Bitwise AND
|-
!|*|| Multiplication
|-
!|<nowiki>+</nowiki>|| Addition
|-
!|<nowiki>-</nowiki>|| Subtraction.and.|| Bitwise AND
|-
!|.eqand.|| Equality test Bitwise AND
|-
!|.gteq.|| Signed greater thanEquality test
|-
!|.highgt.|| Hi byte of operand Signed greater than
|-
!|.lowhigh.|| Low Hi byte of operand
|-
!|.ltlow.|| Signed less than Low byte of operand
|-
!|.modlt.|| Modulus Signed less than
|-
!|.notmod.|| Bitwise complementModulus
|-
!|.ornot.|| Bitwise orcomplement
|-
!|.shlor.|| Shift left Bitwise or
|-
!|.shrshl.|| Shift rightleft
|-
!|.ultshr.|| Unsigned less thanShift right
|-
!|.ugtult.|| Unsigned greater less than
|-
!|.xorugt.|| Exclusive orUnsigned greater than
|-
!/|.xor.| Divison| Exclusive or
|-
!<|/|| Signed less thanDivison
|-
!=|<|| EqualitySigned less than
|-
!>|=|| Signed greater thanEquality
|-
!|>|| Signed greater than|-|^|| Bitwise or
|}
psect text, global
alabel:
ld hl,astring call putit ld hl,anotherstring
psect data, global
astring:
defm 'A string of chars' defb 0 anotherstring: defm 'Another string' defb 0
psect text
putit:
ld a,(hl) or a ret z call outchar inc hl jr putit
==== DEFB, DB ====
:This pseudo-op should be followed by a comma-separatedlist of expressions, which will be assembled into sequential  byte locations. Each expression must have a value between-128 and 255 inclusive. DB can be used as a synonym forDEFB. Example:
DEFB 10, 20, 'a', 0FFH
==== DEFF ====
:This pseudo-op assembles floating point constants into32 bit HI-TECH C format floating point constants. For exam-pleexample:
pi: DEFF 3.14159
==== DEFW ====
:This operates in a similar fashion to DEFB, except thatit assembles expressions into words, without the value restriction. Example:
DEFW -1, 3664H, 'A', 3777Q
==== DEFS ====
:Defs reserves memory locations without initializingthem. Its operand is an absolute expression, representingthe number of bytes to be reserved. This expression isadded to the current location counter. Note however thatlocations reserved by DEFS may be initialized to zero by thelinker if the reserved locations are in the middle of theprogram. Example:
DEFS 20h ;reserve 32 bytes of memory
==== EQU ====
:Equ sets the value of a symbol on the left of EQU tothe expression on the right. It is illegal to set the valueof a symbol which is already defined. Example:
SIZE equ 46
==== DEFL ====
:This is identical to EQU except that it may redefineexisting symbols. Example:
==== DEFM ====
:Defm should be followed by a string of characters,enclosed in single quotes. The ASCII values of these char-acters characters are assembled into successive memory locations.Example:
DEFM 'A string of funny *@$ characters'
==== END ====
:The end of an assembly is signified by the end of thesource file, or the END pseudo-op. The END pseudo-op mayoptionally be followed by an expression which will definethe start address of the program. This is not actually use-ful useful for CP/M. Only one start address may be defined per pro-gramprogram, and the linker will complain if there are more. Exam-pleExample:
END somelabel
==== COND, IF, ELSE, ENDC ====
:Conditional assembly is introduced by the COND pseudo-op. The operand to COND must be an absolute expression. Ifits value is false (zero) the code following the COND up tothe corresponding ENDC pseudo-op will not be assembled.COND/ENDC pairs may be nested. IF may be used as a synonymfor COND. The ELSE pseudo operation may be included withina COND/ENDC block, for example:
IF CPM
==== ELSE ====
:See COND.
==== ENDC ====
:See COND. 
==== ENDM ====
:See MACRO.
==== PSECT ====
:This pseudo-op allows specification of relocatable pro-gram program sections. Its arguments are a psect name, optionallyfollowed by a list of psect flags. The psect name is a sym-bol symbol constructed according to the same rules as for labels,however a psect may have the same name as a label withoutconflict. Psect names are recognized only after a PSECTpseudo-op. The psect flags are as follows:
:;ABS::Psect is absolute
:;GLOBAL::Psect is global
:;LOCAL::Psect is not global
:;OVRLD::Psect is to be overlapped by linker
:;PURE::Psect is to be read-only
:If a psect is global, the linker will merge it with any other global psects of the same name from other modules. Local psects will be treated as distinct from any other psect from another module. Psects are global by default.
:By default the linker concatenates code within a psect from various modules. If a psect is globalspecified as OVRLD, the linker will merge it with anyother global overlap each module's psects contribution of to the same name from other modulesthat psect.Local psects will be treated as This distinct is from particularly any useful otherpsect from another modulewhen linking modules which initialize e.g. Psects are global by defaultinterrupt vectors.
By default :The PURE flag instructs the linker concatenates code within a that the psect is to be psectfrom made various modulesread-only at run time. If a psect is specified as OVRLD, The usefulness of this flag depends on the ability of thelinker will overlap each module's contribution to thatpsect. This is particularly useful when linking moduleswhich initialize e.genforce the requirement. interrupt vectorsCP/M fails miserably in this regard.
The PURE flag instructs the linker that the psect is tobe made read-only at run time. The usefulness of this flagdepends on the ability of the linker to enforce the requirement. CP/M fails miserably in this regard. :The ABS flag makes a psect absolute. The psect will beloaded at zero. This is useful for statically initializinginterrupt vectors and jump tables. Examples:
==== GLOBAL ====
:Global should be followed by one more symbols (commaseparated) which will be treated by the assembler as globalsymbols, either internal or external depending on whetherthey are defined within the current module or not. Example:
==== ORG ====
:An ORG pseudo-op sets the current psect to the default(absolute) psect, and the location counter to its operand,which must be an absolute expression. Example:
ORG 100H
==== MACRO ====
:This pseudo-op defines a macro. It should be eitherpreceded or followed by the macro name, then optionally fol-lowed followed by a comma-separated list of formal parameters. Thelines of code following the MACRO pseudo-op up to the nextENDM pseudo-op will be stored as the body of the macro. Themacro name may subsequently be used in the opcode part of anassembler statement, followed by actual parameters. The textof the body of the macro will be substituted at that point,with any use of the formal parameters substituted with thecorresponding actual parameter. For example:
print MACRO string
psect data
999: db string,'$'
psect text ld de,999b ld c,9 call 5 ENDM
When used, this macro will expand to the 3 instructions
in the body of the macro, with the actual parameters substituted for func and arg. Thusprint 'hello world' expands to
print 'hello world'  expands to  psect data
999: db 'hello world','$'
psect text ld de,999b ld c,9 call 5
through as a single argument. This would expand to the following code:
psect data
999: db 'hello world',13,10,'$'
psect text ld de,999b ld c,9 call 5
ZAS supports two forms of macro declaration for compatibility with older versions of ZAS and other Z80 assemblers. The macro name may be declared either in the labelfield before the MACRO pseudo-op, or in the operand fieldafter the MACRO pseudo-op. Thus these two MACRO declarations are equivalent:
bdos MACRO func,arg
for each expansion of a macro. Any symbols listed after the
LOCAL directive will have a unique assembler-generated symbol substituted for them when the macro is expanded. For
 
 
example:
copy MACRO source,dest,count
LOCAL nocopy push af push bc ld bc,source ld a,b or c jr z,nocopy push de push hl ld de,dest ld hl,source ldir pop hl pop de
nocopy: pop bc
pop af ENDM
(recptr),buf,(recsize) will expand to:
push af push bc ld bc,(recsize) ld a,b or c jr z,??0001 push de push hl ld de,buf ld hl,(recptr) ldir pop hl pop de
??0001: pop bc
pop af
if invoked a second time, the label nocopy would expand to
The REPT pseudo-op defines a temporary macro which is
then expanded a number of times, as determined by its argu-mentargument. For example:
REPT 3
string. For example:
IRP string,<'hello world',13,10>,'arg2' LOCAL str psect data
str: db string,'$'
psect text ld c,9 ld de,str call 5 ENDM
would expand to
psect data
??0001: db 'hello world',13,10,'$'
psect text ld c,9 ld de,??0001 call 5 psect data
??0002: db 'arg2','$'
psect text ld c,9 ld de,??0002 call 5
{|
|+!Code|| !! Equivalent|| !! Meaning |
|-
|alt || m || Arithmetic less than |
|-
|llt || c || Logical less than |
|-
|age || p || Arithmetic greater or equal|
|-
|lge || nc || Logical greater or equal |
|-
|di || || Use after ld a,i for test-|
|-
|ei || || ing state of interrupt|
|-
| || || enable flag - enabled or|
|-
| || || disabled respectively.
|}