Labels in Macros 

A macro with a loop or decision structure contains one or more labels. If such a macro is invoked more than once in a program, a duplicate label appears, resulting in an assembly error. This problem can be avoided by using local labels in the macro.

 Labels in Procedures

The LOCAL directive is provided by the assembler to declare labels in a macro local to that macro. The syntax of using local directive is:

    LOCAL local-label1 [, local-label2, ...]
Every time the macro is expanded, the assembler assigns different symbols to the labels in the list.

 Position of Local Label Definition in Macros

Example: Write a macro to place the largest of two words in AX.
  GET_BIG      MACRO  WORD1, WORD2
                      LOCAL EXIT
                      MOV AX, WORD1
                      CMP AX, WORD2
                      JG  EXIT
                      MOV AX, WORD2
                 EXIT:
               ENDM
 

Now, suppose that FIRST, SECOND, and THIRD are word variables. A macro invocation of the form

    GET_BIG FIRST, SECOND
expands as follows:
                    MOV AX, FIRST
                    CMP AX, SECOND
                    JG  ??0000
                    MOV AX, SECOND
            ??0000:
A later call of the form:
    GET_BIG SECOND, THIRD
expands as follows:
                    MOV AX, SECOND
                    CMP AX, THIRD
                    JG  ??0001
                    MOV AX, THIRD
            ??0001:

Subsequent invocations of this macro or to other macros with local labels causes the assembler to insert labels ??0002, ??0003, and so on into the program.

The labels that the assembler generates to replace the local labels are of the form ??XXXX, where XXXX is a hexadecimal number between 0 and FFFFH. Thus, a program can have up to 2^16=65,536 local labels, a large enough number for most programs.

 Conflicts with Local Labels