Next: Getting Preprocessed Output, Previous: Defining Macros, Up: Using the Assembler Preprocessor [Contents][Index]
Macros often contain the definitions of location labels that must not duplicate when expanding a macro multiple times. To define a number of location labels in the local scope of a macro, you can define local symbols for them using lines of code like these:
lu0 def u##__UNIQUE__ lu1 def u##__UNIQUE__ lu2 def u##__UNIQUE__
The above directives define the symbols lu0
, lu1
, and lu2
with values that have the form ui
, where i is an increasing integer number.
When expanding the macro the first time, the symbols lu0
, lu1
, and lu2
take the values u1
, u2
, u3
(if there are no definitions of other symbols using the predefined symbol ‘__UNIQUE__’).
When expanding the macro the second time, the symbols lu0
, lu1
, and lu2
take the values u4
, u5
, u6
, and so on.
Thus, the values of the symbols lu0
, lu1
, and lu2
are always unique, and you can use them for location labels within macros expanded multiple times.
The following example of a macro illustrates this:
emit_ch macro lu0 def u##__UNIQUE__ lu1 def u##__UNIQUE__ lu2 def u##__UNIQUE__
choice case 0.33, lu0 case 0.33, lu1 end choice
emit "A" jmp lu2
lu0: emit "B" jmp lu2
lu1: emit "C" lu2: end macro
This macro emits the character ‘A’, ‘B’, or ‘C’ by the corresponding user instruction emit
.
You can safely expand the macro an arbitrary number of times—location labels are unique in every expansion.
For example, to emit a sequence of two characters, expand the macro twice:
... emit_ch emit_ch ...
Next: Getting Preprocessed Output, Previous: Defining Macros, Up: Using the Assembler Preprocessor [Contents][Index]