Shop OBEX P1 Docs P2 Docs Learn Events
How to access a byte from COG RAM? — Parallax Forums

How to access a byte from COG RAM?

Hey there,
I've got a quiet simple question which I don't know the answer to: I have reserved an amount of _SOME_CONSTANT longs in my COG RAM inside a DAT block. Now I wan't to check the value of the bytes at certain indexes(if you think off it as an array of bytes). My question simply is, if I do something like this:
DAT                     org     0
                        ' fill SomeLongs with values
                        add     CompareLSB,             #DestInc
CompareLSB              cmp     SomeLongs,              #0

DestInc                 long    (%10_0000_0000 * (_SOME_SIZE * 4 - 1))
SomeLongs               res     _SOME_SIZE
will it only compare the byte which ends at the LSB or what will it do - and is there a better way of doing what I'm trying to achieve?

Thanks in advance,
DragonRaider5

Comments

  • COG RAM is organized as longs, so it's not possible to directly access bytes in the COG. If you really need to access bytes then you have to load the long then shift and mask yourself.

    To treat part of the COG RAM as an array you have to use self modifying code, changing the DST field of the instruction. So test index i of the array at SomeLongs you'd do something like:
         mov  Addr, #SomeLongs
         add  Addr, i
         movd Addr, CompareLSB
         nop                               '' have to let the pipeline clear
    CompareLSB
         cmp 0-0, #0 wc,wz   '' the 0-0 is overwritten by the movd above
    
    Again, that's to access longs; accessing bytes would be considerably more complicated, you'd have to mask out the low bits of the index, load the whole long, and use those low bits to select a byte within the long.

    If the array is in HUB RAM you can just use rdbyte, which is a lot easier.
Sign In or Register to comment.