Propeller Manual

Table Of Contents
BYTE – Spin Language Reference
following it at $1B. Note that the starting address ($18) is arbitrary and is likely to change as
the code is modified or the object itself is included in another application.
Data
64 $AA 55 “H” “e” “l” “l” “o” 0
Figure 2-1: Main Memory Byte-Sized Data Structure and Addressing
$18
(0)
[MyData]
$19
(1)
$1A
(2)
$1B
(0)
[MyStr]
$1C
(1)
$1E
(3)
$1D
(2)
$1F
(4)
Byte Address
(Byte Offset)
[Byte Symbol]
$20
(5)
Near the top of the code, the first executable line of the
MemTest method,
Temp := byte[@MyData][1], reads a byte-sized value from main memory. It sets local
variable
Temp to $AA; the value read from main memory address $19. The address $19 was
determined by the address of the symbol
MyData ($18) plus byte offset 1. The following
progressive simplification demonstrates this.
byte[@MyData][1] ¨ byte[$18][1] ¨ byte[$18 + 1] ¨ byte[$19]
The next line, byte[@MyStr][0] := "M", writes a byte-sized value to main memory. It sets the
value at main memory address $1B to the character “M.” The address $1B was calculated
from the address of the symbol
MyStr ($1B) plus byte offset 0.
byte[@MyStr][0] ¨ byte[$1B][0] ¨ byte[$1B + 0] ¨ byte[$1B]
Addressing Main Memory
As Figure 2-1 shows, main memory is really just a set of contiguous bytes and the addresses
are calculated in terms of bytes. This concept is a consistent theme for any commands that
use addresses.
Main memory is ultimately addressed in terms of bytes regardless of the size of value you are
accessing; byte, word, or long. This is advantageous when thinking about how bytes, words,
and longs relate to each other, but it may prove problematic when thinking of multiple items
of a single size, like words or longs. See the Syntax 3 discussions for
WORD (page 229) and
LONG (page 130) for examples of accessing words and longs.
For more explanation of how data is arranged in memory, see the
DAT section’s Declaring
Data(Syntax 1) on page 100.
Page 54 · Propeller Manual v1.1