Shop OBEX P1 Docs P2 Docs Learn Events
rdlong and memory organization — Parallax Forums

rdlong and memory organization

Hey,

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

  • depends on what you think the first 8 bit are.

    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

  • Vega256Vega256 Posts: 197
    edited 2016-01-01 00:07
    msrobots wrote: »
    depends on what you think the first 8 bit are.

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2016-01-01 00:15
    Vega256 wrote:
    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?
    The most-significant byte of r1 will be $AA; the least significant, $DD.

    -Phil
  • Vega256 wrote: »
    ...
    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.

    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
  • Since the cog memory is only accessed in 32-bit chunks, endianess is irrelevant. Endianess is only
    with a meaning when the bus can be accessed at several widths.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2016-01-02 17:54
    If you use a statement that writes a long to memory, reading that same long in PASM will produce the same result.

    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)
Sign In or Register to comment.