Hardware Reference
In-Depth Information
with the macro body. A procedure call is a machine instruction that is inserted into
the object program and that will later be executed to call the procedure. Figure 7-4
compares macro calls with procedure calls.
Item
Macro call
Procedure call
When is the call made?
During assembly
During program execution
Is the body inserted into the object
program every place the call is
made?
Ye s
N o
Is a procedure call instruction
inserted into the object program
and later executed?
No
Yes
Must a return instruction be used
after the call is done?
No
Yes
How many copies of the body ap-
pear in the object program?
One per macro call One
Figure 7-4. Comparison of macro calls with procedure calls.
Conceptually, it is best to think of the assembly process as taking place in two
passes. On pass one, all the macro definitions are saved and the macro calls ex-
panded. On pass two, the resulting text is processed as though it was in the origi-
nal program. In this view, the source program is read in and is then transformed
into another program from which all macro definitions have been removed, and in
which all macro calls have been replaced by their bodies. The resulting output, an
assembly language program containing no macros at all, is then fed into the assem-
bler.
It is important to keep in mind that a program is a string of characters includ-
ing letters, digits, spaces, punctuation marks, and ''carriage returns'' (change to a
new line). Macro expansion consists of replacing certain substrings of this string
with other character strings. A macro facility is a technique for manipulating char-
acter strings, without regard to their meaning.
7.2.2 Macros with Parameters
The macro facility previously described can be used to shorten source pro-
grams in which precisely the same sequence of instructions occurs repeatedly. Fre-
quently, however, a program contains several sequences of instructions that are al-
most but not quite identical, as illustrated in Fig. 7-5(a). Here the first sequence
exchanges P and Q , and the second sequence exchanges R and S.
Macro assemblers handle the case of nearly identical sequences by allowing
macro definitions to provide formal parameters and by allowing macro calls to
supply actual parameters . When a macro is expanded, each formal parameter
 
 
 
Search WWH ::




Custom Search