Propeller Manual

Table Of Contents
2: Spin Language Reference – LONG
Propeller Manual v1.1 · Page 133
Referring back to the example code above Figure 2-2 you might expect these two statements
to read the first and second longs of
MyList; $FF995544 and 1000, respectively. Instead, it
reads the first and second “bytes” of
MyList, $44 and $55, 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 long-sized values, because each element is
preceded by
LONG, but since the symbol for the list is declared as byte-sized, all direct
references to it will return individual bytes.
However, the
LONG designator can be used instead, since the list also happens to be long-
aligned because of its position following
MyData.
Temp := long[@MyList][0]
Temp := long[@MyList][1]
The above reads the first long, $FF995544, followed by the second long, 1000, of MyList.
This feature is very handy should a list of data need to be accessed as both bytes and longs at
various times in an application.
Other Addressing Phenomena
Both the
LONG 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 := long[@MyList][-1] 'Read last long of MyData (before MyList)
Temp := long[@MyData][2] 'Read first long of MyList (after MyData)
Temp := MyList[-8] 'Read first byte of MyData
Temp := MyData[-2] 'Read long that is two longs 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.