4: BASIC Stamp Architecture – Defining Variables
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 49
byte). Unlike I/O variables, there’s no reason that your program variables
have to be stuck in a specific position in the BASIC Stamp’s physical
memory. A byte is a byte regardless of its location. And if a program uses
a mixture of variables of different sizes, it can be a pain in the neck to
logically dole them out or allocate storage.
More importantly, mixing fixed variables with automatically allocated
variables (discussed in the next section) is an invitation to bugs. A fixed
variable can overlap an allocated variable, causing data meant for one
variable to show up in another! The fixed variable names (of the general-
purpose variables) are only provided for power users who require
absolute access to a specific location in RAM.
We recommend that you avoid using the fixed variables in most
situations. Instead, let PBASIC allocate variables as described in the next
section. The editor software will organize your storage requirements to
make optimal use of the available memory.
Before you can use a variable in a PBASIC program you must declare it.
“Declare” means letting the BASIC Stamp know that you plan to use a
variable, what you want to call it, and how big it is. Although PBASIC
does have predefined variables that you can use without declaring them
first (see previous sections), the preferred way to set up variables is to use
the directive SYMBOL (for the BS1) or VAR (for all other BASIC Stamps).
Here is the syntax for a variable declaration:
SYMBOL Name = RegisterName
-- OR --
Name VAR Size
where Name is the name by which you will refer to the variable,
RegisterName is the "fixed" name for the register and Size indicates the
number of bits of storage for the variable. NOTE: The top example is for
the BS1 and the bottom example is for all other BASIC Stamps.
There are certain rules regarding symbol names. Symbols must start with
a letter, can contain a mixture of letters, numbers, and underscore (_)
characters, and must not be the same as PBASIC keywords or labels used
in your program. Additionally, symbols can be up to 32 characters long.
1
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
D
EFINING AND
U
SING
V
ARIABLES
.
T
HE
R
ULES OF
S
YMBOL
N
AMES
.
Summary of Contents for BASIC Stamp 2e
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...