EasyManua.ls Logo

Intel 8080 - B4_Page_13

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
Macro
Expansion
When
a macro
is
called, the actual parameters to
be
substituted into the prototype code can
be
passed
in
one
of
two modes. Normally, the substitution
of
actual parameters for dummy parameters
is
simply a
text
substitution.
The parameters are not evaluated until the macro
is
expanded.
If
a percent sign
(%)
precedes the actual parameter
in
the macro call, however, the parameter
is
evaluated
immediately, before expansion occurs, and
is
passed
as
a decimal number representing the value
of
the paramo
eter.
In
the case
of
I
RPC,
a '%' preceding the actual parameter causes the entire text string to
be
treated as a
single parameter.
One IRPC iteration occurs for each digit
in
the decimal string passed as the result
of
immediate
evaluation
of
the text string.
The normal mechanism for passing actual parameters
is
adequate for most applications. Using the percent
sign
to pre-evaluate parameters
is
necessary only when the value of the parameter
is
different within the local conĀ·
text
of
the macro definition as compared to its global value outside the macro definition.
Example:
The macro shown
in
this example generates a number
of
rotate instructions. The parameters passed
in
the macro
call determine the number
of
positions the accumulator
is
to
be
rotated and whether rotate right or rotate left
instructions are to
be
generated. Some typical calls for this macro are
as
follows:
SHIFTR
SHIFTR
'R',3
L,%COUNT
-1
The second
call
shows
an
expression used
as
a parameter. This expression
is
to
be
evaluated immediately rather
than
passed simply
as
text.
The definition
of
the
SH
1FT
R macro
is
shown below. This macro
uses
the conditional I F directive to test the
validity
of
the first parameter. Also, the
REPT
macro directive
is
nested within the SHIFTR macro.
SHIFTR
MACRO
X,Y
IF
X
EO
'R'
REPT
Y
RAR
ENDM
ENDIF
IF
X
NE
'L'
EXITM
ELSE
REPT
Y
RAL
ENDM
ENDIF
ENDM
The indentation shown
in
the definition of the SHIFTR macro graphically illustrates the relationships of the IF,
ELSE, ENDIF directives and the REPT,
ENDM
directives. Such indentation
is
not required
in
your program, but
may
be
desirable
as
documentation.
5-15

Table of Contents

Related product manuals