Hardware Reference
In-Depth Information
Typically, the same macro is defined in both parts of an IF statement, like this:
M1 MACRO
IF WORDSIZE GT 16
M2
MACRO
...
ENDM
ELSE
M2
MACRO
...
ENDM
ENDIF
ENDM
Either way, the macro M2 will be defined, but the definition will depend on wheth-
er the program is being assembled on a 16-bit machine or a 32-bit machine. If M1
is not called, M2 will not be defined at all.
Finally, macros can call other macros, including themselves. If a macro is
recursive, that is, it calls itself, it must pass itself a parameter that is changed on
each expansion and the macro must test the parameter and terminate the recursion
when it reaches a certain value. Otherwise the assembler can be put into an infinite
loop. If this happens, the assembler must be killed explicitly by the user.
7.2.4 Implementation of a Macro Facility in an Assembler
To implement a macro facility, an assembler must be able to perform two func-
tions: save macro definitions and expand macro calls. We will examine these now.
The assembler must maintain a table of all macro names and, along with each
name, a pointer to its stored definition so that it can be retrieved when needed.
Some assemblers have a separate table for macro names and some have a combin-
ed opcode table in which all machine instructions, pseudoinstructions, and macro
names are kept.
When a macro definition is encountered, a table entry is made giving the name
of the macro, the number of formal parameters, and a pointer to another table—the
macro definition table—where the macro body will be kept. A list of the formal
parameters is also constructed at this time for use in processing the definition. The
macro body is then read and stored in the macro definition table. Formal parame-
ters occurring within the body are indicated by some special symbol. For example,
the internal representation of the macro definition of CHANGE with semicolon as
''carriage return'' and ampersand as the formal parameter symbol might be:
MOV EAX,&P1; MOV EBX,&P2; MOV &P2,EAX; MOV &P1,EBX;
Within the macro definition table the macro body is simply a character string.
 
 
Search WWH ::




Custom Search