Propeller Manual

Table Of Contents
2: Spin Language Reference – BYTE
optional symbol preceding it, which can be used for later reference (See DAT, page 99). For
example:
DAT
MyData byte 64, $AA, 55 'Byte-aligned and byte-sized data
MyString byte "Hello",0 'A string of bytes (characters)
The above example declares two data symbols, MyData and MyString. Each data symbol
points to the start of byte-aligned and byte-sized data in main memory.
MyData’s values, in
main memory, are 64, $AA and 55, respectively.
MyString’s values, in main memory, are
“H”, “e”, “l”, “l”, “o”, and 0, respectively. This data is compiled into the object and resulting
application as part of the executable code section and may be accessed using the read/write
form, syntax 3, of
BYTE (see below). For more information about using BYTE in this way, refer
to the
DAT section’s Declaring Data(Syntax 1) on page 100, and keep in mind that BYTE is
used for the Size field in that description.
Data items may be repeated by using the optional Count field. For example:
DAT
MyData byte 64. $AA[8], 55
The above example declares a byte-aligned, byte-sized data table, called MyData, consisting of
the following ten values: 64, $AA, $AA, $AA, $AA, $AA, $AA, $AA, $AA, 55. There were
eight occurrences of $AA due to the
[8] in the declaration immediately after it.
Reading/Writing Bytes of Main Memory (Syntax 3)
In
PUB and PRI blocks, syntax 3 of BYTE is used to read or write byte-sized values of main
memory. This is done by writing expressions that refer to main memory using the form:
byte[BaseAddress][Offset]. Here’s an example.
PUB MemTest | Temp
Temp := byte[@MyData][1] 'Read byte value
byte[@MyStr][0] := "M" 'Write byte value
DAT
MyData byte 64, $AA, 55 'Byte-sized/aligned data
MyStr byte "Hello", 0 'A string of bytes (characters)
In this example, the DAT block (bottom of code) places its data in memory as shown in Figure
2-1. The first data element of
MyData is placed at memory address $18. The last data element
of
MyData is placed at memory address $1A, with the first element of MyStr immediately
Propeller Manual v1.1 · Page 53