Page 1 of 1

Indexed Indirect and Indirect Inxed addressing

Posted: Wed Aug 23, 2006 7:59 pm
by VanOccupanther
in "Assembly in one step" (which is a great 6502 teacher, humbly i think) they list the two addressing modes like this:


Indexed Indirect (aa, X)
Indirect Indexed (aa), Y

Does that mean that these can only work with zero page addresses?

Posted: Wed Aug 23, 2006 8:20 pm
by tepples
The indirect indexed modes read a pointer that has to be stored in zero page, but this pointer can point anywhere.

Code: Select all

; Load address $FACE into a 16-bit pointer variable stored at zero page $B6
lda #$FA
sta $B7
lda #$CE
sta $B6

ldy #$10
lda ($B6),y
The last instruction reads from $FACE + $10 = $FADE.

Posted: Wed Aug 23, 2006 10:42 pm
by Celius
I often use Indexed Indirect Addressing when I have a couple of addresses in RAM that are grouped together, like AI addresses to go to and stuff. But if you're just doing something like loading a NAM file, or doing CHR RAM stuff, or just loading from one particular address, use Indirect Indexed.

Posted: Thu Aug 24, 2006 1:58 am
by Bregalad
I'm unsure about the name of the adressing mode because they are confusing.
But you should retain the following :
lda [BlahBlah,X]
Will have the effect to load what is in the pointer found by adding the adress of [BlahBlah] and X, so X helps to determine wich pointer you use.
This instruction is usefull if you have several consecutives pointers in Z-Page RAM. However, you have to manually increment each pointer if they point to a table (wich they are likely to do).
Alternativly, the pointers doesn't need to be consecutive. You could also use the trick to read from either one pointer or the other in zero page RAM, have your [BlahBlah] set to zero, and just load the adres of the desired pointer in X.

lda [BlahBlah],Y
Will have the effect to read the adress of [BlahBlah], add the value of Y to it and finally use the final result as a pointer. This is used much more often than the other one (at least from my personnal experience), because it allow random acess to a pointed table, and you only need to keep the base adress of your table in [BlahBlah], and the Y register does the rest. If the pointed data may be more than 256 bytes, then you have to manually add the high part of the pointer to the high byte of BlahBlah, but you can still avoid to monkey with the low byte.

In summary, [BlahBlah,X] is one opcode that could be easily replaced by others, and is here mainly for code optimisation, but [BlahBlah],Y is really a important adressing mode, and you cannot go too far without using it.

Posted: Thu Aug 24, 2006 7:02 am
by tepples
Bregalad wrote:I'm unsure about the name of the adressing mode because they are confusing.
Which is why I usually call them (d,x) and (d),y after how they appear in WDC's 65C816 opcode matrix. (I learned 6502 assembly on an Apple IIGS.)
But you should retain the following :
lda [BlahBlah,X]
Will have the effect to load what is in the pointer found by adding the adress of [BlahBlah] and X, so X helps to determine wich pointer you use.
This instruction is usefull if you have several consecutives pointers in Z-Page RAM. However, you have to manually increment each pointer if they point to a table (wich they are likely to do).
I don't think I have ever used this addressing mode. But last night I brainstormed about places to use this, and then it hit me: it'd be ideal for fetching the pattern bytestream in a music playback engine. Here, the pointers would be stored at base+0, base+4, base+8, base+12, and base+16, for each of the 2A03's five channels.

Posted: Thu Aug 24, 2006 7:16 am
by Bregalad
I use this adressing mode in both music engine I've written so far, but I think it is the only place I used it up now.
This is very usefull for data pointer that come up for each channel.