BASIC Stamp Architecture – Math and Operators
Page 62
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
right. If you wanted to be even more specific, you could write 12 +
((3*2)/4). When there are parentheses within parentheses, the BASIC
Stamp works from the innermost parentheses outward. Parentheses
placed within parentheses are called nested parentheses.
The BASIC Stamp performs all math operations by the rules of positive
integer math. That is, it handles only whole numbers, and drops any
fractional portions from the results of computations. The BASIC Stamp
handles negative numbers using two's complement rules.
The BS2, BS2e, BS2sx and BS2p can interpret two’s complement negative
numbers correctly in DEBUG and SEROUT instructions using modifiers
like SDEC (for signed decimal). In calculations, however, it assumes that
all values are positive. This yields correct results with two’s complement
negative numbers for addition, subtraction, and multiplication, but not for
division.
The standard operators we just discussed: +, - ,* and / all work on two
values; as in 1 + 3 or 26 * 144. The values that operators process are
referred to as arguments. So we say that the add, subtract, multiply and
divide operators take two arguments.
Operators that take one argument are called unary operators and those
that take two are called binary operators. Please note that the term “binary
operator” has nothing to do with binary numbers; it’s just an inconvenient
coincidence that the same word, meaning ‘involving two things’ is used in
both cases.
The minus sign (-) is a bit of a hybrid, it can be used as a unary operator as
well: as in -4.
In classifying the BASIC Stamp's math and logic operators, we divide
them into two types: unary and binary. Unary operators take precedence
over binary; the unary operation is always performed first. For example,
on the BS2, BS2e, BS2sx and BS2p, SQR is the unary operator for square
root. In the expression 10 - SQR 16, the BASIC Stamp first takes the square
root of 16, then subtracts it from 10.
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
1
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
I
NTEGER
M
ATH
.
U
NARY AND
B
INARY
O
PERATORS
.
N
OTES ABOUT THE
16-
BIT
WORKSPACE
.
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...