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
.
Содержание BASIC Stamp 2e
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...