BASIC Stamp Architecture – //, MIN
Page 70
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
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.
Value1 VAR WORD
Value2 VAR WORD
Value1 = 100
Value2 = - 3200
Sign = Value1.BIT15 ^ Value2.BIT15 ' Sign = (Value1 sign) XOR (Value1 sign).
Value2 = ABS Value2 / ABS Value1 ' Divide absolute values.
IF Sign = 0 THEN Skip0 ' Negate result if one of the
Value2 = - Value2 ' argument was negative.
Skip0:
DEBUG SDEC ? Value2 ' Show the result (-32)
The Modulus operator (//) returns the remainder left after dividing one
value by another. Some division problems don’t have a whole-number
result; they return a whole number and a fraction. For example, 1000/6 =
166.667. Integer math doesn’t allow the fractional portion of the result, so
1000/6 = 166. However, 166 is an approximate answer, because 166*6 =
996. The division operation left a remainder of 4. The // (double-slash)
returns the remainder of a given division operation. Naturally, numbers
that divide evenly, such as 1000/5, produce a remainder of 0. Example:
SYMBOL Value1 = W0
SYMBOL Value2 = W1
Value1= 1000
Value2= 6
Value1= Value1 // Value2 ' Get remainder of Value1 / Value2.
DEBUG Value1 ' Show the result (4).
-- or --
Value1 VAR WORD
Value2 VAR WORD
Value1= 1000
Value2= 6
Value1= Value1 // Value2 ' Get remainder of Value1 / Value2.
DEBUG DEC ? Value1 ' Show the result (4).
The Minimum operator (MIN) limits a value to a specified 16-bit positive
minimum. The syntax of MIN is:
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
M
ODULUS
: //
M
INIMUM
: MIN
1
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
Содержание 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...