BRA - Branch Always Command
The Branch Always command is used to skip over sections of code. If we reach this command we will branch to the label… always.
This can also be used to loop a task. It is functionally similar to using the Jump command.
For more advanced code, you can also use this to branch to a distance past the label using the X register as the distance to overshoot.
Syntax
BRA label
Where label is the location you want to skip to. This is the simple version that simply jumps to the label.
BRA label,x
Where label is the location you want to skip. Adding the "x" tells the task to skip past the label a distance equal to the value in the X register. This is the advanced version that allows you to dynamically skip to multiple locations.
Examples
Example 1
This task is a looping chase.
Task1()
{
Name="RGB Chase"
Area=5
Fade=4
Delay=6
Loop:
Preset(P=5) //Red
Delay()
Preset(P=6) //Green
Delay()
Preset(P=7) //Blue
Delay()
Preset(P=8) //Pink
Delay()
BRA Loop //Branches to the label "Loop:"
}
Example 2
This task uses the X Reg for a jump table
Task2()
{
Name="Linear Preset Jump Table"
Start(0x1c,10,x,0x65,x,x,x) //Start on an area 10 linear preset message
Copy @0,~0,7 //Copy the message to user ram
LDA ~2 //Load the preset number into the accumulator
MUL 4 //Multiply the value by 4. This creates an offset of 4
TAX //Transfer the value in the accumulator to the x register
BRA PJumper,x //Jump to the label plus the value in the x register
Null
PJumper: //This is the jump table. The task will jump to the specified row.
BRA P1
BRA P2
BRA P3
BRA P4
BRA P5
Null
P1:
//Do something for Preset 1
Null
...
}