EasyManua.ls Logo

Intel 8080 - B4_Page_01

Intel 8080
224 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter
5. Macros
Macros
Vs.
Subroutines
At
this point, you may
be
wondering how macros differ from subroutines invoked
by
the CALL instruction.
Both aid program structuring and reduce the coding
of
frequently executed routines.
One distinction between the two
is
that subroutines necessarily branch to another part
of
your program while
macros generate in-line code. Thus, a program contains only one version
of
a given subroutine, but contains
as
many versions
of
a given macro as there are calls for that macro.
Notice the emphasis on 'versions'
in
the previous sentence, for this
is
a major difference between macros and
subroutines. A macro does not necessarily generate the same source code each time it
is
called.
By
changing the
parameters
in
a macro call, you can change the source code the macro generates.
In
addition, macro parameters
can
be
tested at assembly-time by the conditional assembly directives. These two tools enable a general-purpose
macro definition to generate customized source code for a particular programming situation. Notice that macro
expansion and any code customization occur at assembly-time and
at
the source code level.
By
contrast, a
generalized subroutine resides
in
your program and requires execution time.
It
is
usually possible to obtain similar results using either a macro or a subroutine. Determining which
of
these
facilities to
use
is
not always an obvious
deci~ion.
In
some cases, using a single subroutine rather than multiple
in-line macros can reduce the overall program size.
In
situations involving a large number
of
parameters, the
use
of
macros may
be
more efficient. Also, notice that macros can call subroutines, and subroutines can contain
macros.
USI NG MACROS
The assembler recognizes the following macro operations:
MACRO directive
ENDM
directive
LOCAL directive
REPT directive
I
RP
directive
I
RPC
directive
EXITM directive
Macro call
All
of
the directives listed above are related to macro definition. The macro
call
initiates the parameter sub-
stitution (macro expansion) process.
Macro Definition
Macros must
be
defined
in
your program before they can
be
used. A macro definition
is
initiated
by
the
MACRO
assembler directive, which lists the name
by
which the macro can later be called, and the
dummy
parameters to
be
replaced during macro expansion. The macro definition
is
terminated
by
the
ENDM
directive. The prototype
instructions bounded
by
the MACRO and
ENDM
directives are called the macro body,
5-3

Table of Contents

Related product manuals