Help Kodiak64 for FREE!

Click here to read how.

Share this page

Kodiak64 Newsletter

100% free, 100% spam-free!

(You can view a sample here).


NEW in the Kodiak64 Online Shop!

Click to visit Kodiak64 online shop

TXY (6502 wishlist)

Posted on

By Kodiak


Being endlessly in search of faster executing code to keep raster time to a minimum on interrupts, I often wish MOS had made a TXY and a TYX 6502 instruction (maybe they didn't due to hardware issues); without them, we have to do something like this:

LDX ZPVAL ; ZPVAL = a Zero Page value
LDY ZPVAL

That takes 6 cycles and uses 4 bytes, but if we can tolerate the a-reg being written, we can use the illegal opcode LAX, which trims that down to 5 cyles + 3 bytes:

LAX ZPVAL
TAY

Obviously, the big downside (in many coding scenarios) is that the a-register is affected by the LAX operation.

But with a TXY instruction, this would have been:

LDX ZPVAL
TXY

5 cycles, 3 bytes, so the same performance-wise as the LAX solution, but with the a-reg untouched!

Now you might be thinking, is it worth it for 1 measly cycle saved?

Well, if you are serious about keeping a tight eye on saving raster time, then of course it's worth it, especially in a sequential coding situation in which this kind of operation needs to occur repeatedly, in which case the cycles saved with TXY (or conversely, TYX) would be cumulative and could be the difference between a viable effect and abandoning it.

(Besides, I know many if not most experienced coders can't bear to waste a single cycle if it can be avoided!)

Some other similar wishlist entries:

  • LAX in immediate mode (a functional version thereof, that is)
  • LAY (y-index version of LAX)
  • LXY


Interested in coding on the C64? Check out these books on Amazon (and yes, I get a tiny pittance if you buy via any banner below):



____


PS: Don't forget to check the home page regularly for more articles like this and visit the Everything64 Forum to comment further.

And of course, kindly follow me on Twitter and subscribe to my YouTube channel!

Help Kodiak64 for FREE!

Click here to read how.

Share this page

Kodiak64 Newsletter

100% free, 100% spam-free!

(You can view a sample here).