-

Changes

Jump to: navigation, search

Z80 Assembler Reference Manual

177 bytes added, 10:22, 31 July 2017
no edit summary
==== MACRO ====
:This pseudo-op defines a macro. It should be either preceded or followed by the macro name, then optionally followed by a comma-separated list of formal parameters. The lines of code following the MACRO pseudo-op up to the next ENDM pseudo-op will be stored as the body of the macro. The macro name may subsequently be used in the opcode part of an assembler statement, followed by actual parameters. The text of 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. Thus 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

Navigation menu