BASIC Stamp Architecture – Order of Operations
Page 60
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
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 'Compile time assignment
Cheers CON 3 ' Compile time.
Glasses CON Cheers * 2 - 1 ' Compile time.
OneNinety CON 100 + 90 ' Compile time.
NoWorkee CON 3 * Result ' ERROR: Variables not allowed here
Result = Glasses ' Runtime.
Result = 99 + Glasses ' Runtime.
Result = One 1 ' "100 + 90" solved at compile-time,
' One 1 solved at runtime.
Result = 100 + 90 ' 100 + 90 solved at runtime.
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 CON 3 * Result” would
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 (/).
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
W
HEN IS
R
UNTIME
?
O
RDER OF
O
PERATIONS
.
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...