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.

The following listing shows a macro that uses unique labels and equates.

Listing: Unique Label Macro Definition
my_macro: .macro 
 alpha\@ = my_count 
my_count .set my_count + 1 
 add alpha\@,d0 
 jmp label\@ 
 add d1,d0 
label\@: 
 nop 
 .endm 

The following listing shows two calls to the my_macro macro, with my_count initialized to 0.

Listing: Invoking my_macro Macro
my_count .set 0 
 my_macro 
 my_macro 

The following listing shows the expanded my_macro code after the two calls.

Listing: Expanding my_macro Calls
alpha??0000 = my_count 
my_count .set my_count + 1 
 add alpha??0000,d0 
 jmp label??0000 
 add d1,d0 
label??0000 
 nop 
alpha??0001 = my_count 
my_count .set my_count + 1 
 add alpha??0001,d0 
 jmp label??0001 
 add d1,d0 
label??0001 
 nop