|
III.11.6 Premature End of a Macro Expansion
Sometimes it is useful, if a macro expansion can be terminated, before
the end of the macro body is reached. This can be forced with the EXITM
(exit macro) instruction. However, this makes sense in conjunction with
conditional assembly only.
Example:
FLEXIBLE MACRO QUANTITY
DB 'Text'
IF QUANTITY LE 255
EXITM
ENDIF
DW QUANTITY
ENDM
The macro FLEXIBLE always has to insert the string 'Text'
into the CODE space. After that, it should insert a 16-bit
constant only, if the numerical value of the parameter
QUANTITY is greater than 255.
Otherwise the macro expansion should be terminated with
EXITM before. If the macro is called as follows,
FLEXIBLE 42
it will be expanded to
DB 'Text'
in list mode $GENONLY/$CONDONLY.
However, if it is called like this,
FLEXIBLE 4711
it will be expanded to:
DB 'Text'
DW 4711
When a macro expansion is terminated with EXITM, all IFxx constructions that
have been opened within the macro body so far, are closed.
Of course macro bodies may also contain control statements. If an include
file is inserted into a macro body with a $INCLUDE control, and this include
file, or a nested include file, contains an EXITM instruction, all include
file levels up to the next macro level are closed at this point, and the
expansion of that macro is terminated immediately.
|