blargg wrote:
I get annoyed whenever I encounter people referring to some of the unexpected behaviors of 6502 instructions as bugs (for example, JSR pushing the address of the byte before next instruction). Basically the logic seems to be "This instruction doesn't behave how I want it to. It's a bug!" I'm all for pointing out faults, but these are not faults in the 6502, unless you consider it a fault that it was one tenth the cost and significantly faster than the other chips at the time.
Indeed, the fact that JSR pushes PC+2 instead of PC+3 stems from the fact that the PC is pre-incremented, not post-incremented, when fetching an instruction. Hence, the final +1 occurs on each instruction fetch.
Quote:
- If an interrupt occurs on a BRK instruction, the breakpoint is ignored.
I believe this to be a bug, on the basis that the interrupt should execute first (higher priority), then it should return to the BRK instruction, which is re-executed, thus allowing the BRK to execute.
The bug can expose itself in some circumstances -- for example, using BRK as a breakpoint instruction (one of its uses) -- imagine telling a debugger to single-step, only to have it run the program to completion. Imagine if this happens only periodically and sporadically.
IIRC, 65C02 and 65816 CPUs fixed this.
Quote:
- Undefined op-codes do strange things, some lock up the CPU.
I don't think these were ever documented as bugs, as it's pretty clear this was a cost-cutting measure.
Quote:
- When adding a carry to the MSB of an address, a fetch occurs at a garbage address. The CMOS chips refetch the last byte of the instruction.
This is an artifact of the bus architecture in use. Since the bus interface has no real "valid bus cycle" indication, it must rely on phi2 to perform this action. So, while some internal activity is taking place, you end up with what appears to be sporadic/spurious bus fetches.
The 65816 at least now has a VPA and VDA set of signals, which are properly set to '00'b when performing an internal operation of this sort.
Quote:
- When doing a fetch-modify-store instruction (INC, DEC, ASL, LSR, ROL, ROR) garbage is stored into the location during the "modify" cycle... followed by the "real" store cycle which stores the correct data. The CMOS chips do a second fetch instead of a garbage store.
This *IS* a bug -- consider doing an INC on an I/O port in a heart defribulator (one of the many applications for the 6502 today). Would you like garbage being dumped to an I/O port that could potentially affect your life? 6502s are still used heavily in automotive environments as well, where they control things like air bags and such. Do you want your airbag to glitch out because of some garbage byte stored to an I/O port?
Remember, INCing and DECing an I/O port is a VERY common way to affect a single bit with the minimum number of clock cycles, so in real-time, deeply embedded environments, this IS an issue. A potentially life threatening issue.