Page 17 of 62
SBasic User's Manual SBasic Version 2.7 Page 17
Printed: December 5, 1999
Labels
SBasic does not support line numbers, but it does support line labels.
Line labels consist of a string of up to 20 characters, ending with a
colon (:). Labels must begin with an alphabetic character or an
underscore ('_'); remaining characters in a label can also include
digits. Any text following a line label definition is ignored.
NOTE: Though legal, starting labels with an underscore can cause
obscure problems if you embed assembly language in your SBasic source
file. See the section below on ASM and ENDASM, regarding references
to SBasic variables from within an ASM block.
Example:
foo: ' define the line label foo
a = 3 ' write a value to A
return ' return from this subroutine
main: ' start of the main program
gosub foo ' execute the subroutine foo
This example shows several important points. Note that labels require
a trailing colon only when they are defined, but not when they are
referenced. Thus, the GOSUB to FOO doesn't need a colon at the end of
FOO.
Also, every SBasic program MUST contain the line label MAIN, even if
it contains no other line labels. The startup code that supports
SBasic on the target system always jumps to the label MAIN: to begin
execution. If your program does not have a MAIN:, the compiler will
report an error.
Note that the line label MAIN does not mark the first line of your
program's code; it only marks the starting point for execution of your
program following reset. You are free to place the line label MAIN
anywhere in your file you deem appropriate.