Propeller Manual

Table Of Contents
2: Spin Language Reference – BYTE
An Alternative Memory Reference
There is yet another way to access the data from the code example above; you could
reference the data symbols directly. For example, this statement reads the first byte of the
MyData list:
Temp := MyData[0]
And these statements read the second and third bytes of MyData:
Temp := MyData[1]
Temp := MyData[2]
Other Addressing Phenomena
Both the
BYTE 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 := byte[@MyStr][-1] 'Read last byte of MyData (before MyStr)
Temp := byte[@MyData][3] 'Read first byte of MyStr (after MyData)
Temp := MyStr[-3] 'Read first byte of MyData
Temp := MyData[-2] 'Read byte that is two bytes 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.
Accessing Bytes of Larger-Sized Symbols (Syntax 4)
In
PUB and PRI blocks, syntax 4 of BYTE is used to read or write byte-sized components of
word-sized or long-sized variables. For example:
VAR
word WordVar
long LongVar
PUB Main
WordVar.byte := 0 'Set first byte of WordVar to 0
WordVar.byte[0] := 0 'Same as above
WordVar.byte[1] := 100 'Set second byte of WordVar to 100
LongVar.byte := 25 'Set first byte of LongVar to 25
LongVar.byte[0] := 25 'Same as above
LongVar.byte[1] := 50 'Set second byte of LongVar to 50
Propeller Manual v1.1 · Page 55