SLAU131V October 2004 – February 2020
This is an example of code that declares and uses a local label legally:
.global ADDRA, ADDRB, ADDRC
Label1: MOV #ADDRA, R11 ; Load Address A to R11.
SUB #ADDRB, R11 ; Subtract Address B.
JL $1 ; If < 0, branch to $1
MOV #ADDRB, R11 ; otherwise, load ADDRB to R11
JMP $2 ; and branch to $2.
$1 MOV #ADDRA, R11 ; $1: load ADDRA to AC0.
$2 ADD #ADDRC, R11 ; $2: add ADDRC.
.newblock ; Undefine $1 so it can be used again.
JMP $1 ; If less than zero, branch to $1.
MOV R11, &ADDRC ; Store AC0 low in ADDRC.
$1 NOP
The following code uses a local label illegally:
.global ADDRA, ADDRB, ADDRC
Label1: MOV #ADDRA, R11 ; Load Address A to R11.
SUB #ADDRB, R11 ; Subtract Address B.
JL $1 ; If < 0, branch to $1
MOV #ADDRB, R11 ; otherwise, load ADDRB to R11
JMP $2 ; and branch to $2.
$1 MOV #ADDRA, R11 ; $1: load ADDRA to AC0.
$2 ADD #ADDRC, R11 ; $2: add ADDRC.
JMP $1 ; If less than zero, branch to $1.
MOV R11, &ADDRC ; Store AC0 low in ADDRC.
$1 NOP
The $1 label is not undefined before being reused by the second branch instruction. Therefore, $1 is redefined, which is illegal.
Local labels are especially useful in macros. If a macro contains a normal label and is called more than once, the assembler issues a multiple-definition error. If you use a local label and .newblock within a macro, however, the local label is used and reset each time the macro is expanded.
Up to ten local labels of the $n form can be in effect at one time. Local labels of the form name? are not limited. After you undefine a local label, you can define it and use it again. Local labels do not appear in the object code symbol table.
For more information about using labels in macros see Section 6.6.