Why some processors have unofficial codes and/or bugs?

196 views Asked by At

Lately I am writing (or trying) an emulator for the 6502 NES CPU.

I am learning many many things, some of them really surprise me and I was wondering what's the explanation for those, in particular, two things came to my mind

  1. The existence of bugs, in particular the 6502 seems to have a bug in the indirect addressing mode, at least for the first processors (it affects the one used in the NES)
  2. Unofficial operation codes: Again, really surprising that there are codes not official yet usable, some of them seem to be totally useless (like DOP and TOP which are variations of NOP), and some of them seem to be composition of other operation codes (such SAX or DCP).

The question is, how is it possible that when manufacturing millions of those CPUs, they ended up with bugs (such the indirect addressing mode) and also, why on earth would you as a manufacturer include unofficial operation codes that may be removed in following revisions? Does this happen also with newer CPUs?

1

There are 1 answers

5
Guffa On

1: Sometimes there are bugs even in popular and supposedly well tested processors, like for example the Pentium FDIV bug. Any system that is complex enough to be really useful, has bugs.

2: The existence of undocumented operation codes was mainly to simplify the logic in the operation code identifying process.

If we look for example at the LDY, LDA, LDX and LAX operations (zero page addressing mode), the values for the operation codes are:

operation  hex  binary
-----------------------------
LDY        A4   10100100
LDA        A5   10100101
LDX        A6   10100110
LAX        A7   10100111

If you look at the lower two bits, you see that they were used to specify the target of the operation. 00 means the Y register, 01 means the A register, 10 means the X register, and as 11 has both bits set the data ends up both in the A and X register.