4: BASIC Stamp Architecture – /
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 69
is the upper byte of the multiplier (0 to 255 whole units) and the fraction is
the lower byte of the multiplier (0 to 255 units of 1/256 each). The */ (star-
slash) instruction gives you an excellent workaround for the BASIC
Stamp's integer-only math. Suppose you want to multiply a value by 1.5.
The whole number, and therefore the upper byte of the multiplier, would
be 1, and the lower byte (fractional part) would be 128, since 128/256 = 0.5.
It may be clearer to express the */ multiplier in hex—as $0180—since hex
keeps the contents of the upper and lower bytes separate. Here's an
example:
Value1 VAR WORD
Value1= 100
Value1= Value1*/ $0180 ' Multiply by 1.5 [1 + (128/256)]
debug ? Value1 ' Show result (150).
To calculate constants for use with the */ instruction, put the whole
number portion in the upper byte, then use the following formula for the
value of the lower byte: Hint: INT( fraction * 256). For instance, take Pi (
π
,
3.14159). The upper byte would be $03 (the whole number), and the lower
would be INT(0.14159 * 256) = 36 ($24). So the constant Pi for use with */
would be $0324. This isn’t a perfect match for Pi, but the error is only
about 0.1%.
The Divide operator (/) 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:
SYMBOL Value1 = W0
SYMBOL Value2 = W1
Value1= 1000
Value2= 5
Value1= Value1 / Value2 ' Divide the numbers.
DEBUG Value1 ' Show the result (200).
-- OR --
Value1 VAR WORD
Value2 VAR WORD
Value1= 1000
Value2= 5
Value1= Value1 / Value2 ' Divide the numbers.
DEBUG DEC ? Value1 ' Show the result (200).
1
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
D
IVIDE
: /
1
2
e
2
sx
2
p
2
Содержание BASIC Stamp 1
Страница 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...