SLAU131Y October 2004 – June 2021
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.