Specifications

BASIC Stamp II
Page 240 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
w1 = -1575
w2 = 976
w1 = w1 + w2 ' Add the numbers.
debug sdec ? w1 ' Show the result (-599).
-
Subtracts variables and/or constants, returning a 16-bit result. Works
exactly as you would expect with unsigned integers from 0 to 65535. If
the result is negative, it will be correctly expressed as a signed 16-bit
number. For example:
w1 = 1000
w2 = 1999
w1 = w1 - w2 ' Subtract the numbers.
debug sdec ? w1 ' Show the result (-999).
/
Divides variables and/or constants, returning a 16-bit result. Works
exactly as you would expect with unsigned integers from 0 to 65535.
Use / only with positive values; signed values do not provide correct
results. Here’s an example of unsigned division:
w1 = 1000
w2 = 5
w1 = w1 / w2 ' Divide w1 by w2.
debug dec ? w1 ' Show the result (200).
A workaround to the inability to divide signed numbers is to have
your program divide absolute values, then negate the result if one (and
only one) of the operands was negative. All values must lie within the
range of -32767 to +32767. Here is an example:
sign var bit ' Bit to hold the sign.
w1 = 100
w2 = -3200
sign = w1.bit15 ^ w2.bit15 ' Sign = (w1 sign) XOR (w2 sign).
w2 = abs w2 / abs w1 ' Divide absolute values.
if sign = 0 then skip0 ' Negate result if one of the
w2 = -w2 ' arguments was negative.
skip0:
debug sdec ? w2 ' Show the result (-32)