Operating instructions

Sweet-16 Programming
Using Macros
Some
very
useful information
is
presented about
Macros
in
general, the APPLE
II
Sweet·16 Interpreter,
and
how to
use
them together.
Richard
C.
Vile, Jr.
3467
Yellowstone Drive
Ann Arbor,
MI
48105
and
INC LOC1L
BNE
=
+5
INC LOC1H
INC LOC2L
BNE
=
+5
INC LOC2H
The symbol
WHERE
does not represent
a specific memory location, but poten-
tially many different memory locations.
INCD
(COUNT)
The actual parameter is substituted for
all occurrences of the dummy parameter
in
the macro body and the instructions
in the macro body are assembled direct-
ly
into the program at the point
of
the
macro call. This is known
as
"expan-
ding"
the call:
It is called,
in
assembler terminology, a
formal or dummy parameter. Even
though our example has only one formal
parameter, macros in general may have
many. The three exclamation marks
preceding the name INCD indicate
to
the
assembler that the label INCD is the
name of a macro. '.MD' stands for Macro
Definition and '.ME' stands for Macro
End.
The sequence
of
instructions bet-
ween .MD and .ME is called the body
of
the macro. Once a macro definition is
written into a program, the macro may
subsequently be called
by
using its
name
in
an
instruction,
as
if
it were
an
opcode. More
sophisticated
macro
assemblers allow macros to appear
in
any field
of
an
instruction, rather than
just the opcode field. When a macro is
called, the programmer is obligated
to
supply
actual
parameters to replace the
dummy parameters used
in
the defini-
tion. In the example given above, when
(NCO
is called,
it
must
be
accompanied
by
the label associated with an actual
memory location used by the program:
.MD (WHERE)
INC WHERE
BNE
=
+5
INC WHERE+ 1
.ME
!!!
INC
0
where the
symbol'
='
is used
to
refer
to
the location
of
the instruction being
assembled. These two sequences both
have the same purpose:
to
cause the
16
bit
quantity
stored
in
two consecutive
memory locations to
be
increased by
one. For this example we have assumed
that the locations are not
in
page zero
and are directly addressed. A macro
assembler will allow these sequences
to
be abbreviated using a new symbol,
chosen by the programmer. The symbol
must
be
formally declared in a Macro
Definition, before it is used. Such a
definition is shown below using the
notation
of
the ASMrrED assembler
of
Carl Moser:
Macro
assemblers
extend
the
capabilities
of
ordinary assemblers
by
providing ways
to
abbreviate commonly
used sequences of instructions. Often a
programmer
will use sequences
of
in-
structions
that
have identical opcodes
and addressing modes, but differ only
in
the memory locations referred to. Con-
sider the following:
The history
of
computer program-
ming is replete with stories
of
the
development
of
new tools. Assemblers
were designed with the purpose
of
reliev-
ing the programmer of the tedium
of
pro-
gramming in binary machine language.
Over the course
of
the past twenty years,
various features have been added
to
assembly languages
to
further ease the
pain. Prime among these inventions has
been the macro capability available in
many
assemblers.
Macros
provide
means for extending the expressive
capabilities
of
assembly
language.
Another software tool developed
in
re-
cent years is the virtual machine. A vir-
tual machine is emulated, imitated or in-
terpreted by a program. It provides
capabilities not directly available in the
hardware
of
the real machine on which
it
is simulated. This article discusses the
combined
application
of
macro
assembly and virtual machine inter-
pretation on the APPLE
II
personal com·
puter system.
Macro Assemblers
January, 1980
MICRO
--
The 6502 Journal
20:25