View Single Post
Mentor
28Jan2012,14:18  
xpi0t0s's Avatar
It isn't necessarily going to be the same for every CPU, that's why I asked in the first place. But if you think it'll help, have a look at http://uva.ulb.ac.be/cit_courseware/asm/mc68000.htm and scroll down to ADDRESS REGISTER INDIRECT WITH INDEX (8-BIT) and MOVE.W $02(A0,A1.W),D0 is the relevant command.

So let's suppose you have a data structure in memory stored at A0. The offset into that data structure of the data item you want is $02. And you want to iterate over that item - maybe it's a string, for example. You don't want to change A0 because you want to keep that address around, and if you change it you'd have to remember by how much you changed it, and remember to change it back, so overall that's a bad idea. So what you need is a throwaway counter variable, and that's what the index is for.

So the code would start with A1=0, and suppose it's a C string that's NULL-terminated, so you pull out of memory the character defined by $02(A0,A1.W) which is (A0+2)+0. If that string is "hi" then that's an 'h'.

You then increment A1 by 1 and pull the next byte out of memory, which is 'i' at (A0+2)+1.

You then increment A1 by 1 and pull the next byte out of memory, which is '\0' (the terminating NULL) at (A0+2)+2.

Put all that in a loop and you have the following pseudocode:

Code:
A1=0
D0=( (A0+2)+A1 )
while D0 != 0 LOOP
// do whatever you want with D0 - display it on the screen, for example
A1=A1+1
D0=( (A0+2)+A1 )
END LOOP