Label - Target For Branch/Jump Command
A Label is a marker in the code. It has no functional operation other than being a pointer that the code can refer to. Labels within a task are local to that task and can be reused in other tasks. Labels outside of tasks are common to all tasks for use with the Copy command.
When you load tasking from a device all the label names will be replaced with generic values making the code harder to read. |
Syntax
LabelName:
BRA LabelName
When referencing a label you only use the name. For the location of the label you put a colon after the name.
-
It is case-sensitive. When it is referenced in a command such as BRZ, 'Day' and 'day' are not the same thing.
-
It must start with a letter. 'FirstMarker' is fine but '1stMarker' is not.
-
It cannot contain any gaps. 'First_Marker' is fine but 'First Marker' is not.
-
Cannot contain any symbols but underscores.
When naming your labels try to make them descriptive and follow a formatting convention to make them visually distinct such as CamelCase or all_lowercase. |
Examples
Example 1
Branching to a label.
{
LDA ~2 //Load ~2 memory location
CMP #0x00 //Compare if it is 0x00
BRZ P1 //If it matches branch to label "P1:" If it doesn't match continue.
CMP #0x01 //Compare if it is 0x01
BRZ P2 //If it matches branch to label "P2:" If it doesn't match continue.
CMP #0x02 //Compare if it is 0x02
BRZ P3 //If it matches branch to label "P3:" If it doesn't match continue.
CMP #0x03 //Compare if it is 0x03
BRZ P4 //If it matches branch to label "P4:" If it doesn't match continue.
Null
P1:
Preset(A=4,P=1)
Null
P2:
Preset(A=4,P=2)
Null
P3:
Preset(A=4,P=3)
Null
P4:
Preset(A=4,P=4)
Null
}
Example 2
NewVector to a label.
{
LightsOn:
Preset(A=5,P=1)
Preset(A=8,P=1)
NewVector(LightsOff)
Null
LightsOff:
Preset(A=5,P=4)
Preset(A=8,P=4)
NewVector(LightsOn)
Null
}
Example 3
Copying from a label.
Not that the label is not within the task so any task can reference it.
OneTouch_Message: DyNet(0x1C,0x02,0x00,0x6B,0x00,0x00,0xFF) //One Touch Message
Startup1()
{
Name="Start Task"
Copy OneTouch_Message, ~30,7 // Copy a default status message to ~30-36
}
Example 4
Loading from a label.
Loading from an array using the X register.
PresetOpcodeArray: Send2(0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D)
{
...
LDA ~15 //Load the preset number we want to send
ADD #4 //Add 4. Arrays have an index of 4
SWAP //Swap it into the X Register
LDA PresetOpcodeArray,x //Grab the correct opcode from the array
STA ~3 //Store it into the opcode byte of the classic preset message.
TX ~0,2,7 //Send the preset message
Null
...
}
Example 5
Tx’ing from a label.
Using TX command to send a message to the spur only.
Room_Occupied: DyNet(0x1C,200,0x00,0x00,0x00,0x00,0xFF) //P1 for occupancy Bogus
Room_UnOccupied: DyNet(0x1C,200,0x00,0x03,0x00,0x00,0xFF) //P4 for occupancy Bogus
Task1()
{
Name="Room Occupied"
TX Room_Occupied,2,7 //Send Room Occupied preset to spur only
Null
}