BASIC Stamp Architecture – Defining Variables
Page 50
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
See Appendix B for a list of PBASIC keywords. PBASIC does not
distinguish between upper and lower case, so the names MYVARIABLE,
myVariable, and MyVaRiAbLe are all equivalent.
For the BS1, the RegisterName 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. 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 the BS2, BS2e, BS2sx and BS2p, 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, BS2e, BS2sx
or BS2p:
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.
1
1
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
Summary of Contents for BASIC Stamp 1
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...