Propeller Manual

Table Of Contents
WORD – Spin Language Reference
Range of Word
Memory that is word-sized (16 bits) can contain a value that is one of 2
16
possible
combinations of bits (i.e., one of 65,536 combinations). This gives word-sized values a range
of 0 to 65,535. Since the Spin language performs all mathematic operations using 32-bit
signed math, any word-sized values will be internally treated as positive long-sized values.
However, the actual numeric value contained within a word is subject to how a computer and
user interpret it. For example, you may choose to use the Sign-Extend 15 operator (
~~), page
157, in a Spin expression to convert a word value that you interpret as “signed” (-32,768 to
+32,767) to a signed long value.
Word Variable Declaration (Syntax 1)
In
VAR blocks, syntax 1 of WORD is used to declare global, symbolic variables that are either
word-sized, or are any array of words. For example:
VAR
word Temp 'Temp is a word (2 bytes)
word List[25] 'List is a word array
The above example declares two variables (symbols), Temp and List. Temp is simply a single,
word-sized variable. The line under the
Temp declaration uses the optional Count field to
create an array of 25 word-sized variable elements called
List. Both Temp and List can be
accessed from any
PUB or PRI method within the same object that this VAR block was declared;
they are global to the object. An example of this is below.
PUB SomeMethod
Temp := 25_000 'Set Temp to 25,000
List[0] := 500 'Set first element of List to 500
List[1] := 9_000 'Set second element of List to 9,000
List[24] := 60_000 'Set last element of List to 60,000
For more information about using WORD in this way, refer to the VAR section’s Variable
Declarations (Syntax 1) on page 210, and keep in mind that
WORD is used for the Size field in
that description.
Page 228 · Propeller Manual v1.1