BASIC stamp manual v2.2

BRANCH – BASIC Stamp Command Reference
Page 134 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Demo Program (BRANCH.bs1)
' BRANCH.bs1
' This program shows how the value of idx controls the destination of the
' BRANCH instruction.
' {$STAMP BS1}
' {$PBASIC 1.0}
SYMBOL idx = B2
Main:
DEBUG "idx: ", #idx, " "
BRANCH idx, (Task_0, Task_1, Task_2) ' branch to task
DEBUG "BRANCH target error...", CR, CR ' ... unless out of range
Next_Task:
idx = idx + 1 // 4 ' force idx to be 0..3
GOTO Main
Task_0:
DEBUG "BRANCHed to Task_0", CR
GOTO Next_Task
Task_1:
DEBUG "BRANCHed to Task_1", CR
GOTO Next_Task
Task_2:
DEBUG "BRANCHed to Task_2", CR
GOTO Next_Task
Demo Program (BRANCH.bs2)
' BRANCH.bs2
' This program shows how the value of idx controls the destination of the
' BRANCH instruction.
' {$STAMP BS2}
' {$PBASIC 2.5}
idx VAR Nib
Main:
DEBUG "idx: ", DEC1 idx, " "
BRANCH idx, [Task_0, Task_1, Task_2] ' branch to task
DEBUG "BRANCH target error...", CR, CR ' ... unless out of range
Next_Task:
idx = idx + 1 // 4 ' force idx to be 0..3
1
All
2
NOTE: This example program can be
used with all BS2 models by changing
the $STAMP directive accordingly.