Hardware Reference
In-Depth Information
MOV EAX,P
MOV EBX,Q
MOV Q,EAX
MOV P,EBX
The programmer has defined SWAP as an abbreviation for the four statements
shown above.
MOV
EAX,P
SWAP MACRO
MOV
EBX,Q
MOV EAX,P
MOV
Q,EAX
MOV EBX,Q
MOV
P,EBX
MOV Q,EAX
MOV P,EBX
MOV
EAX,P
ENDM
MOV
EBX,Q
MOV
Q,EAX
SWAP
MOV
P,EBX
SWAP
(a)
(b)
Figure 7-3. Assembly language code for interchanging P and Q twice. (a) With-
out a macro. (b) With a macro.
Although different assemblers have slightly different notations for defining
macros, all require the same basic parts in a macro definition:
1. A macro header giving the name of the macro being defined.
2. The text that is the body of the macro.
3. A pseudoinstruction marking the end of the definition (e.g., ENDM ).
When the assembler encounters a macro definition, it saves it in a macro defi-
nition table for subsequent use. From that point on, whenever the name of the
macro ( SWAP in the example of Fig. 7-3) appears as an opcode, the assembler re-
places it by the macro body. The use of a macro name as an opcode is known as a
macro call and its replacement by the macro body is called macro expansion .
Macro expansion occurs during the assembly process and not during execution
of the program. This point is important. The program of Fig. 7-3(a) and that of
Fig. 7-3(b) will produce precisely the same machine language code. Looking only
at the machine language program, it is impossible to tell whether or not any macros
were involved in its generation. The reason is that once macro expansion has been
completed the macro definitions are discarded by the assembler. No trace of them
is left in the generated program.
Macro calls should not be confused with procedure calls. The basic difference
is that a macro call is an instruction to the assembler to replace the macro name
 
Search WWH ::




Custom Search