When I use indirect addressing, I usually have a pointer variable and the Y register as an offset index:
Code:
LDA (Pointer), Y
Is there any way to omit the Y register?
I'd like to be able to do something like this:
Code:
LDA (Pointer)
But it tells me it's an illegal addressing mode, so I have to circumvent it with:
Code:
LDY #0
LDA (Pointer), Y
Is this the only way or is there a better way to use indirect addressing without an offset?
The other way is to develop for the Lynx (65C02), TurboGrafx-16 (HuC6280), or Super NES (65816) instead.
So, on 6502, there's no way to shorten this expression?
Pretty much nope. Unless you'd rather use X=0 and use the (nn,X) addressing mode (which is slower) instead.
Nah, that wouldn't be an alternative.
Alright, looks like I have to keep doing it the old way.
Thanks.
The 65c02 (CMOS) has the (ZP) addressing mode (ie, without the indexing); but something you can do for the NMOS 6502, if the code is in RAM instead of ROM, is to do self-modifying code where you make the pointer variable be the operand of the instruction itself. This has the added benefits of speed and of saving precious ZP space.
psycopathicteen is right. You can have a short subroutine in the RAM...
LDA $0000 ;absolute
RTS
To change the pointer, you overwrite the absolute address.
Then, you JSR here to get the value.
But you also have only 2048 bytes of RAM. When is preserving Y worth 4 bytes of RAM and the 12-cycle overhead of a JSR/RTS pair?
Unless you can store the whole subroutine/loop in RAM (so that JSR/RTS aren't executed repeatedly), it's better to just backup Y in ZP, load it with 0, do the indirect access and restore Y, with a total overhead of 8 cycles, instead of 12.