Propeller Manual

Table Of Contents
2: Spin Language Reference – WORD
Propeller Manual v1.1 · Page 233
Accessing Words of Larger-Sized Symbols (Syntax 4)
In
PUB and PRI blocks, syntax 4 of WORD is used to read or write word-sized components of
long-sized variables. For example:
VAR
long LongVar
PUB Main
LongVar.word := 65000 'Set first word of LongVar to 65000
LongVar.word[0] := 65000 'Same as above
LongVar.word[1] := 1 'Set second word of LongVar to 1
This example accesses the word-sized components of LongVar, individually. The comments
indicate what each line is doing. At the end of the
Main method LongVar will equal 130,536.
The same techniques can be used to reference word-sized components of long-sized data
symbols.
PUB Main | Temp
Temp := MyList.word[0] 'Read low word of MyList long 0
Temp := MyList.word[1] 'Read high word of MyList long 0
MyList.word[1] := $1234 'Write high word of MyList long 0
MyList.word[2] := $FFEE 'Write low word of MyList long 1
DAT
MyList long $FF998877, $DDDDEEEE 'Long-sized/aligned data
The first and second executable lines of Main read the values $8877 and $FF99, respectively,
from
MyList. The third line writes $1234 to the high word of the long in element 0 of MyList,
resulting in a value of $12348877. The fourth line writes $FFEE to the word at index 2 in
MyList (the low word of the long in element 1), resulting in a value of $DDDDFFEE.