rdlong and memory organization
Vega256
Posts: 197
in Propeller 1
Hey,
According to the manual, main memory is ultimately stored byte-wise in little endian format. Suppose I wrote:
In memory, a_var looks like:
$DD | $CC | $BB | $AA
$x $x+1 $x+2 $x+3
I then try to read back a_var with rdlong from ASM:
Cog memory is only long-addressable. When the value of a_var is read from main memory to cog memory, will the first 8 bits of r1 start with $DD or $AA?
According to the manual, main memory is ultimately stored byte-wise in little endian format. Suppose I wrote:
var long a_var 'relevant code a_var := $AABBCCDD
In memory, a_var looks like:
$DD | $CC | $BB | $AA
$x $x+1 $x+2 $x+3
I then try to read back a_var with rdlong from ASM:
rdlong r1, a_var_address
Cog memory is only long-addressable. When the value of a_var is read from main memory to cog memory, will the first 8 bits of r1 start with $DD or $AA?
Comments
Since PASM just knows about longs "and r1, #$FF" will result in $DD.
So in PASM you have to mentally think of big endian (doing things like shr/shl/ror/rol etc) while in HUB you have to use little endian while assembling longs out of bytes.
I do have no idea how the data of a cog long is physically organized, and no way to find out. I don't do Verilog...
Enjoy!
Mike
And (if ignoring your instruction) "shr r1, #8", "and r1, #$FF" would result in $CC, correct?
So basically, the first byte of the value being read from is the first byte of the register being read to (even though you can't actually access the byte of the latter).
EDIT:
I see what you mean about it depending on perspective. In my mind, "first" means rightmost.
-Phil
Yes in PASM it does. But in HUB it is the other way around and "first" is leftmost Byte.
rdlong and wrlong do the magic. Or PASM, no way to find out.
Enjoy!
Mike
with a meaning when the bus can be accessed at several widths.
If you write:
X := $01020304
...in Spin, it will read back as $01020304 in PASM.
It's only if you're writing bytes from Spin and reading back longs (from Spin or PASM) that you'd need to worry about the difference. (Or writing longs and reading bytes)