Hardware Reference
In-Depth Information
MOV
EAX,P
CHANGE MACRO P1, P2
MOV
EBX,Q
MOV EAX,P1
MOV
Q,EAX
MOV EBX,P2
MOV
P,EBX
MOV P2,EAX
MOV P1,EBX
MOV
EAX,R
ENDM
MOV
EBX,S
MOV
S,EAX
CHANGE P, Q
MOV
R,EBX
CHANGE R, S
(a)
(b)
Figure 7-5. Nearly identical sequences of statements. (a) Without a macro.
(b) With a macro.
appearing in the macro body is replaced by the corresponding actual parameter.
The actual parameters are placed in the operand field of the macro call. Figure
7-5(b) shows the program of Fig. 7-5(a) rewritten using a macro with two parame-
ters. The symbols P1 and P2 are the formal parameters. Each occurrence of P1
within a macro body is replaced by the first actual parameter when the macro is ex-
panded. Similarly, P2 is replaced by the second actual parameter. In the macro
call
CHANGE P, Q
P is the first actual parameter and Q is the second actual parameter. Thus the ex-
ecutable programs produced by both parts of Fig. 7-5 are identical. They contain
precisely the same instructions with the same operands.
7.2.3 Advanced Features
Most macro processors have a whole raft of advanced features to make life
easier for the assembly language programmer. In this section we will take a look at
a few of MASM's advanced features. One problem that occurs with all assemblers
that support macros is label duplication. Suppose that a macro contains a condi-
tional branch instruction and a label that is branched to. If the macro is called two
or more times, the label will be duplicated, causing an assembly error. One solu-
tion is to have the programmer supply a different label on each call as a parameter.
A different solution (used by MASM) is to allow a label to be declared LOCAL ,
with the assembler automatically generating a different label on each expansion of
the macro. Some other assemblers have a rule that numeric labels are automat-
ically local.
MASM and most other assemblers allow macros to be defined within other
macros. This feature is most useful in combination with conditional assembly.
 
 
Search WWH ::




Custom Search