PDA

View Full Version : Assembly Question: Indirect Reference (looping through code)



Sam Schweighart
05-30-2010, 10:53 PM
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

Mike Green
05-30-2010, 11:23 PM
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 Schweighart
05-30-2010, 11:30 PM
Ahh, That makes sense. Thanks for your help!

Sam Schweighart
05-30-2010, 11:41 PM
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!

Kye
05-30-2010, 11:43 PM
Yeah, it just makes the code more readable.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Mike Green
05-31-2010, 12:09 AM
"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)
05-31-2010, 01:37 AM
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