Shop OBEX P1 Docs P2 Docs Learn Events
Need help creating a pointer to a COG RAM block in PASM — Parallax Forums

Need help creating a pointer to a COG RAM block in PASM

Mike GMike G Posts: 2,702
edited 2010-04-06 08:39 in Propeller 1
I'm simply trying to fill a buffer in COG ram using a pointer. The following PASM code works but I want to use a pointer so I can increment and decrement.

...
                  mov     rxBuffer, #1
                  mov     rxBuffer+1,#2


rxBuffer                res     64  





I've been sitting here for a couple hours trying to figure out the syntax. I though this would be really easy. I read the Propeller manual ( I don't know how many times to date) and I tried a forum search. I must be missing a concept or I'm not using the correct language.

Thanks for any help.

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-04-06 03:07
    As far as I can see there is no "indexed" addressing in PASM except for the RD/WR-BYTE,WORD,LONG instructions. Nor is one really needed since the 9 bit source and destination address can access the entire cog ram.

    You have 2 options that can accomplish the same thing by modifying the MOV instruction.

    The first option is to keep the address pointer in a long and use a MOVS or MOVD to copy the address to the source or destination of your MOV instruction.

    The second option is to add (or subtract) %1 for the source address, or %1000000000 for the destination address of the MOV instruction.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-06 04:11
                 movd   :moveIt,#rxBuffer   ' initialize destination address
                 movs   :moveIt,#otherBuf   ' initialize source address
                 mov     count,#64               ' number of longs to copy.  Also allows for pipeline delay
    :moveIt  mov   0-0,0-0                    ' "0-0" is just a placeholder
                 add     :moveIt,bothIncr     ' increment both source and destination
                 djnz    count,#:moveIt       ' count down, loop if not yet zero
    '...
    bothIncr long    1<<9 + 1               ' ones line up with source and destination
    count     res     1
    rxBuffer res     64
    otherBuf res    64
    
  • potatoheadpotatohead Posts: 10,261
    edited 2010-04-06 04:22
    Just in case, "1<<9", means "take one, and shift it left 9 times", shorthand for %10_0000_0000, which then has %01 added to it. That syntax tripped me up the first time I worked through this use case.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!
  • Mike GMike G Posts: 2,702
    edited 2010-04-06 04:32
    Thanks all,

    I get the idea... a little foggy. So I have some work to do.

    I really appreciate the help.
  • potatoheadpotatohead Posts: 10,261
    edited 2010-04-06 04:52
    You get that the instruction itself is being modified, right? That's the key element here. On many CPU's, there are specific registers that contain addresses and indexes. Of course, on those you specify a mode, such as direct, or indirect, then just modify the pointer registers.

    In the case of the propeller, the instruction IS the pointer, in that the source and destination bit fields hold the actual memory values to be moved, and they are simply changed on each loop through the block copy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!
  • Mike GMike G Posts: 2,702
    edited 2010-04-06 08:39
    potatohead said...
    You get that the instruction itself is being modified, right?

    Yeah, I get it now. My mind was set on something like the wrbyte instruction.

    I don't know how many times I read Page 312 (MOVD) to 314 (MOVS) in the propeller manual. It didn't click until I worked through Mike Green's example and read your explanation a few times.

    Thanks again.
Sign In or Register to comment.