truffly wrote:But why would you ever need to use indexed indirect addressing with the X register? What practical purpose does this serve? There has to be some situation where this feature would prove useful, otherwise I'd assume it wouldn't be featured in the processor design. Have you ever used indexed indirect addressing in your programs? Do you think it is particularly useful, or do you think indirect indexed addressing is a better tool?
(ZP,X) is used all the time in the Forth programming language which uses a data stack in ZP that's separate from the return stack in page 1. Keeping them separate like this solves certain problems in passing stacked data to and from nested subroutines. X is used as the stack pointer. Then suppose you want to read the content of the memory pointed to by the top stack two-byte cell. Regardless of the current depth of the ZP data stack, do
LDA (0,X). (We make X point to the top of the stack, not one position past it like the S register does for the hardware stack.) If you want to read the content of memory pointed to by the second-on-stack two-byte cell, it's
LDA(2,X), again regardless of the current data-stack depth. You may find benefits in doing things this way in assembly language too. This, and tons more, is discussed in detail in my treatise on 6502 stacks (plural, not just the page-1 hardware stack), at
http://wilsonminesco.com/stacks/ .