Creating Unique Labels and Equates

Use the backslash and at characters (\@) to have the assembler generate unique labels and equates within a macro. Each time you invoke the macro, the assembler generates a unique symbol of the form ??nnnn, such as ??0001 or ??0002.

In your code, you refer to such unique labels and equates just as you do for regular labels and equates. But each time you invoke the macro, the assembler replaces the \@ sequence with a unique numeric string and increments the string value.

Unique Label Macro Definition shows a macro that uses unique labels and equates. Invoking putstr Macro shows two calls to the putstr macro. Expanding putstr Calls shows the expanded code after the two calls.

Listing 1. Unique Label Macro Definition
putstr: .macro  string
        lis     r3,(str\@)@h

        oris    r3,r3,(str\@)@l

        bl      put_string

        b       skip\@

str\@:  .asciz  string

        .align  4

skip\@:

        .endm
Listing 2. Invoking putstr Macro
putstr 'SuperSoft Version 1.3'
putstr 'Initializing...'
Listing 3. Expanding putstr Calls
        lis     r3,(str??0000)@h
        oris    r3,r3,(str??0000)@l

        bl      put_string

        b       skip??0000

str??0000:      .asciz  'SuperSoft Version

        .align  4

skip??0000:

        lis     r3,(str??0001)@h

        oris    r3,r3,(str??0001)@l

        bl      put_string

        b       skip??0001

str??0001:      .asciz  'Initializing...'

        .align  4

skip??0001: