Specifications
BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 235
2
16-bit Workspace
Most of the descriptions that follow say something like ‘computes (some
function) of a 16-bit value.’ This does not mean that the operator does
not work on smaller byte or nibble values. It just means that the com-
putation is done in a 16-bit workspace. If the value is smaller than 16
bits, the BS2 pads it with leading 0s to make a 16-bit value. If the 16-bit
result of a calculation is to be packed into a smaller variable, the higher-
order bits are discarded (truncated).
Keep this in mind, especially when you are working with two’s comple-
ment negative numbers, or moving values from a larger variable to a
smaller one. For example, look what happens when you move a two’s
complement negative number into a byte:
b2 = -99
debug sdec ? b2 ' Show signed decimal result (157).
How did -99 become 157? Let’s look at the bits: 99 is %01100011 binary.
When the BS2 negates 99, it converts the number to 16 bits
%0000000001100011, and then takes the two’s complement,
%1111111110011101. Since we’ve asked for the result to be placed in an
8-bit (byte) variable, the upper eight bits are truncated and the lower
eight bits stored in the byte: %10011101.
Now for the second half of the story. Debug’s SDEC modifier expects a
16-bit, two’s complement value, but has only a byte to work with. As
usual, it creates a 16-bit value by padding the leading eight bits with
0s: %0000000010011101. And what’s that in signed decimal? 157.
Each of the instruction descriptions below includes an example. It’s a
good idea to test your understanding of the operators by modifying
the examples and seeing whether you can predict the results. Experi-
ment, learn, and work the Debug instruction until it screams for mercy!
The payoff will be a thorough understanding of both the BS2 and com-
puter-oriented math.










