BASIC stamp manual v2.2
BASIC Stamp Architecture – Defining Variables
Page 86 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
number of bits of storage for the variable. NOTE: The top example is for
the BS1 and the bottom example is for all BS2 models.
There are certain rules regarding symbol names. Symbols must start with
a letter or underscore, can contain a mixture of letters, numbers, and
underscore (_) characters, and must not be the same as PBASIC reserved
words, or labels used in your program. Additionally, symbols can be up to
32 characters long. See Appendix B for a list of PBASIC reserved words.
PBASIC does not distinguish between upper and lower case, so the names
MYVARIABLE, myVariable, and MyVaRiAbLe are all equivalent.
For the BS1, the register name is one of the predefined "fixed" variable
names, such as W0, W1, B0, B1, etc. Here are a few examples of variable
declarations on the BS1:
SYMBOL temporary = W0 ' value can be 0 to 65535
SYMBOL counter = B1 ' value can be 0 to 255
SYMBOL result = B2 ' value can be 0 to 255
The above example will create a variable called temporary whose contents
will be stored in the RAM location called W0. Also, the variable counter
will be located at RAM location B1 and result at location B2. Note that
temporary is a word-sized variable (because that's what size W0 is) while
the other two are both byte-sized variables. Throughout the rest of the
program, we can use the names temporary, counter, and result instead of
W0, B1 and B2, respectively. This makes the code much more readable; it's
easier to determine what counter is used for than it would be to figure out
what the name B1 means. Please note that counter resides at location B1,
and B1 happens to be the high byte of W0. This means than changing
counter will also change temporary since they overlap. A situation like this
usually is a mistake and results in strange behavior, but is also a powerful
feature if used carefully.
For all BS2 models, the Size argument has four choices: 1) Bit (1 bit), 2) Nib
(nibble; 4 bits), 3) Byte (8 bits), and 4) Word (16 bits). Here are some
examples of variable declarations on the BS2 models:
mouse VAR BIT ' Value can be 0 or 1.
cat VAR NIB ' Value can be 0 to 15.
dog VAR BYTE ' Value can be 0 to 255.
rhino VAR WORD ' Value can be 0 to 65535.
T
HE RULES OF SYMBOL NAMES.
1
1
All
2
All
2