LONG
Title: | LONG |
Author: | CardboardGuru |
Published: | Thu, 27 Dec 2007 09:59:36 GMT |
LONG
In Spin a long is a signed integer. Unlike words and bytes which are unsigned. In assembler it's your choice whether it's signed or not, depending on what operand variants you use.
LONG is used as a keyword in 4 different ways:
LONG Symbol <[Count]>
Declaration of a Spin long variable. Guaranteed to be long aligned. When compiling, Spin groups all the long declarations together in a block before all the word and 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 RDLONG/WRLONG.
LONG <Data> <, Data>...
LONG <Data> [ count ]
Declare a long aligned label. 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 RDLONG/WRLONG ).
When a long data value is followed by a count in square brackets, that number of longs will be created. This is useful for pre-initialising block or arrays of data within a Cog.
LONG [BaseAddressInBytes]
LONG [BaseAddressInBytes] [OffsetInLongs]
In spin will read/write to a word in Hub RAM. It can only do long aligned read/write, in other words it ignores the least significant two bits of BaseAddressInBytes.
{{LONG [BaseAddressInBytes] := value}}
'Is equivalent to:
{{BYTE[ BaseAddressInBytes & $FFFE ] := value & $FF}}
{{BYTE[ BaseAddressInBytes | $0001 ] := (value >> 8) & $FF}}
{{LONG [BaseAddressInBytes] [OffsetInLongs] := value}}
'Is equivalent to:
{{BYTE[(BaseAddressInBytes&$FFFE)+(OffsetInWords*2)] := value & $FF}}
{{BYTE[(BaseAddressInBytes|$0001)+(OffsetInWords*2)] := (value >> 8) & $FF}}
Symbol.LONG[OffsetInWords]
In spin will read/write to a long in Hub RAM. Symbol must be a long variable. It'd more straightforward to use simple array indexing - Symbol[Offset].
See also
WORD
BYTE
LONG vs RES
Symbol Address operator