BYTE

Designator: Declare byte-sized symbol, byte aligned/sized data, or read/write a byte of main memory.

VAR
   BYTE Symbol < [Count] >


DAT
   < Symbol > BYTE Data < [Count] >


((PUBPRI))
  BYTE [BaseAddress] < [Offset] >


((PUBPRI))
  Symbol.BYTE < [Offset] >

  • Symbol is the desired name for the variable (Syntax 1) or data block (Syntax 2) or is the existing name of the variable (Syntax 4).
  • Count is an optional expression indicating the number of byte-sized elements for Symbol (Syntax 1), or the number of byte-sized entries of Data (Syntax 2) to store in a data table.
  • Data is a constant expression or comma-separated list of constant expressions. Quoted strings of characters are also allowed; they are treated as a comma-separated list of characters.
  • BaseAddress is an expression describing the address of main memory to read or write. If Offset is omitted, BaseAddress is the actual address to operate on. If Offset is specified, BaseAddress + Offset is the actual address to operate on.
  • Offset is an optional expression indicating the offset from BaseAddress to operate on, or the offset from byte 0 of Symbol.

Explanation

BYTE is one of three multi-purpose declarations (BYTE, WORD, and LONG) that declare or operate on memory. BYTE can be used to:

  1. declare a byte-sized (8-bit) symbol or a multi-byte symbolic array in a VAR block, or
  2. declare byte-aligned, and possibly byte-sized, data in a DAT block, or
  3. read or write a byte of main memory at a base address with an optional offset, or
  4. access a byte within a word-sized or long-sized variable. 

Range of Byte

Memory that is byte-sized (8 bits) can contain a value that is one of 28 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 or Post-Clear '~' in a Spin expression to convert a byte value that you interpret as "signed" (-128 to +127) to a signed long value.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.