BASIC Stamp Architecture – ABS, COS, DCD, ~, -
Page 64
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
The Absolute Value operator (ABS) converts a signed (two’s complement)
16-bit number to its absolute value. The absolute value of a number is a
positive number representing the difference between that number and 0.
For example, the absolute value of -99 is 99. The absolute value of 99 is
also 99. ABS works on two’s complement negative numbers. Examples of
ABS at work:
Result VAR WORD
Result = -99 ' Put -99 (2's complement format) into Result.
DEBUG SDEC ? Result ' Display it on the screen as a signed #.
DEBUG SDEC ? ABS Result ' Display it on the screen as a signed #.
The Cosine operator (COS) returns the two’s complement, 16-bit cosine of
an angle specified as an 8-bit (0 to 255) angle. See the explanation of the
SIN operator, below. COS is the same in all respects, except that the cosine
function returns the x distance instead of the y distance. To demonstrate
the COS operator, use the example program from SIN, below, but
substitute COS for SIN.
The Decoder operator (DCD) is a 2
n
-power decoder of a four-bit value.
DCD accepts a value from 0 to 15, and returns a 16-bit number with the
bit, described by value, set to 1. For example:
Result VAR WORD
Result = DCD 12 ' Set bit 12.
DEBUG BIN ? Result ' Display result (%0001000000000000)
The Inverse operator (~) complements (inverts) the bits of a number. Each
bit that contains a 1 is changed to 0 and each bit containing 0 is changed to
1. This process is also known as a “bitwise NOT” and one's compliment.
For example:
Result VAR BYTE
Result = %11110001 ' Store bits in byte Result.
DEBUG BIN ? Result ' Display in binary (%11110001).
Result = ~ Result ' Complement Result.
DEBUG BIN ? Result ' Display in binary (%00001110).
The Negative operator (-) negates a 16-bit number (converts to its two’s
complement).
SYMBOL Result = W1
Result = -99 ' Put -99 (2's complement format) into Result.
Result = 100 ' Add 100 to it.
DEBUG Result ' Display Result (1)
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
1
A
BSOLUTE
V
ALUE
: ABS
C
OSINE
: COS
D
ECODER
: DCD
I
NVERSE
: ~
N
EGATIVE
: -
Содержание 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...