OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [zmac/] [zmac.html] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gdevic
<H3>Overview of zmac</H3>
2
zmac is a Z-80 macro cross-assembler. It has all the features you'd
3
expect. It assembles the specified input file (with a '.z' extension
4
if there is no pre-existing extension and the file as given doesn't
5
exist) and produces program output in many <A HREF="#format">different formats</A>.
6
It also produces a nicely-formatted
7
listing of the machine code and cycle counts alongside the source
8
in a ".lst" file.
9
<P>
10
To reduce clutter and command line options, all zmac output is put
11
into an (auto-created) <TT>zout</TT> subdirectory.  For <TT>file.z</TT> the listing
12
will be in <TT>zout/file.lst</TT>, the TRS-80 executable format in <TT>zout/file.cmd</TT>
13
and so on.
14
<P>
15
<A HREF="#undoc">Undocumented</A> Z-80 instructions are supported as well as 8080 code.
16
<P>
17
zmac strives to be a powerful assembler with expressions familiar to C
18
programmers while providing good backward compatibility with original
19
assemblers such as Edtasm, MRAS and Macro-80.
20
<HR>
21
<H3>Usage</H3>
22
zmac
23
[ --help ]
24
[ --version ]
25
[ --dep ]
26
[ --mras ]
27
[ --rel ]
28
[ --doc ]
29
[ --zmac ]
30
[ -8bcefghijJlLmnopstz ]
31
[ filename[.z] ]
32
<P>
33
<H3>Options</H3>
34
<P>
35
<TABLE>
36
<TR><TD VALIGN="TOP"><PRE>--help </PRE></TD><TD>Display a list of options and a terse description of what the options do. </TD></TR>
37
<TR><TD VALIGN="TOP"><PRE>--version </PRE></TD><TD>Print zmac version name. </TD></TR>
38
<TR><TD VALIGN="TOP"><PRE>--mras </PRE></TD><TD>MRAS compatibility mode.  Any <TT>?</TT> in a label will be expanded to the current module identifier as set by <TT>*mod</TT>. </TD></TR>
39
<TR><TD VALIGN="TOP"><PRE>--rel </PRE></TD><TD>Output ".rel" (relocatable object file) format only. </TD></TR>
40
<TR><TD VALIGN="TOP"><PRE>--zmac </PRE></TD><TD>zmac compatibility mode.  <TT>defl</TT> labels are undefined after each pass. Quotes and double quotes are stripped from macro arguments before expansion. <TT>$</TT> is ignored in identifiers allowing <TT>foo$bar</TT> to construct identifiers in macro expansions.  Use <TT>`</TT> (backquote) instead in normal mode.  Labels starting with <TT>"."</TT> are temporary and are reset whenever a non-temporary label is defined (thus they may be reused).  Labels starting with <TT>"_"</TT> are local to their file thus avoid multiple definition when brought in with <TT>include</TT>. </TD></TR>
41
<TR><TD VALIGN="TOP"><PRE>--dep </PRE></TD><TD>Print all files read by <TT>include</TT> and <TT>incbin</TT>. </TD></TR>
42
<TR><TD VALIGN="TOP"><PRE>--doc </PRE></TD><TD>Print this documentation in HTML format to standard output. </TD></TR>
43
<TR><TD VALIGN="TOP"><PRE>-8 </PRE></TD><TD>Accept 8080 mnemonics preferentially.  Equivalent to <TT>.8080</TT> pseudo-op. </TD></TR>
44
<TR><TD VALIGN="TOP"><PRE>-b </PRE></TD><TD>Don't generate any machine code output at all. </TD></TR>
45
<TR><TD VALIGN="TOP"><PRE>-c </PRE></TD><TD>Make the listing continuous, i.e., don't generate any page breaks or page headers. Can make things less confusing if you're going to consult the listing online rather than printing it.  This is the default. </TD></TR>
46
<TR><TD VALIGN="TOP"><PRE>-e </PRE></TD><TD>Omit the "error report" section in the listing. </TD></TR>
47
<TR><TD VALIGN="TOP"><PRE>-f </PRE></TD><TD>List instructions not assembled due to "<TT>if</TT>" expressions being false. (Normally these are not shown in the listing.) </TD></TR>
48
<TR><TD VALIGN="TOP"><PRE>-g </PRE></TD><TD>List only the first line of equivalent hex for a source line. </TD></TR>
49
<TR><TD VALIGN="TOP"><PRE>-h </PRE></TD><TD>Display a list of options and a terse description of what the options do. (same as --help) </TD></TR>
50
<TR><TD VALIGN="TOP"><PRE>-i </PRE></TD><TD>Don't list files included with <TT>include</TT> or <TT>read</TT>. </TD></TR>
51
<TR><TD VALIGN="TOP"><PRE>-I dir </PRE></TD><TD>Add <TT>dir</TT> to the end of the include file search path. </TD></TR>
52
<TR><TD VALIGN="TOP"><PRE>-j </PRE></TD><TD>Promote relative jumps and <TT>DJNZ</TT> to absolute equivalents as needed. </TD></TR>
53
<TR><TD VALIGN="TOP"><PRE>-J </PRE></TD><TD>Error if an absolute jump could be replaced with a relative jump. </TD></TR>
54
<TR><TD VALIGN="TOP"><PRE>-l </PRE></TD><TD>Don't generate a listing at all. </TD></TR>
55
<TR><TD VALIGN="TOP"><PRE>-L </PRE></TD><TD>Generate listing no matter what. Overrides any conflicting options. </TD></TR>
56
<TR><TD VALIGN="TOP"><PRE>-m </PRE></TD><TD>List macro expansions. </TD></TR>
57
<TR><TD VALIGN="TOP"><PRE>-n </PRE></TD><TD>Omit line numbers from listing. </TD></TR>
58
<TR><TD VALIGN="TOP"><PRE>-o </PRE></TD><TD>List to standard output. </TD></TR>
59
<TR><TD VALIGN="TOP"><PRE>-p </PRE></TD><TD>Use a few linefeeds for page break in listing rather than ^L. </TD></TR>
60
<TR><TD VALIGN="TOP"><PRE>-P </PRE></TD><TD>Output listing for a printer with headers, multiple symbols per column, etc. </TD></TR>
61
<TR><TD VALIGN="TOP"><PRE>-s </PRE></TD><TD>Omit the symbol table from the listing. </TD></TR>
62
<TR><TD VALIGN="TOP"><PRE>-t </PRE></TD><TD>Only output number of errors instead list of each one. </TD></TR>
63
<TR><TD VALIGN="TOP"><PRE>-z </PRE></TD><TD>Accept Z-80 mnemonics preferentially.  Equivalent to <TT>.z80</TT> pseudo-op. </TD></TR>
64
</TABLE>
65
<HR>
66
<H3>Input Format</H3>
67
<P>
68
zmac uses the standard Zilog mnemonics, and the pseudo-ops are also
69
largely as you'd expect.
70
<P>
71
A "<TT>.</TT>" may optionally preceeed any psuedo-op.
72
For example, "<TT>.org</TT>" and "<TT>org</TT>" are treated as equivalent.
73
<P>
74
Input can be upper or lowercase.
75
<P>
76
Comments start with <TT>;</TT> and carry on to the end of the line.
77
<P>
78
Number constants can take a trailing h or a leading $ or 0x for hex,
79
a trailing b for binary, a trailing o or q for octal, or a trailing
80
d for decimal.
81
<P>
82
<TT>'LH'</TT> (any length 2 string) can be treated as a number whose value
83
is <TT>'H'</TT> * 256 + <TT>'L'</TT>.
84
<P>
85
Labels are declared with <TT>label:</TT> or just <TT>label</TT> - indentation is unimportant.
86
Labels can be up to 40 chars long.  They can start with and contain
87
letters, digits, <TT>$</TT>, <TT>.</TT>, <TT>?</TT>, <TT>@</TT> and _.  Ambiguous identifiers like
88
<TT>$FCB</TT> will be treated as hex constants unless defined as a label.  Labels
89
declared with two colons (<TT>label::</TT>) make the label public.
90
<P>
91
Here is how other things work.  Numbers are used as examples, but a full
92
<A HREF="#expr">expression</A> can be used in their place.
93
<P>
94
<H4>Data</H4>
95
<P>
96
<TT>defb 42</TT>
97
<BLOCKQUOTE>A byte.  <TT>ascii</TT>, <TT>byte</TT>, <TT>db</TT>, <TT>defm</TT> and <TT>text</TT> are synonyms.
98
</BLOCKQUOTE>
99
<P>
100
<TT>defb 'foobar'</TT>
101
<BLOCKQUOTE>An ASCII character string (not NUL-terminated).
102
Double quotes can also be used.
103
</BLOCKQUOTE>
104
<P>
105
<TT>defb 'Who needs anything more than CP/M?',13,10,'$'</TT>
106
<BLOCKQUOTE>Strings and bytes can mix together.
107
</BLOCKQUOTE>
108
<P>
109
<TT>defw 2112</TT>
110
<P>
111
<TT>defw $123,0x456</TT>
112
<BLOCKQUOTE>A word (16 bits).  <TT>word</TT> and <TT>dw</TT> are synonyms.
113
</BLOCKQUOTE>
114
<P>
115
<TT>defd $12345678</TT>
116
<BLOCKQUOTE>A double word (32 bits). <TT>dword</TT> is a synonym.
117
</BLOCKQUOTE>
118
<P>
119
<TT>defs 500</TT>
120
<BLOCKQUOTE>Skip output ahead 500 bytes.  This will insert 500 zeros in the ".ams"
121
and ".cim" output files or if inside a ".phase" section.
122
<TT>block</TT>, <TT>ds</TT> and <TT>rmem</TT> are synonyms.
123
</BLOCKQUOTE>
124
<P>
125
<TT>dc 'string'</TT>
126
<BLOCKQUOTE>Like <TT>ascii</TT> but accepts only a single string and the high bit of the
127
last character will be set.
128
</BLOCKQUOTE>
129
<P>
130
<TT>dc count,value</TT>
131
<BLOCKQUOTE>Repeat the byte <TT>value</TT> a total of <TT>count</TT> times.  Similar to <TT>defs</TT>
132
except that memory is always filled with <TT>value</TT>.
133
</BLOCKQUOTE>
134
<P>
135
<TT>incbin file</TT>
136
<BLOCKQUOTE>Inserts the raw contents of the file into the assembly.  Simpler for
137
large amounts of data.
138
</BLOCKQUOTE>
139
<P>
140
<H4>Symbols</H4>
141
<P>
142
<TT>label equ 100</TT>
143
<BLOCKQUOTE>Define a symbol to have a fixed value.  The symbol can be used before it
144
is defined.  A symbol defined with <TT>equ</TT> or as a label can be defined only
145
once, except that a symbol defined with <TT>equ</TT> may be redefined to the
146
same value.
147
</BLOCKQUOTE>
148
<P>
149
<TT>label defl 200</TT>
150
<BLOCKQUOTE>Define a symbol to have a changeable value.  The symbol cannot be used
151
before it is defined, and it can be redefined to a different value later
152
with another <TT>defl</TT>. <TT>aset</TT> is a synonym.
153
</BLOCKQUOTE>
154
<P>
155
<TT>min</TT>
156
<P>
157
<TT>max</TT>
158
<BLOCKQUOTE>Same as <TT>defl</TT> except that the symbol is defined as the
159
smaller or bigger of two comma-separated expressions.
160
</BLOCKQUOTE>
161
<P>
162
<TT>*mod</TT>
163
<BLOCKQUOTE>Increment the internal module name string.  The first time this results
164
in "a".  Then "b", "c", ... "z".  Then "aa", "ab", "ac", etc. all the way
165
up to "zzzz".  The module name string is used in <TT>--mras</TT> mode where "?" in
166
label names is replaced with the current module name.
167
</BLOCKQUOTE>
168
<P>
169
<TT>extern lab1,lab2,...</TT>
170
<BLOCKQUOTE>The listed labels are defined in an external module for later linking.
171
No effect unless zmac is producing ".rel" output.
172
<TT>ext</TT> and <TT>extrn</TT> are synonyms.
173
</BLOCKQUOTE>
174
<P>
175
<TT>public lab1,lab2,...</TT>
176
<BLOCKQUOTE>The given labels will be visible to external modules when linking.
177
No effect unless zmac is producing ".rel" output.
178
<TT>global</TT> and <TT>entry</TT> are synonyms.
179
</BLOCKQUOTE>
180
<P>
181
<H4>Location Control</H4>
182
<P>
183
<TT>org 9000h</TT>
184
<BLOCKQUOTE>Set the address to assemble to 0x9000.
185
</BLOCKQUOTE>
186
<P>
187
<TT>phase address</TT>
188
<BLOCKQUOTE>Continue to produce code and data for loading at the current address
189
but assemble instructions and define labels as if they originated at
190
the given address.  Useful when producing code that will be copied to
191
a different location before being executed (e.g., an overlay).
192
</BLOCKQUOTE>
193
<P>
194
<TT>dephase</TT>
195
<BLOCKQUOTE>End <TT>phase</TT> mode assembly.
196
</BLOCKQUOTE>
197
<P>
198
<TT>aseg</TT>
199
<TT>cseg</TT>
200
<TT>dseg</TT>
201
<BLOCKQUOTE>Switch to the absolute, code and data segments respectively.
202
No effect unless zmac is producing ".rel" output.
203
</BLOCKQUOTE>
204
<P>
205
<H4>Input Control</H4>
206
<P>
207
<TT>end</TT>
208
<BLOCKQUOTE>Ends the input.  Any lines after an <TT>end</TT> are silently ignored.
209
If an arg is given, it declares the entry address for the program.
210
This has no effect in ".cim" output. In ".hex" output
211
it generates an S-record directing 0 bytes of data to be loaded
212
at the given address.
213
</BLOCKQUOTE>
214
<P>
215
<TT>if</TT> ... [ <TT>else</TT> ... ] <TT>endif</TT>
216
<BLOCKQUOTE>For conditional assembly. If you do <TT>if foo</TT> and <TT>foo</TT> evaluates to
217
zero, all the lines up until the next corresponding <TT>else</TT> or <TT>endif</TT>
218
are completely ignored.  Conversely, if <TT>foo</TT> evaluates to non-zero, any
219
lines from a corresponding <TT>else</TT> to the <TT>endif</TT> are ignored.  Ifs can
220
be nested.  <TT>cond</TT>/<TT>endc</TT> are synonyms for <TT>if</TT>/<TT>endif</TT>.
221
</BLOCKQUOTE>
222
<P>
223
<TT>include file</TT>
224
<BLOCKQUOTE>Include a file. Like C's (well, cpp's) #include and follows the same
225
include path search rules, but the filename arg
226
lacks the angle brackets or quotes (though single or double quotes may be used).
227
<TT>read</TT> is a synonym.
228
</BLOCKQUOTE>
229
<P>
230
<TT>comment X</TT>
231
<BLOCKQUOTE>Suspend assembly until the next occurence of character <TT>X</TT> on a line.
232
The rest of the line will be ignored.  A multi-line comment.
233
</BLOCKQUOTE>
234
<P>
235
<TT>assert expr</TT>
236
<BLOCKQUOTE>Stop assembly if <TT>expr</TT> is non-zero.
237
</BLOCKQUOTE>
238
<P>
239
<H4>Cycle Counting</H4>
240
<P>
241
<TT>sett expr</TT>
242
<BLOCKQUOTE>Set the current T-state count to <TT>expr</TT>. <TT>tstate</TT> is a synonym.
243
</BLOCKQUOTE>
244
<P>
245
<TT>setocf expr</TT>
246
<BLOCKQUOTE>Set the current opcode fetch count to <TT>expr</TT>.
247
</BLOCKQUOTE>
248
<P>
249
<H4>Code Generation</H4>
250
<P>
251
<TT>8080</TT>
252
<BLOCKQUOTE>Make cycle counting operators return 8080 cycle counts and
253
interpret any ambiguous assembly statements as Intel 8080 mnemonics.
254
<TT>CP</TT> will be interpreted as "call on positive" and <TT>JP</TT> as "jump on positive".
255
</BLOCKQUOTE>
256
<P>
257
<TT>z80</TT>
258
<BLOCKQUOTE>Make cycle counting operators return Z-80 cycle counts and
259
interpret any ambiguous assembly statements as Zilog Z-80 mnemonics.
260
<TT>CP</TT> will be interpreted as "compare accumulator" and <TT>JP</TT> as "jump unconditionally".
261
</BLOCKQUOTE>
262
<P>
263
<TT>jperror enable</TT>
264
<BLOCKQUOTE>If <TT>enable</TT> is non-zero, turn on errors when <TT>JR</TT> instructions could be used
265
instead of <TT>JP</TT>, off otherwise.  Used to check existing code for situations
266
where shorter code could be generated.  Same as <TT>-J</TT> option.
267
No effect if in 8080 mode.
268
</BLOCKQUOTE>
269
<P>
270
<TT>jrpromote enable</TT>
271
<BLOCKQUOTE>If <TT>enable</TT> is non-zero, <TT>JR</TT> and <TT>DJNZ</TT> instructions will be promoted to
272
equivalent <TT>JP</TT> and <TT>DEC&nbsp;B</TT>, <TT>JP&nbsp;NZ</TT> instructions if the relative branch
273
offset is out of range.  If <TT>enable</TT> is zero, promotion is disabled.
274
Same as the <TT>-j</TT> option.
275
No effect if in 8080 mode.
276
</BLOCKQUOTE>
277
<P>
278
<H4>Undocumented <A NAME="undoc">Instructions</A></H4>
279
<P>
280
Most Z-80 chips support a number of undocumented instructions that were part of
281
the original design but not made an offical part of the Zilog specification.
282
These instructions may not be supported by all Z-80 chips, especially
283
licensed variants, but are fairly widely available nonetheless.
284
<P>
285
<TT>sl1 r</TT>
286
<BLOCKQUOTE>Same as <TT>sla r</TT> but shifts a 1 into the lower bit of <TT>r</TT> rather than a 0.
287
</BLOCKQUOTE>
288
<P>
289
<TT>in (c)</TT>
290
<BLOCKQUOTE>Inputs a byte from port <TT>c</TT> but does not store the value.  Flags are still
291
set as with the normal <TT>in r,(c)</TT> instruction.
292
</BLOCKQUOTE>
293
<P>
294
<TT>out (c),0</TT>
295
<BLOCKQUOTE>Outputs a zero to port <TT>c</TT>.
296
</BLOCKQUOTE>
297
<P>
298
<TT>bit/set/res n,(ix+d),r</TT>
299
<P>
300
<TT>rlc/rrc/rl/rr/sla/sl1/sra/srl (iy+d),r</TT>
301
<BLOCKQUOTE>Same as the corresponding operation on just <TT>(ix+d)</TT> or <TT>(iy+d)</TT> but with
302
the result being stored both into <TT>(ix+d)</TT> and register <TT>r</TT>.  Except for <TT>bit</TT>
303
which has no effect on <TT>r</TT>. zmac supports the syntax to allow those
304
instruction patterns to be generated.
305
</BLOCKQUOTE>
306
<P>
307
The upper and lower bytes of the <TT>ix</TT> and <TT>iy</TT> can be used in a number of
308
instructions much in the same way as <TT>d</TT> and <TT>e</TT> correspond to the upper and
309
lower bytes of <TT>de</TT>.  zmac names these <TT>ixh</TT>, <TT>ixl</TT>, <TT>iyh</TT> and <TT>iyl</TT> and
310
are referred to generically as <TT>ixylh</TT> here.
311
<P>
312
<TT>inc/dec/add/adc/sub/sbc/and/xor/or/cp ixylh</TT>
313
<BLOCKQUOTE>Arithmetic or logical operation on <TT>ix</TT> or <TT>iy</TT> high or low byte.
314
</BLOCKQUOTE>
315
<P>
316
<TT>ld a/b/c/d/e,ixylh</TT>
317
<BLOCKQUOTE>Load register with <TT>ix</TT> or <TT>iy</TT> high or low byte.
318
</BLOCKQUOTE>
319
<P>
320
<TT>ld ixylh,a/b/c/d/e</TT>
321
<BLOCKQUOTE>Load <TT>ix</TT> or <TT>iy</TT> high or low byte with register.
322
</BLOCKQUOTE>
323
<P>
324
<TT>pfix</TT>
325
<P>
326
<TT>pfiy</TT>
327
<BLOCKQUOTE>Output $DD and $FD prefix bytes.  The Z-80 allows multiple prefix bytes
328
for IX and IY instructions.  This allows you to specify them abstractly.
329
There is little purpose except for delaying an interrupt or confusing
330
disassemblers.
331
</BLOCKQUOTE>
332
<P>
333
<H4>Miscellaneous</H4>
334
<P>
335
<TT>name str</TT>
336
<BLOCKQUOTE>Set the name of the output model to <TT>str</TT>.  For compatibility reasons
337
<TT>str</TT> may be parenthesized (e.g., "<TT>name ('foo')</TT>").  Not all output
338
formats support an internal name and many have severe length limits.
339
</BLOCKQUOTE>
340
<P>
341
<TT>rsym</TT> and <TT>wsym</TT>
342
<BLOCKQUOTE>Read/write a symbol file. These simply load/save the currently defined
343
symbols from/to the file specified (in a non-portable format). <TT>rsym</TT>
344
takes place at the point it is encountered in the file (on the first
345
pass); <TT>wsym</TT> is delayed until assembly has finished.
346
</BLOCKQUOTE>
347
<P>
348
<H4>Listing Pseudo-ops</H4>
349
<P>
350
There are several pseudo-ops for controlling the listing. None of
351
these ops appear in the listing themselves:
352
<P>
353
<TT>eject</TT>
354
<BLOCKQUOTE>Start a new listing page.
355
</BLOCKQUOTE>
356
<P>
357
<TT>nolist</TT>
358
<BLOCKQUOTE>Do nothing. This can be used to have a comment in the source but not
359
the listing, I suppose.
360
</BLOCKQUOTE>
361
<P>
362
<TT>elist</TT>, <TT>flist</TT>, <TT>glist</TT>, <TT>mlist</TT>
363
<BLOCKQUOTE>These have the same effect as the similarly-named command-line
364
options, though possibly with the sense reversed depending on the
365
default. Use an arg &gt;0 (or no arg) to enable, and an arg &lt;0 to
366
disable.
367
</BLOCKQUOTE>
368
<P>
369
<TT>list</TT>
370
<BLOCKQUOTE>Sets whether to list or not. You can use this to avoid listing certain
371
parts of the source. Takes same optional arg as 'elist', etc..
372
</BLOCKQUOTE>
373
<P>
374
<TT>title</TT>
375
<BLOCKQUOTE>Set title (used in listing and symbol file).
376
</BLOCKQUOTE>
377
<P>
378
<TT>space</TT>
379
<BLOCKQUOTE>Output arg blank lines in the listing, or one line if no arg is given.
380
</BLOCKQUOTE>
381
<P>
382
<HR>
383
<P>
384
<H3><A NAME="expr">Expressions</A></H3>
385
<P>
386
Expressions feature a full set of C operators with the same precedence
387
rules and some common assembler extensions and names.
388
Here is the complete list of operators, highest-precedence first.
389
Operators separated only by a space are synonyms; for example, <TT>~</TT>
390
is the same as <TT>not</TT>.
391
<P>
392
<TT>!</TT> (logical), <TT>~ not</TT> (bitwise), <TT>+</TT> (unary), <TT>-</TT> (unary), <TT>low</TT>, <TT>high</TT>, <TT>t</TT>, <TT>tilo</TT>, <TT>tihi</TT>, <TT>ocf</TT>
393
<P>
394
<TT>*</TT>, <TT>/</TT>, <TT>% mod</TT>
395
<P>
396
<TT>+</TT>, <TT>-</TT>
397
<P>
398
<TT>&lt;&lt; shl</TT>, <TT>&gt;&gt; shr</TT>
399
<P>
400
<TT>&lt; lt</TT>, <TT>&gt; gt</TT>, <TT>&lt;= le</TT>, <TT>&gt;= ge</TT>
401
<P>
402
<TT>== = eq</TT>, <TT>!= &lt;&gt; ne</TT>
403
<P>
404
<TT>&amp; and</TT> (bitwise)
405
<P>
406
<TT>^ xor</TT> (bitwise)
407
<P>
408
<TT>| or</TT> (bitwise)
409
<P>
410
<TT>&amp;&amp;</TT>
411
<P>
412
<TT>||</TT>
413
<P>
414
<TT>? :</TT>  (ternary choice operator)
415
<P>
416
You can use normal parentheses or square brackets to override
417
the precedence rules. Square brackets can be used where parentheses would
418
conflict with Z-80 mnemonic syntax, but this is not necessary in any
419
practical case.
420
<P>
421
The <TT>?</TT> may need spaces around it to distinguish it from a label that
422
has <TT>?</TT> in it.
423
<P>
424
The unary operators not familiar to C programmers:
425
<P>
426
<TABLE>
427
<TR><TD VALIGN="TOP"><PRE>low expr </PRE></TD><TD>Returns low 8 bits of <TT>expr</TT> </TD></TR>
428
<TR><TD VALIGN="TOP"><PRE>high expr </PRE></TD><TD>Returns high 8 bits of <TT>expr</TT> </TD></TR>
429
<TR><TD VALIGN="TOP"><PRE>t expr </PRE></TD><TD>Current count of T-states up to memory location <TT>expr</TT> </TD></TR>
430
<TR><TD VALIGN="TOP"><PRE>tilo expr </PRE></TD><TD>Low count of T-states used by instruction at memory location <TT>expr</TT> </TD></TR>
431
<TR><TD VALIGN="TOP"><PRE>tihi expr </PRE></TD><TD>High count of T-states used by instruction at memory location <TT>expr</TT> </TD></TR>
432
<TR><TD VALIGN="TOP"><PRE>ocf expr </PRE></TD><TD>Current count of opcode fetches up to memory location <TT>expr</TT> </TD></TR>
433
</TABLE>
434
<HR>
435
<H3>Macros</H3>
436
The following defines a macro named m with zero or more formal parameters
437
<TT>p1</TT>, <TT>p2</TT>, ..., <TT>pn</TT>, zero or more local symbols <TT>?s1</TT>, <TT>?s2</TT>, ..., <TT>?sm</TT>,
438
and body <TT>b1</TT>, <TT>b2</TT>, ...:
439
<P>
440
<TABLE>
441
<TR><TD VALIGN="TOP"><PRE><TT>m macro p1, p2, ..., pn, ?s1, ?s2, ..., ?sm</TT> </PRE></TD><TD> </TD></TR>
442
<TR><TD VALIGN="TOP"><PRE><TT>&nbsp;&nbsp;&nbsp;b1</TT> </PRE></TD><TD> </TD></TR>
443
<TR><TD VALIGN="TOP"><PRE><TT>&nbsp;&nbsp;&nbsp;b2</TT> </PRE></TD><TD> </TD></TR>
444
<TR><TD VALIGN="TOP"><PRE><TT>&nbsp;&nbsp;&nbsp;...</TT> </PRE></TD><TD> </TD></TR>
445
<TR><TD VALIGN="TOP"><PRE><TT>&nbsp;&nbsp;&nbsp;endm</TT> </TD></TR>
446
</TABLE>
447
<P>
448
The macro is called by writing:
449
<BLOCKQUOTE><TT>m v1, v2, ..., vn</TT>
450
</BLOCKQUOTE>
451
<P>
452
A macro call expands to the text of the macro's body, with each
453
occurrence of a formal parameter <TT>pk</TT> replaced by the corresponding
454
value <TT>vk</TT>, and with each local symbol <TT>?sk</TT> replaced by a new, unique
455
symbol invented for this call.  Invented symbols begin with <TT>?</TT>,
456
so you should avoid using such symbols elsewhere in your program.
457
<P>
458
zmac currently does not check that you have provided the right number
459
of parameters when calling a macro.  If you provide too few, unmatched
460
formals are replaced with the empty string.  If you provide too
461
many, the additional values begin to replace local symbols as if
462
they were ordinary parameters.  (This could be considered a feature.)
463
After the local symbols are all replaced, additional parameters
464
are silently ignored.
465
<P>
466
For compatibility with Macro-80, the first line of a macro definition can
467
list other labels that will be treated locally:
468
<P>
469
<BLOCKQUOTE><TT>&nbsp;&nbsp;&nbsp;local lab1,lab2,...</TT>
470
</BLOCKQUOTE>
471
<P>
472
Each time the macro is expanded the local labels are replaced with unique
473
names thus avoiding multiple definition problems.
474
<P>
475
For compatability with MRAS, macro arguments may be preceeded by <TT>&nbsp;</TT>
476
in their definition and use.
477
<P>
478
Any <TT>`</TT> (backquote) in a macro is ignored thus allowing a macro to
479
construct identifiers.  For example:
480
<P>
481
<TABLE>
482
<TR><TD VALIGN="TOP"><PRE><TT>move macro dir</TT> </PRE></TD><TD> </TD></TR>
483
<TR><TD VALIGN="TOP"><PRE><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ld`dir`r</TT> </PRE></TD><TD> </TD></TR>
484
<TR><TD VALIGN="TOP"><PRE><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endm</TT> </TD></TR>
485
</TABLE>
486
<P>
487
Invoking <TT>move i</TT> will construct a <TT>ldir</TT> block move instruction.
488
<HR>
489
<H3>Compatibility</H3>
490
<P>
491
zmac is broadly compatible with many original Z-80 and 8080 assemblers
492
because it accepts many different names for common operations and has
493
liberal identifier and numeric formats.  It also accepts most simple
494
usage of macros.
495
<P>
496
When assembling old code keep these portability problems in mind.
497
<P>
498
Expression order of evaluation may be different.  zmac uses C semantics
499
more order of evaluation but assemblers often used simple left to right
500
ordering.  zmac will evaluate <TT>2+2*3</TT> as <TT>8</TT> where other assemblers will
501
yield <TT>12</TT>.
502
<P>
503
zmac has no support operating on strings in macros.  Assemblers like Macro-80
504
could perform conditional tests on strings.
505
<P>
506
Advanced macros are unlikely to work.  zmac hasn't advanced to the state where
507
all the possible ways of substituting parameters are supported.  Nor does it
508
have simple repetition, a way to exit a macro expansion early and so on.
509
<P>
510
Consult the original assembler manual.  zmac error messages won't help you
511
figure out what an unknown assembler command is supposed to do.
512
<P>
513
Compare against original output.  The very safest thing to do when porting
514
assembly code is to compare the binary output of zmac against that produced
515
by the original assembler.  This way you can ensure everything has been
516
interpreted correctly.  Only once that has been achieved should you modify
517
the code.
518
<HR>
519
<H3>Errors and Warnings</H3>
520
<P>
521
Any errors or warnings encountered during assembly are reported to standard
522
error and in the listing file.  The errors output immediately give the source
523
file and line number containing the error.  In listings the error letter
524
and message appear just after the line containing the error.
525
<P>
526
<TABLE>
527
<TR><TD VALIGN="TOP"><PRE>B </PRE></TD><TD>Balance error </TD></TR>
528
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>A string is missing an closing quote or an <TT>if</TT> is missing an <TT>endif</TT> </TD></TR>
529
<TR><TD VALIGN="TOP"><PRE>E </PRE></TD><TD>Expression error </TD></TR>
530
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An expression did not parse or attempts a divide or modulus by 0. </TD></TR>
531
<TR><TD VALIGN="TOP"><PRE>F </PRE></TD><TD>Syntax error </TD></TR>
532
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>General problem with the syntax on a line.  Sometimes extra explanation will be printed on standard output. </TD></TR>
533
<TR><TD VALIGN="TOP"><PRE>I </PRE></TD><TD>Digit error </TD></TR>
534
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>A numeric constant has too many digits to be represented as a 32 bit number. </TD></TR>
535
<TR><TD VALIGN="TOP"><PRE>M </PRE></TD><TD>Mult. def. error </TD></TR>
536
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>A symbol has been defined more than once and those values differ. </TD></TR>
537
<TR><TD VALIGN="TOP"><PRE>P </PRE></TD><TD>Phase error </TD></TR>
538
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>On the second or subsequent assembly passes the assembly has changed significantly.  Most commonly it means an <TT>if</TT> has changed conditions but can also happen when labels or equated values do not converge to a fixed value. </TD></TR>
539
<TR><TD VALIGN="TOP"><PRE>U </PRE></TD><TD>Undeclared error </TD></TR>
540
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An undeclared symbol was used in an expression or <TT>public</TT> statement. </TD></TR>
541
<TR><TD VALIGN="TOP"><PRE>V </PRE></TD><TD>Value error </TD></TR>
542
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An invalid value was given to a statement.  Often this means using less than -128 or greater then 255 in a <TT>defb</TT> or less than -32768 or greater than 65535 in a <TT>defw</TT>.  Or similar invalid values used Z-80/8080 opcodes requiring an 8 or 16 bit value (and other restrictions like 0 to 7 for <TT>BIT</TT>). Also if a relative jump is out of range or if a negative value is given in <TT>defs</TT> or <TT>dc</TT>. </TD></TR>
543
<TR><TD VALIGN="TOP"><PRE>O </PRE></TD><TD>Phase/Dephase error </TD></TR>
544
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD><TT>phase</TT> was used within another <TT>phase</TT> or <TT>dephase</TT> without <TT>phase</TT>. Or if <TT>org</TT> is used within <TT>phase</TT>. </TD></TR>
545
<TR><TD VALIGN="TOP"><PRE>A </PRE></TD><TD>Assertion failure error </TD></TR>
546
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An assert statement evaluated to zero. </TD></TR>
547
<TR><TD VALIGN="TOP"><PRE>J </PRE></TD><TD>Use JR error </TD></TR>
548
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An absolute jump instruction was used where relative jump was in range of the destination address.  Only generated if <TT>-j</TT> or <TT>jrpromote</TT> is in effect. </TD></TR>
549
<TR><TD VALIGN="TOP"><PRE>R </PRE></TD><TD>Not relocatable error </TD></TR>
550
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An expression was used that must be generated at link time but cannot be handled by the ".rel" format.  For instance, an <TT>org</TT> to a symbol in the data segment when in the code segment.  Or a relative jump to a different segment.  The ".rel" format can evaluate expressions at link time using the <TT>high</TT>, <TT>low</TT>, <TT>not</TT>, <TT>-</TT>, <TT>+</TT>, <TT>*</TT>, <TT>/</TT> and <TT>%</TT> operators. zmac is clever enough to use <TT>high</TT> or <TT>low</TT> in place of <TT>&amp; $ff00</TT> and <TT>&amp; 255</TT>.  But it won't replace a <TT>shl</TT> with a multiply. </TD></TR>
551
<TR><TD VALIGN="TOP"><PRE>G </PRE></TD><TD>Register usage error </TD></TR>
552
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>A invalid register was given to an instruction.  For example, <TT>LD B,(DE)</TT> or <TT>ADD HL,IX</TT>. </TD></TR>
553
<TR><TD VALIGN="TOP"><PRE>Z </PRE></TD><TD>Z-80 instruction in 8080 mode error </TD></TR>
554
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>An instruction was assembled that is only valid on the Z-80 but <TT>.8080</TT> (or <TT>-8</TT>) mode is in effect.  However, use use of Z-80 mnemonics that output valid 8080 instructions is always OK. </TD></TR>
555
<TR><TD VALIGN="TOP"><PRE>H </PRE></TD><TD>$hex constant interpreted as symbol warning </TD></TR>
556
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>A symbol such as <TT>$FCB</TT> has been defined even though it could appear to be a hexadecimal constant.  zmac will treat <TT>$FCB</TT> as symbol for the entire assembly which could be rather surprising if that were not the intent. </TD></TR>
557
<TR><TD VALIGN="TOP"><PRE>N </PRE></TD><TD>Not implemented warning </TD></TR>
558
<TR><TD VALIGN="TOP"><PRE>&nbsp; </PRE></TD><TD>For statements that have been added as parse rules but have no effect. The only current example is <TT>subttl</TT> which sets the sub title of a listing in certain assemblers. </TD></TR>
559
</TABLE>
560
<P>
561
<HR>
562
<H3>Output <A NAME="format">Formats</A></H3>
563
<P>
564
Except for ".rel", zmac writes every known output when assembling.  This
565
is no burden on modern computers and saves having to come up with options
566
to select a particular output format.
567
<P>
568
".rel" is a special case since that format is intended for linking and
569
can have undefined external symbols which would be errors in the other
570
formats which do not support them.
571
<P>
572
<TABLE>
573
<TR><TD VALIGN="TOP"><PRE>.ams </PRE></TD><TD>AMSDOS executable format for Amstrad computers. </TD></TR>
574
<TR><TD VALIGN="TOP"><PRE>.bds </PRE></TD><TD>Experimental format with the potential for source-level debugging. </TD></TR>
575
<TR><TD VALIGN="TOP"><PRE>.cas </PRE></TD><TD>TRS-80 high-speed (1500 baud) cassette SYSTEM file.  The internal name of the file is the source file name shortened to 6 characters with suffixes removed. </TD></TR>
576
<TR><TD VALIGN="TOP"><PRE>.cim </PRE></TD><TD>Core In-Memory image.  A raw binary format with the first byte corresponding to the lowest generated code or data and proceeding contiguously until the highest address generated.  Any gaps are filled with zeros.  Typically used for CP/M where all executables start at address 256 or for ROM images. </TD></TR>
577
<TR><TD VALIGN="TOP"><PRE>.cmd </PRE></TD><TD>TRS-80 DOS executable file format as used by all major DOSes on the TRS-80 (TRS-DOS, LDOS, MULTIDOS, NEWDOS, etc.) </TD></TR>
578
<TR><TD VALIGN="TOP"><PRE>.hex </PRE></TD><TD>Intel hex record format. </TD></TR>
579
<TR><TD VALIGN="TOP"><PRE>.lcas </PRE></TD><TD>TRS-80 low-speed (500 baud) cassette SYSTEM file.  The internal name of the file is the source file name shortened to 6 characters with suffixes removed. </TD></TR>
580
<TR><TD VALIGN="TOP"><PRE>.rel </PRE></TD><TD>Relocatable object module format as produced by MACRO-80 and other assemblers. </TD></TR>
581
</TABLE>
582
<P>
583
<HR>
584
<H3>Miscellaneous</H3>
585
In the symbol table listing, the <TT>=</TT> prefix is given for those symbols
586
defined by <TT>equ</TT> or <TT>defl</TT>.
587
<HR>
588
<H3>Exit Status</H3>
589
<P>
590
<TABLE>
591
<TR><TD VALIGN="TOP"><PRE>0 </PRE></TD><TD>No errors. </TD></TR>
592
<TR><TD VALIGN="TOP"><PRE>1 </PRE></TD><TD>One or more errors were found during assembly, or zmac exited with a fatal error. </TD></TR>
593
</TABLE>
594
<P>
595
<HR>
596
<H3>Credits</H3>
597
Bruce Norskog original wrote zmac in 1978.
598
<P>
599
Updates and bugfixes over the years by John Providenza, Colin Kelley,
600
and more recently by Russell Marks, Mark RISON, Chris Smith,
601
Matthew Phillips and Tim Mann.
602
<P>
603
Extensive modifications for cycle counting, multiple output formats,
604
".rel" output, 8080 mode and older assembler compatibilty were written
605
by George Phillips.
606
<P>
607
This document was based on Russell Marks zmac man page which had
608
tweaks by Mark RISON and Tim Mann.  George Phillips converted it to HTML
609
and documented the new features and some older ones (e.g., <TT>phase</TT>/<TT>dephase</TT>).
610
<!--
611
  If you ran "zmac --doc" you may want to send the output
612
  to a file using "zmac --doc >zmac.html" and then open
613
  zmac.html in your web browser.
614
-->

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.