nesdev.com
http://forums.nesdev.com/

Indirect addressing without index possible?
http://forums.nesdev.com/viewtopic.php?f=2&t=15875
Page 1 of 1

Author:  DRW [ Sat Apr 29, 2017 9:13 am ]
Post subject:  Indirect addressing without index possible?

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?

Author:  tepples [ Sat Apr 29, 2017 9:18 am ]
Post subject:  Re: Indirect addressing without index possible?

The other way is to develop for the Lynx (65C02), TurboGrafx-16 (HuC6280), or Super NES (65816) instead.

Author:  DRW [ Sat Apr 29, 2017 9:33 am ]
Post subject:  Re: Indirect addressing without index possible?

So, on 6502, there's no way to shorten this expression?

Author:  Dwedit [ Sat Apr 29, 2017 9:37 am ]
Post subject:  Re: Indirect addressing without index possible?

Pretty much nope. Unless you'd rather use X=0 and use the (nn,X) addressing mode (which is slower) instead.

Author:  DRW [ Sat Apr 29, 2017 9:52 am ]
Post subject:  Re: Indirect addressing without index possible?

Nah, that wouldn't be an alternative.

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

Thanks.

Author:  Garth [ Sat Apr 29, 2017 2:48 pm ]
Post subject:  Re: Indirect addressing without index possible?

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.

Author:  psycopathicteen [ Sat Apr 29, 2017 2:57 pm ]
Post subject:  Re: Indirect addressing without index possible?

Self-modifying code.

Author:  dougeff [ Sat Apr 29, 2017 4:54 pm ]
Post subject:  Re: Indirect addressing without index possible?

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.

Author:  tepples [ Sun Apr 30, 2017 5:22 am ]
Post subject:  Re: Indirect addressing without index possible?

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?

Author:  tokumaru [ Sun Apr 30, 2017 8:16 am ]
Post subject:  Re: Indirect addressing without index possible?

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.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/