WORD
Designator: Declare word-sized symbol, word aligned/sized data, or read/write a word of main memory.
VAR
WORD Symbol < [Count ] >
DAT
< Symbol > WORD Data < [Count] >
((PUB ┆ PRI))
WORD [BaseAddress] < [Offset ] >
((PUB ┆ PRI))
Symbol.WORD < [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 word-sized elements for Symbol (Syntax 1), or the number of word-sized entries of Data (Syntax 2) to store in a data table.
- Data is a constant expression or comma-separated list of constant expressions.
- BaseAddress is an expression describing the word-aligned 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 * 2 is the actual address to operate on.
- Offset is an optional expression indicating the offset from BaseAddress to operate on, or the offset from word 0 of Symbol. Offset is in units of words.
Explanation
WORD is one of three multi-purpose declarations (BYTE, WORD, and LONG) that declare or operate on memory. WORD can be used to:
- declare a word-sized (16-bit) symbol or a multi-word symbolic array in a VAR block, or
- declare word-aligned, and/or word-sized, data in a DAT block, or
- read or write a word of main memory at a base address with an optional offset, or
- access a word within a long-sized variable.
Range of Word
Memory that is word-sized (16 bits) can contain a value that is one of 216 possible combinations of bits (i.e., one of 65,536 combinations). This gives word-sized values a range of 0 to 65,535. Since the Spin language performs all mathematic operations using 32-bit signed math, any word-sized values will be internally treated as positive long-sized values. However, the actual numeric value contained within a word is subject to how a computer and user interpret it. For example, you may choose to use the Sign-Extend 15 or Post-Set '~~' operator in a Spin expression to convert a word value that you interpret as "signed" (-32,768 to +32,767) to a signed long value.
Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.