Propeller Manual

Table Of Contents
BYTE – Spin Language Reference
Page 52 · Propeller Manual v1.1
Range of Byte
Memory that is byte-sized (8 bits) can contain a value that is one of 2
8
possible combinations
of bits (i.e., one of 256 combinations). This gives byte-sized values a range of 0 to 255.
Since the Spin language performs all mathematic operations using 32-bit signed math, any
byte-sized values will be internally treated as positive long-sized values. However, the actual
numeric value contained within a byte is subject to how a computer and user interpret it. For
example, you may choose to use the Sign-Extend 7 operator (
~), page 156, in a Spin
expression to convert a byte value that you interpret as “signed” (-128 to +127) to a signed
long value.
Byte Variable Declaration (Syntax 1)
In
VAR blocks, syntax 1 of BYTE is used to declare global, symbolic variables that are either
byte-sized, or are any array of bytes.
For example:
VAR
byte Temp 'Temp is a byte
byte Str[25] 'Str is a byte array
The above example declares two variables (symbols), Temp and Str. Temp is simply a single,
byte-sized variable. The line under the
Temp declaration uses the optional Count field to
create an array of 25 byte-sized variable elements called
Str. Both Temp and Str can be
accessed from any
PUB or PRI method within the same object that this VAR block was declared;
they are global to the object. An example of this is below.
PUB SomeMethod
Temp := 250 'Set Temp to 250
Str[0] := "A" 'Set first element of Str to "A"
Str[1] := "B" 'Set second element of Str to "B"
Str[24] := "C" 'Set last element of Str to "C"
For more information about using BYTE in this way, refer to the VAR section’s Variable
Declarations (Syntax 1) on page 210, and keep in mind that
BYTE is used for the Size field in
that description.
Byte Data Declaration (Syntax 2)
In
DAT blocks, syntax 2 of T BYTE is used to declare byte-aligned, and/or byte-sized data that is
compiled as constant values in main memory.
DATT blocks allow this declaration to have an