Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 227
2
Now, assuming that you used the constant cheers wherever your
program needed ‘the number of cheers,’ your upgrade would be
complete.
You can take this idea a step further by defining constants with expres-
sions—groups of math and/or logic operations that the Stamp host
software solves (evaluates) at compile time (the time right after you
press ALT-R and before the BS2 starts running your program). For ex-
ample, suppose the “Cheers” program also controls a pump to fill
glasses with champagne. The number of glasses to fill is always twice
the number of cheers, minus 1. Another constant:
cheers con 5 ‘ # of cheers.
glasses con cheers*2-1 ‘ # of glasses.
As you can see, one constant can be defined in terms of another. That
is, the number glasses depends on the number cheers.
The expressions used to define constants must be kept fairly simple.
The Stamp host software solves them from left to right, and doesn’t
allow you to use parentheses to change the order of evaluation. Only
nine operators are legal in constant expressions as shown in Table M-4.
This may seem odd, since the BS2’s runtime math operations can be
made quite complex with bushels of parentheses and fancy operators,
but it’s the way things are. Seriously, it might not make sense to allow
really wild math in constant expressions, since it would probably ob-
scure rather than clarify the purpose of the constants being defined.
Table M-4. Operators Allowed in Constant Expressions
(all operations performed as 16-bit math)
+ add
subtract
* multiply
/ divide
<< shift left
>> shift right
& logical AND
| logical OR
^ logical XOR