Next: , Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]


5.14.5 Generating Unique Location Labels

Macros should often contain definitions of location labels that must not duplicate when a macro is expanded several times in the source text. When there is a number of location labels used locally in a macro, local symbols can be defined for them using lines of code like these:

lu0     def     u##__UNIQUE__
lu1     def     u##__UNIQUE__
lu2     def     u##__UNIQUE__

The above directives define symbols lu0, lu1, and lu2, values of which have form ui, where i is an increasing integer number. When the macro is expanded the first time, symbols lu0, lu1, and lu2 take the values u1, u2, u3 (if there are no other symbols defined using predefined symbol ‘__UNIQUE__’). When the macro is expanded the second time, symbols lu0, lu1, and lu2 take the values u4, u5, u6, and so on. Thus, values of symbols lu0, lu1, and lu2 will never duplicate, and those symbols can be used for location labels within macros that are expanded several times. This is illustrated by the following example of a macro:

        .data

ls2     probeq  2

        .code

emit_ch macro

lu0     def     u##__UNIQUE__
lu1     def     u##__UNIQUE__
lu2     def     u##__UNIQUE__

        casels  ls2, lu0, lu1
        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. The macro can be safely expanded an arbitrary number of times, and this should not cause problems with duplicate location labels. For example, to emit a sequence of two characters, expand the macro twice:

        ...
        emit_ch
        emit_ch
        ...

Next: , Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]