There was INX and INY, why no INA?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

There was INX and INY, why no INA?

Post by DementedPurple » Thu May 11, 2017 11:46 am

You know how in the 6502 instruction set, you do INX and INY to increment the X and Y registers, but why did you have to do INC A instead of having a different command?

lidnariq
Posts: 8692
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: There was INX and INY, why no INA?

Post by lidnariq » Thu May 11, 2017 11:49 am

Because SEC/ADC #0 isn't that much bigger.

adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Seattle

Re: There was INX and INY, why no INA?

Post by adam_smasher » Thu May 11, 2017 11:56 am

Nothing on a chip comes for free, in terms of cost and space and energy used and heat produced, so CPU designers need to think carefully about what features they include. This was doubly true at the time the 6502 was designed, when integrated circuit technology was nowhere near advanced as it is now and they had far fewer resources available.

So: conceptually, the accumulator A is the place where you do math, and X and Y are index registers for counting and pointing and stuff and the like. Incrementing/decrementing counters and indexes are common enough operations (for things like looping through arrays) that the designers of the 6502 chose to use some silicon on adding instructions to do that. But they figured that you're not doing math in the accumulator that just involves adding 1 all that often, and when you do you can just do ADC #1, so they opted not to include any extra circuitry for an INC A instruction. Now, that's a tiny bit slower and a tiny bit bigger than INC A would be, but the 6502 designers figured it was still a worthwhile trade-off.

Note that later chips in the 65xx family *did* include INC A, because at that point technology had advanced and they had more room on the chip to work with.

User avatar
rainwarrior
Posts: 7636
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: There was INX and INY, why no INA?

Post by rainwarrior » Thu May 11, 2017 12:01 pm

There's a lot of asymmetries in the instruction set. If you look at available addressing modes there's a ton of weird inconsistencies there.

For example, there's an INC abs, X but no INC abs, Y.

As for the "why", it must have seemed cheaper or more convenient to implement the hardware without it. Explaining in more detail that that would require a lot of reverse engineering and speculation, though.

User avatar
tokumaru
Posts: 11438
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: There was INX and INY, why no INA?

Post by tokumaru » Thu May 11, 2017 12:46 pm

If you work with the 6502 long enough you start to get the hang of which instructions exist and which don't, but I for example still have look up the reference to make sure something I need exists when designing complex algorithms. I usually stay on the safe side and assume that not all addressing modes are available for all operations, so when I look up an instruction like ORA I end up being positively surprised.

EDIT: If you're really bothered by the absence of certain opcodes, you can always create macros to simulate them. This will make your source code look more like the way you wanted it to be, but the performance and the final binary will obviously be the same as if you typed out the individual instructions that simulate your invented ones.
Last edited by tokumaru on Thu May 11, 2017 12:50 pm, edited 1 time in total.

Garth
Posts: 148
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: There was INX and INY, why no INA?

Post by Garth » Thu May 11, 2017 12:48 pm

The 65c02 does have INA (plus DEA, PHX, PHY, PLX, PLY, STZ, BRA, BIT#, and other goodies). The original 6502 was designed by hand though, and the masks were laid out by hand, similar to designing a PC board without CAD, which I imagine was largely why the things added later in the 65c02 didn't make it into the original. On 6502.org, we've had a lot of discussions over the years about extra instructions that would be nice. Of course, the 65816 did do a nice job of doing all that while putting up with the requirement that it still be able to execute 6502 code; but otherwise remember that for a given wafer technology, a more-complex instruction set also means more-complex instruction-decoding circuitry, reducing the maximum clock rate. Any possible slowing needed to be more than offset by the benefit of having whatever new instruction is being considered, and how frequently it would be used. I've also wondered about the process to evaluate the usefulness of proposed new instructions. You would kind of have to write a lot of software to see how it works out, but OTOH you wouldn't want to spend a lot of time on something there's no silicon for yet, or even cycle-accurate simulators. Chicken and egg situation.
http://WilsonMinesCo.com/ lots of 6502 resources

psycopathicteen
Posts: 2901
Joined: Wed May 19, 2010 6:12 pm

Re: There was INX and INY, why no INA?

Post by psycopathicteen » Thu May 11, 2017 2:44 pm

What the heck? There's INC. It does the same thing as INA would.

User avatar
tokumaru
Posts: 11438
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: There was INX and INY, why no INA?

Post by tokumaru » Thu May 11, 2017 2:59 pm

INC only works on memory, not on the accumulator.

User avatar
rainwarrior
Posts: 7636
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: There was INX and INY, why no INA?

Post by rainwarrior » Thu May 11, 2017 3:08 pm

tokumaru wrote:INC only works on memory, not on the accumulator.
The 65C02 added an accumulator version of the instruction. (Presuming psycopathicteen is familiar with it via SNES.)

User avatar
tokumaru
Posts: 11438
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: There was INX and INY, why no INA?

Post by tokumaru » Thu May 11, 2017 3:45 pm

Yeah, I was just letting him know that things are different with the 6502.

User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: There was INX and INY, why no INA?

Post by Myask » Thu May 11, 2017 4:31 pm

I always liked how the Minecraft mod Redpower CPU, based on later entries in the 6502 family, implemented STP as "halt and catch fire".

lidnariq
Posts: 8692
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: There was INX and INY, why no INA?

Post by lidnariq » Thu May 11, 2017 4:53 pm

It would be kinda interesting to sit down with the decode ROMs and figure out what novel sensible instructions could have been fit in the same 130x21bit decode ROM

User avatar
pubby
Posts: 536
Joined: Thu Mar 31, 2016 11:15 am

Re: There was INX and INY, why no INA?

Post by pubby » Thu May 11, 2017 7:26 pm

I'd be happy with an ADD/SUB that didn't add the carry. I mean, CMP and AXS exist, so why can't ADD/SUB exist?

User avatar
Hamtaro126
Posts: 763
Joined: Thu Jan 19, 2006 5:08 pm

Re: There was INX and INY, why no INA?

Post by Hamtaro126 » Thu May 11, 2017 9:50 pm

pubby wrote:I'd be happy with an ADD/SUB that didn't add the carry. I mean, CMP and AXS exist, so why can't ADD/SUB exist?

Code: Select all

.macro ADD arg
CLC
ADC #arg
.endmacro

.macro SUB arg
SEC
SBC #arg
.endmacro
AKA SmilyMZX/AtariHacker.

User avatar
tokumaru
Posts: 11438
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: There was INX and INY, why no INA?

Post by tokumaru » Thu May 11, 2017 9:55 pm

That's only one addressing mode though, and offers no speed improvements.

Post Reply