WORD - rosco-pc/propeller-wiki GitHub Wiki
A word is an unsigned integer. Unlike a long which is signed.
WORD
is used as a keyword in 4 different ways:
WORD Symbol
WORD <Size> <Data> <,<Size> Data>...
WORD [BaseAddressInBytes]
WORD [BaseAddressInBytes]``[OffsetInWords]
Symbol.WORD[OffsetInWords]
Declaration of a Spin word variable. Guaranteed to be word aligned. When compiling, Spin groups all the word declarations together in a block after all the long declarations and before the byte declarations, so you can't count on the order of differently sized variables in memory being as in the source. However, all same sized variables will be in the order you declare them.
These variables only exist in Hub memory. They will exist at a place past the binary image combined by PropTool.
They are always initialised to zero.
To access them from assembler, you'd have to pass the address of one to the assembly program through the [[PAR]]
mechanism and use RDWORD
/WRWORD
.
Declare a word aligned label. Size [WORD
|LONG
] indicates how much space to allocate for that labelled location. Size defaults to WORD
. Data will be put into the location modulus the Size field. Layout in memory will reflect the order declared in the source, however differently aligned declarations may result in padding.
The data exists in Hub RAM, and may be copied to [Cog RAM]] when starting a Cog. Spin references will use the original in Hub RAM, Assembler references will use the Cog RAM copy (unless done by reference though PAR
and RDWORD
/WRWORD
).
In spin will read/write to a word in Hub RAM. It can only do word aligned read/write, in other words it ignores the least significant bit of BaseAddressInBytes.
{{WORD [BaseAddressInBytes] := value}}
'Is equivalent to:
{{BYTE[ BaseAddressInBytes & $FFFE ] := value & $FF}}
{{BYTE[ BaseAddressInBytes | $0001 ] := (value >> 8) & $FF}}
{{WORD [BaseAddressInBytes] [OffsetInWords] := value}}
'Is equivalent to:
{{BYTE[(BaseAddressInBytes&$FFFE)+(OffsetInWords*2)] := value & $FF}}
{{BYTE[(BaseAddressInBytes|$0001)+(OffsetInWords*2)] := (value >> 8) & $FF}}
In spin will read/write to a word in Hub RAM. Symbol must be a long or a word variable (although as a word, it'd be more straightforward to use simple array indexing - Symbol[Offset]
).