SLAU131Y October 2004 – June 2021
All labels in an assembly language program must be unique. This includes labels in macros. If a macro is expanded more than once, its labels are defined more than once. Defining a label more than once is illegal. The macro language provides a method of defining labels in macros so that the labels are unique. Simply follow each label with a question mark, and the assembler replaces the question mark with a period followed by a unique number. When the macro is expanded, you do not see the unique number in the listing file. Your label appears with the question mark as it did in the macro definition. You cannot declare this label as global. See Section 5.9.3 for more about labels.
The syntax for a unique label is:
label ? |
Unique Labels in a Macro shows unique label generation in a macro. The maximum label length is shortened to allow for the unique suffix. For example, if the macro is expanded fewer than 10 times, the maximum label length is 126 characters. If the macro is expanded from 10 to 99 times, the maximum label length is 125. The label with its unique suffix is shown in the cross-listing file. To obtain a cross-listing file, invoke the assembler with the --cross_reference option (see Section 5.4).
1 * Define macro to find minimum
2
3 MIN .macro src1,src2,dst
4 CMP src1,src2
5 JL m1?
6 MOV src1,dst
7 JMP m2?
8 m1? MOV src2,dst
9 m2?
10 .endm
11
12 0000 MIN R11,R12,R13
1 0000 9B0C CMP R11,R12
1 0002 3802 JL m1?
1 0004 4B0D MOV R11,R13
1 0006 3C01 JMP m2?
1 0008 4C0D m1? MOV R12,R13
1 m2?