Chapter
5.
Macros
5-2
The concepts of macro definition, call, and expansion can be illustrated by a typical business form letter, where
the
prototype
instructions consist
of
preset text. For example,
we
could define a macro CNFIRM with the
text
Air
Flight welcomes you
as
a passenger.
Your flight number FNO leaves at DTIME and arrives
in
DEST at ATIME.
This macro has four dummy pdrameters to be replaced, when the macro
is
called, by the actual flight number,
departure time,
de<;tination, and arrival time. Thus the macro call might look like
CNFIRM
123,
'10:45',
'Ontario',
'11
:52'
A second macro, CAR, could
be
called
if
the passenger has requested
that
a rental car be reserved
at
the desti-
nation airport. This macro might
have the
text
Your automobile reservation has been confirmed with
MAKE
rent-a-car agency.
Finally, a macro GREET could be defined
to
specify the passenger name.
Dear NAME:
The entire
text
of the busines', letter (source file) would then look like
GREET 'Ms. Scannel'
CNFIRM 123,
'10:45',
'Ontario',
'11
:52'
CAR 'Blotz'
We
trust you
will
enjoy your flight.
Sincerely,
When
this source file i, passed through a macro processor, the mdcro cdlls are expdnded to produce the following
letter.
Dear
Ms.
Scannel:
Air
Flight welcomes ',IOU
as
a passenger. Your flight number 123 leaves at 10:45 and arrives
in
Ontario at
11
:52. Your automobile reservation has been confirmed with Blotz rent-a-car
agency.
We
trust you
will
enjoy your flight.
Sincerely,
While this example illustrates the substitution of parameters
in
a macro,
it
overlooks the relationship of the macro
processor and the assembler. The purpose of the macro processor
is
to generate source code which
is
then
assembled.