Propeller Manual

Table Of Contents
2: Spin Language Reference – VAR
PUB SomeMethod
Code := 60000
LargeNumber := Code * 250
GetString(@Str)
if Str[0] == "A"
<more code here>
Notice that Code and LargeNumber are used directly by expressions. The Str reference in the
GetString method’s parameter list looks different; it has an @, the Symbol Address operator,
preceding it. This is because our fictitious
GetString method needs to write back to the Str
variable. If we had said GetString(Str), then the first byte of Str, element 0, would have
been passed to
GetString. By using the Symbol Address operator, @, we caused the address of
Str to be passed to GetString instead; GetString can use that address to write to Str’s
elements. Lastly, we use
Str[0] in the condition of an IF statement to see if the first byte is
equal to the character
"A". Remember, the first element of an array is always zero (0).
Variable Declarations (Syntax 2)
A variation on Syntax 1 allows for comma-delimited variables of the same size. The
following is, similar to the above example, but we declare two words,
Code and Index.
VAR
byte Str[10]
word Code, Index
long LargeNumber
Range of Variables
The range and nature of each type of variable is as follows:
BYTE – 8 bits (unsigned); 0 to 255.
WORD – 16 bits (unsigned); 0 to 65,535.
LONG – 32 bits (signed); -2,147,483,648 to +2,147,483,647.
For more details regarding their range and usage, see
BYTE on page 51, WORD on page 227, and
LONG on page 128.
Propeller Manual v1.1 · Page 211