Labels Inside Macros

To avoid the problem of multiple-defined labels resulting from multiple calls to a macro that has labels in its source statements, the programmer can direct the Assembler to generate unique labels on each call to a macro.

Assembler-generated labels include a string of the form _nnnnn where nnnnn is a 5-digit value. The programmer requests an assembler-generated label by specifying \@ in a label field within a macro body. Each successive label definition that specifies a \@ directive generates a successive value of _nnnnn, thereby creating a unique label on each macro call. Note that \@ may be preceded or followed by additional characters for clarity and to prevent ambiguity.

The following listing shows the definition of the clear macro:

Listing: Clear macro definition

clear: MACRO
           LD X, #\1

           LD D6, #16

         \@LOOP: CLR.B (0,X)

           INC.B (0,X)

           DEC D6

           BNE   \@LOOP

        ENDM

This macro is called in the application, as listed in the following listing:

Listing: Calling the clear macro

         clear     temporary
         clear     data

The two macro calls of clear are expanded in the following manner, as listed in the following listing:

Listing: Macro call expansion

             clear temporary
               LD X, #temporary

               LD D6, #16

_00001LOOP: CLR.B (0,X)

               INC.B(0,X)

               DEC D6

               BNE _00001LOOP

               clear data

               LD X, #data

               LD D6, #16

_00002LOOP: CLR.B (0,X)

               INC.B (0,X)

               DEC D6

               BNE _00002LOOP