Propeller Manual

Table Of Contents
WORD – Spin Language Reference
Temp := MyData[1]
Temp := MyData[2]
So why wouldn’t you just use direct symbol references all the time? Consider the following
case:
Temp := MyList[0]
Temp := MyList[1]
Referring back to the example code above Figure 2-5, you might expect these two statements
to read the first and second words of
MyList; $FF99 and 1000, respectively. Instead, it reads
the first and second “bytes” of
MyList, $99 and $FF, respectively.
What happened? Unlike
MyData, the MyList entry is defined in the code as byte-sized and
byte-aligned data. The data does indeed consist of word-sized values, because each element
is preceded by
WORD, but since the symbol for the list is declared as byte-sized, all direct
references to it will return individual bytes.
However, the
WORD designator can be used instead, since the list also happens to be word-
aligned because of its position following
MyData.
Temp := word[@MyList][0]
Temp := word[@MyList][1]
The above reads the first word, $FF99, followed by the second word, 1000, of MyList. This
feature is very handy should a list of data need to be accessed as both bytes and words at
various times in an application.
Other Addressing Phenomena
Both the
WORD and direct symbol reference techniques demonstrated above can be used to
access any location in main memory, regardless of how it relates to defined data. Here are
some examples:
Temp := word[@MyList][-1] 'Read last word of MyData (before MyList)
Temp := word[@MyData][3] 'Read first word of MyList (after MyData)
Temp := MyList[-6] 'Read first byte of MyData
Temp := MyData[-2] 'Read word that is two words before MyData
These examples read beyond the logical borders (start point or end point) of the lists of data
they reference. This may be a useful trick, but more often it’s done by mistake; be careful
when addressing memory, especially if you’re writing to that memory.
Page 232 · Propeller Manual v1.1