Shop OBEX P1 Docs P2 Docs Learn Events
Assembly Question: Indirect Reference (looping through code) — Parallax Forums

Assembly Question: Indirect Reference (looping through code)

Sam SchweighartSam Schweighart Posts: 5
edited 2010-05-30 17:37 in Propeller 1
Is it possible to do an indirect reference in assembly? (I apologize if I'm using the wrong terminology)

I have a number of variables (100) starting at var1. Is it possible to create a loop in assembly, and add 1 to all of them?

Or do I have to name each variable and explicitly add one to each of them.

:loop
add    (some reference), #1
goto loop

.
.
.
res var 100





VS

add    var1, #1
add    var2, #1
add    var3, #1

.
.
.


var1 res 1
var2 res 1
var3 res 1
.
.
.



]

Post Edited (Sam Schweighart) : 5/30/2010 3:30:15 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-30 15:23
    There is no built-in indirect addressing nor are there any index registers. The sort of thing you want to do is accomplished by doing instruction modification where you calculate the address, then put it directly into an instruction to be executed. Here's one example:
       movd   addIt, #var1          ' initialize address
       mov     count, #10         ' number of items to increment
    addIt:
       add   0-0,#1           ' note 0-0 is used as placeholder
       add   addIt,dest1          ' increment destination address
       djnz   count, #addIt          ' decrement count, branch if not done
    '...
    dest1   long   1 << 9          ' destination address starts at bit 9
    count   res   1
    var1   res   10
    
  • Sam SchweighartSam Schweighart Posts: 5
    edited 2010-05-30 15:30
    Ahh, That makes sense. Thanks for your help!
  • Sam SchweighartSam Schweighart Posts: 5
    edited 2010-05-30 15:41
    Actually, I have a quick question...

    The place holder '0-0' ... why did you use '0-0'? Was it arbitrary? Could I just use '0' or '123' ?

    Thanks!
  • KyeKye Posts: 2,200
    edited 2010-05-30 15:43
    Yeah, it just makes the code more readable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-30 16:09
    "0-0" is unlikely to be used for any other purpose and it has the value zero. It's relatively easy to spot in code.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-30 17:37
    Sam,

    When you modify an instruction to do indirect referencing, be sure to execute at least one instruction between the modifying and modified instructions (e.g. mov count, #10 and djnz count, #addIt in Mike's example). This is necessary because of the Propeller's instruction pipelining. You can use a nop if you have to.

    -Phil
Sign In or Register to comment.