Chapter.5.
Macros
5-4
When
label symbols used
in
a macro body have 'global' scope, mul tiply-defined symbol errors result if the macro
is
called more than once. A label can
be
given limited scope using the LOCAL directive. This directive assigns a
unique
value
to
the symbol each time the macro
is
called and expanded. Dummy parameters also have limited
~cope.
Occasionally you may wish to duplicate a block
of
code several times, either within a macro or
in
line with
other source code. This can
be
accomplished with minimal coding effort using the REPT (repeat block),
IRP
(indefinite repeat), and IRPC (indefinite repeat character) directives. Like the MACRO directive, these directives
are terminated by
ENDM.
The EXITM directive provides an alternate exit from a macro. When encountered, it terminates the current macro
just
as
if
EN
OM
had been encountered.
Macro Definition Directives
MA
eRO
Directive
Label Opcode Operand
name MACRO optional dummy parameter(s)
The name
in
the label field specifies the name
of
the macro body being defined. Any valid user-defined symbol
name can
be
used
as
a macro name. Note that this name must
he
present and must
not
be
terminated
by
a colon.
A dummy parameter can
be
any valid user-defined symbol name or can
be
null.
When
multiple parameters are listed,
they must
be
separated by commas. The scope
of
a dummy parameter
is
limited to its specific macro definition. If a
reserved
symbol
is
used
as
a dummy parameter, its reserved value
is
not recognized. For example, if you code
A,B,C
as
a dummy parameter list, substitutions
will
occur properly. However, you cannot
use
the accumulator
or the
Band
C registers within the macro. Because
of
the limited scope
of
dummy parameters, the
use
of
these
registers
is
not affected outside the macro definition.
Dummy parameters
in
a comment are not recognized.
No
substitution occurs tor such parameters.
Dummy parameters may appear
in
a character string. However, the dummy parameter must
be
adjacent to an
ampersand character
(&)
as
explained later
in
this chapter.
Any machine instruction or
applicable assembler directive can
be
included
in
the macro body. The distinguishing
feature
of
macro prototype text
is
that parts
of
it can
be
made variable
by
placing substitutable dummy param-
eters
in
instruction fields. These dummy parameters are the same
as
the symbols
in
the operand field
of
the
MACRO directive.
Example:
Define macro MACl with dummy parameters
Gl,
G2, and G3.