BASIC Stamp Architecture – Order of Operations
On the BS2, BS2e, BS2sx and BS2p, not all of the math or logic operations
in a program are solved by the BASIC Stamp. The editor software solves
operations that define constants before the program is downloaded to the
BASIC Stamp. The preprocessing that takes place before the program is
downloaded is referred to as "compile time."
After the download is complete, the BASIC Stamp starts executing your
program; this is referred to as "runtime." At runtime the BASIC Stamp
processes math and logic operations involving variables, or any
combination of variables and constants.
Because compile-time and runtime expressions appear similar, it can be
hard to tell them apart. A few examples will help:
Result
VAR
BYTE
Cheers
CON
3
Glasses
CON
Cheers * 2 - 1
OneNinety CON
100 + 90
NoWorkee CON
3 * Result
Result = Glasses
Result = 99 + Glasses
Result = OneNinety + 1
Result = 100 + 90
Notice that the last example is solved at runtime, even though the math
performed could have been solved at compile time since it involves two
constants. If you find something like this in your own programs, you can
save some EEPROM space by converting the run-time expression 100+90
into a compile-time expression like OneNinety CON 100+90.
To sum up: compile-time expressions are those that involve only
constants; once a variable is involved, the expression must be solved at
runtime. That's why the line "NoWorkee
generate an error message. The CON directive works only at compile time,
so variables are not allowed.
Let's talk about the basic four operations of arithmetic: addition (+),
subtraction (-), multiplication (*), and division (/).
Page 60 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
'Compile time assignment
' Compile time.
' Compile time.
' Compile time.
' ERROR: Variables not allowed here
' Runtime.
' Runtime.
' "100 + 90" solved at compile-time,
' OneNinety + 1 solved at runtime.
' 100 + 90 solved at runtime.
CON
3 * Result" would
W
R
?
HEN IS
UNTIME
2
2
2
2
e
sx
p
2
2
2
2
e
sx
p
O
.
O
RDER OF
PERATIONS
2
2
2
1
2
e
p
sx
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?