This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Indirect addressing without index possible?

Indirect addressing without index possible?
by on (#194587)
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?
Re: Indirect addressing without index possible?
by on (#194588)
The other way is to develop for the Lynx (65C02), TurboGrafx-16 (HuC6280), or Super NES (65816) instead.
Re: Indirect addressing without index possible?
by on (#194589)
So, on 6502, there's no way to shorten this expression?
Re: Indirect addressing without index possible?
by on (#194590)
Pretty much nope. Unless you'd rather use X=0 and use the (nn,X) addressing mode (which is slower) instead.
Re: Indirect addressing without index possible?
by on (#194592)
Nah, that wouldn't be an alternative.

Alright, looks like I have to keep doing it the old way.

Thanks.
Re: Indirect addressing without index possible?
by on (#194611)
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.
Re: Indirect addressing without index possible?
by on (#194612)
Self-modifying code.
Re: Indirect addressing without index possible?
by on (#194621)
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.
Re: Indirect addressing without index possible?
by on (#194643)
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?
Re: Indirect addressing without index possible?
by on (#194645)
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.