BASIC stamp manual v2.2

4: BASIC Stamp Architecture – Defining Variables
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 85
The 40-pin BS2p uses the first three words for I/O even though it has
twice as many I/O pins. This is done with the AUXIO, MAINIO, and
IOTERM commands, which effectively switch the auxiliary I/O registers
in and out of the INS, OUTS, and DIRS locations.
Just like the I/O variables, the general-purpose variables have predefined
names: W0 through W12 and B0 through B25. B0 is the low byte of W0; B1
is the high byte of W0; and so on through W12 (B24=low byte, B25=high
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 difficult 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 BS2 models). 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
DEFINING AND USING VARIABLES (VAR).
1
A
ll
2
1
All
2
2
p