| ||||||||||||||||
| ||||||||||||||||
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.
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.
Now, suppose that FIRST, SECOND, and THIRD are word variables. A macro invocation of the form GET_BIG FIRST, SECONDexpands as follows: MOV AX, FIRST CMP AX, SECOND JG ??0000 MOV AX, SECOND ??0000:A later call of the form: GET_BIG SECOND, THIRDexpands 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.
|