Shop OBEX P1 Docs P2 Docs Learn Events
Quick question about reserve symbols — Parallax Forums

Quick question about reserve symbols

mononautmononaut Posts: 2
edited 2011-05-03 17:20 in Propeller 1
I'm pretty new to the spin language (and micro programming in general), so please forgive me if this is a really simple problem.

The RES assembly command allows an optional number of longs to be reserved, but I can't seem to figure out how to refer to any besides the first. I'm working on a project that would benefit from having four longs under one symbol, but once I declare "red res 4," from what I understand, "red" will only refer to the first long in the reserve memory at that address. How can I quickly get the address for the next few longs after the first?

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-05-03 14:39
    You'll probably want self modifying code. This snippet was provided by Mike Green.
    DAT
    ''Snippet - Self modifying code
                            movd   :moveIt,#rxBuffer     ' initialize destination address
                            movs   :moveIt,#otherBuf     ' initialize source address
                            mov     count,#5            ' 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     5
    otherBuf                res     5
    
  • mononautmononaut Posts: 2
    edited 2011-05-03 14:53
    This is very helpful, thank you! Like I said, I'm still new to micro programming, and I still haven't even trained my brain to think about registers as commands... before you posted that snippet, I'd have taken a long time to figure out what movd and movs are actually for.

    Also, the very concept of self-modifying code is very new to me.
  • kuronekokuroneko Posts: 3,623
    edited 2011-05-03 17:20
    mononaut wrote: »
    ... but once I declare "red res 4," from what I understand, "red" will only refer to the first long in the reserve memory at that address. How can I quickly get the address for the next few longs after the first?
    This entirely depends on how you're going to access them. If it's in a loop (array access) then self-modifying code as suggested by Mike (and provided by Mike) is the way to go. If you need one-off access then the following will do:
    mov red+0, cnt        ' equivalent to mov red, cnt
        mov red+2, value
        mov red+1, red+3
    
Sign In or Register to comment.