Difference between revisions of "6502"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
(Illegal instructions)
(I/O Access)
 
(288 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[File:MOS 6502AD 4585 top.jpg|right|thumb|250px|The 6502 CPU]]
 
[[File:MOS 6502AD 4585 top.jpg|right|thumb|250px|The 6502 CPU]]
  
The '''MOS Technology 6502''' is an 8-bit microprocessor designed by Chuck Peddle for MOS Technology in 1975. When it was introduced it was the least expensive full featured CPU on the market by far, at about 1/6th the price, or less, of competing designs from larger companies such as Motorola and Intel. It was nevertheless faster than most of them, and, along with the [[Zilog]] [[Z80]], sparked off a series of computer projects that would eventually result in the home computer revolution of the 1980s. The 6502 design was originally second-sourced by Rockwell and Synertek and later licensed to a number of companies; it is still made for embedded systems.
+
The '''MOS Technology 6502''' is an 8-bit microprocessor designed by Chuck Peddle in 1975 for MOS Technology (later purchased by Commodore). Along with the [[Zilog]] [[Z80]], it sparked off a series of computer projects that would eventually result in the home computer revolution of the 1980s. The 6502 design was originally second-sourced by Rockwell and Synertek and later licensed to a number of companies; it is still made for embedded systems.
  
 
Originally the CPC was destined to be designed around the 6502 processor. But when Amstrad approached [[Locomotive Software]] to develop a Basic for it with a very tight deadline, Locomotive PLC, who already had a Z80 Basic in the works, urged and convinced Amstrad to switch to the Z80.
 
Originally the CPC was destined to be designed around the 6502 processor. But when Amstrad approached [[Locomotive Software]] to develop a Basic for it with a very tight deadline, Locomotive PLC, who already had a Z80 Basic in the works, urged and convinced Amstrad to switch to the Z80.
 +
 +
<br>
 +
 +
== History ==
 +
 +
In 1973, Peddle worked at Motorola on developing the 6800 processor. Peddle recognized a market for a very low price microprocessor and began to champion such a design to complement the Motorola 6800. His efforts were frustrated by Motorola management and he was told to drop the project. He then left for MOS Technology, where he headed the design of the 6501.
 +
 +
The 6501 was pin-compatible with the 6800, meaning it could be used in the same systems without any changes. However, this led to legal trouble with Motorola, who argued that the 6501 infringed on their patents.
 +
 +
To resolve this, MOS Technology stopped producing the 6501 and introduced the 6502. While the 6502 was similar in design to the 6501 and 6800, it was no longer pin-compatible with the 6800, avoiding further legal issues.
 +
 +
Importantly, the 6502 had a much lower price point, which made it highly attractive to electronics manufacturers. Priced initially at just $25, the 6502 drastically undercut the Motorola 6800 and other competing processors like the Intel 8080, which were priced around $179 at the time. Motorola must have learnt from this lesson when they decided to sell the 68000 at $15 to Apple for the Macintosh in 1984.
  
 
<br>
 
<br>
Line 9: Line 21:
 
== Description ==
 
== Description ==
  
The 6502 microprocessor is an 8-bit CPU with an 8-bit ALU and a 16-bit address bus capable of direct access to 64KB of memory space. Like the Z80, the 6502 is also a little-endian CPU, meaning it stores 16-bit values with the least significant byte first, followed by the most significant byte. The 6502 has 151 instructions, which are composed of 56 distinct opcodes across various addressing modes.
+
The 6502 microprocessor is an 8-bit CPU with an 8-bit ALU and a 16-bit address bus capable of direct access to 64KB of memory space.
 +
 
 +
Like the Z80, the 6502 is a little-endian CPU, meaning it reads 16-bit values with the least significant byte first, followed by the most significant byte. The 6502 has 151 instructions, which are composed of 56 distinct opcodes across various addressing modes.
 +
 
 +
The 6502 is an 8-bit CPU in the purest sense. Unlike the Z80, the 6502 does not have any 16-bit instructions and cannot pair its registers. To work with a 16-bit number you will need to split it in two and work with each half individually.
  
 
Although it lacks the raw processing power of processors like the Intel 80x86 or the Motorola 68000 series, the 6502 was known for its efficiency and affordability, making it a popular choice for embedded systems and early home computers. Its simple design contributed to lower manufacturing costs and simplified integration.
 
Although it lacks the raw processing power of processors like the Intel 80x86 or the Motorola 68000 series, the 6502 was known for its efficiency and affordability, making it a popular choice for embedded systems and early home computers. Its simple design contributed to lower manufacturing costs and simplified integration.
  
The 6502 chip is made up of 4528 transistors (3510 enhancement transistors and 1018 depletion pullup transistors). It comes in a 40-pin DIP package. It has been produced by various manufacturers and used in a wide range of applications, from early gaming consoles like the [[Atari 2600|Atari VCS]] and [[Nintendo Entertainment System]] to personal computers like the [[Apple II]] and [[Commodore 64]].
+
The 6502 chip is made up of 4528 transistors (3510 enhancement transistors and 1018 depletion pullup transistors).
 +
To put it into perspective, 64KB of DRAM contains 524288 transistors, as 1 bit of DRAM needs 1 transistor. The 6502 is mid-1970s technology while the 64KB DRAM is early-1980s technology.
 +
 
 +
Despite having so few transistors, the 6502 is generally considered at least twice as fast as the Z80 for the same clock speed [https://www.cpcwiki.eu/forum/amstrad-cpc-hardware/the-cpc-revision-zero-article/msg243843/ Source]. Three reasons explain this:
 +
* The 6502 has an 8-bit ALU, while the Z80 uses a 4-bit ALU.
 +
* The 6502 features a built-in clock doubler, allowing it to perform 1 internal operation and 1 memory access per cycle.
 +
* On average, a 2MHz 6502 can make 2 memory accesses per microsecond, while a 4MHz Z80 can only make 1.
 +
 
 +
This shows the design differences between the 6502 and Z80. The 6502 focused on efficiency, using its limited transistor budget for the ALU and fast memory access. In contrast, the Z80 neglected these and used more transistors for extra registers and complex instructions. However, these Z80's features, like the alternate register set, register pairs and 16-bit stack, make it easier to develop complex software.
 +
 
 +
The 6502 comes in a 40-pin DIP package. It has been produced by various manufacturers and used in a wide range of applications, from gaming consoles like the [[Atari 2600|Atari VCS]], [[Atari Lynx]], [[Nintendo Entertainment System]] and [[PC-Engine]] to personal computers like the [[Apple II]], [[BBC Micro]], [[Atari XL]], [[Oric]], [[VIC20]] and [[Commodore 64]].
  
 
<br>
 
<br>
Line 29: Line 55:
 
|-
 
|-
 
| P (Processor Status) || 8-bit ||  
 
| P (Processor Status) || 8-bit ||  
* bit7 - NF - Negative Flag
+
* bit7 - NF - Negative Flag: 1 when result is negative
* bit6 - VF - Overflow Flag
+
* bit6 - VF - Overflow Flag: 1 on signed overflow
* bit5 - Unused (always set to 1)
+
* bit5 - Unused: always set to 1
* bit4 - BF - Break Command
+
* bit4 - BF - Break Flag: 1 when pushed by instructions (BRK / PHP) and 0 when pushed by interrupts (NMI / IRQ)
* bit3 - DF - Decimal Mode Flag
+
* bit3 - DF - Decimal Mode Flag: 1 when CPU is in Decimal Mode
* bit2 - IF - Interrupt Disable Flag
+
* bit2 - IF - Interrupt Disable Flag: when 1, no interrupt will occur (except BRK and NMI)
* bit1 - ZF - Zero Flag
+
* bit1 - ZF - Zero Flag: 1 when all bits of a result are 0
* bit0 - CF - Carry Flag
+
* bit0 - CF - Carry Flag: 1 on unsigned overflow
|| The status register is modified by arithmetic and logic operations, as well as interrupts
+
|| Flags are affected by most operations.
 +
BF is not a physical flag implemented in a register. It only appears on the stack when the P register is pushed to it.
 +
 
 +
PHP (Push Processor Status) and PLP (Pull Processor Status) can be used to set or retrieve P directly via the stack.
 +
 
 +
Interrupts (BRK / NMI / IRQ) implicitly push P to the stack. Interrupts returning with RTI will implicitly pull P from the stack.
 +
 
 +
The effect of toggling the IF flag is delayed by 1 instruction when caused by SEI, CLI, or PLP.
 
|-
 
|-
| S (Stack Pointer) || 8-bit || Points to the current location in the stack || Stack is located in page 1 ($0100-$01FF), 8-bit S is offset to this base
+
| S (Stack Pointer) || 8-bit || Points to the current location in the stack || Stack is located in page 1 ($0100-$01FF), 8-bit S register is offset to this base
 
|-
 
|-
 
| PC (Program Counter) || 16-bit || Points to the next instruction to be executed || Automatically increments as instructions are executed
 
| PC (Program Counter) || 16-bit || Points to the next instruction to be executed || Automatically increments as instructions are executed
Line 46: Line 79:
 
<br>
 
<br>
  
== 6502 Instruction set ==
+
== Memory Access ==
  
=== Standard instructions ===
+
The address space that the 6502 uses is split into pages. There are 256 pages and each page is 256 bytes in size, ranging from page 0 to page 255.
 +
 
 +
In order to make up for the lack of registers, the 6502 includes a zero page addressing mode ($0000-$00FF) that uses only 1 address byte in the instruction instead of the 2 that are needed to address the full 64 KB of memory. This provides fast access to the first 256 bytes of RAM by using shorter instructions.
 +
 
 +
The stack is permanently located in page 1 ($0100-$01FF) and managed by the 8-bit stack pointer (S), with an initial value of $FF. It grows downward as data is pushed onto the stack. The stack has a 256-byte limit, and overflow occurs if not managed properly.
 +
 
 +
Instructions PHA and PHP push the accumulator and processor status onto the stack, while PLA and PLP pull them back. Subroutine calls with JSR store the return address on the stack, and RTS retrieves it to continue execution. Similarly, interrupts (BRK) push the program counter and status, while RTI restores them.
 +
 
 +
<br>
 +
 
 +
== I/O Access ==
 +
 
 +
All I/O operations are memory-mapped. There are no port-based I/O instructions. Memory-mapped ports often have different properties than normal RAM:
 +
 
 +
* The contents of a port can be updated by the hardware. Reading a port will not always return the same value each time it is read
 +
 
 +
* It is also possible that reading a port will alter its contents, or alter the contents of other related ports
 +
 
 +
* A read-only port is what it sounds like. Attempting to write to this address will not affect the contents
 +
 
 +
* A write-only port can be written to, but reading it will result in undefined behaviour
 +
 
 +
* Using the ports with instructions other than the Load/Store ones can be very unintuitive
 +
 
 +
This is not all negative though. Memory-mapped I/O means that:
 +
 
 +
* The familiar instructions for accessing memory can be used for I/O, instead of learning a new set of instructions
 +
 
 +
* No need to learn the weird partial I/O address decoding rules
 +
 
 +
* Chips are directly accessible instead of being chained, like how the [[PSG|PSG chip]] has to be clumsily accessed through the [[8255|PPI chip]]
 +
 
 +
<br>
 +
 
 +
== Interrupts ==
 +
 
 +
6502 machines use the last 6 bytes of their address space to hold a vector table containing (in order) the addresses of the NMI routine, the program's start, and the IRQ routine.
 +
 
 +
On a RESET, the CPU loads the vector from $FFFC/$FFFD into the program counter and continues fetching instructions from there.
 +
 
 +
On an NMI, the CPU pushes the low byte and the high byte of the program counter as well as the processor status onto the stack, disables interrupts and loads the vector from $FFFA/$FFFB into the program counter and continues fetching instructions from there.
 +
 
 +
On an IRQ, the CPU does the same as in the NMI case, but uses the vector at $FFFE/$FFFF.
 +
 
 +
On a BRK instruction, the CPU does the same as in the IRQ case, but sets BF in the copy of the status register that is saved on the stack.
 +
 
 +
The priority sequence for interrupts, from top priority to bottom, is as follows: RESET, BRK, NMI, IRQ. [https://www.westerndesigncenter.com/wdc/documentation/w65c816s.pdf Source at chapter 7.19]
 +
 
 +
<br>
 +
 
 +
=== Interrupt hijacking ===
 +
 
 +
On NMOS, if NMI is asserted during the first 4 ticks of a BRK instruction, the BRK instruction will execute normally at first (PC increments will occur and P will be pushed with BF set to 1), but execution will branch to the NMI vector instead of the IRQ/BRK vector, effectively skipping the BRK instruction. On CMOS, this situation is correctly handled by executing BRK and then servicing the interrupt.
 +
 
 +
An IRQ can also hijack a BRK, though it won't be as visible since they use the same interrupt vector.
 +
 
 +
Similarly, an NMI can hijack an IRQ. But this is not usually a problem because the IRQ will normally still be asserted when the NMI returns and generate a new interrupt.
 +
 
 +
<br>
 +
 
 +
=== Branch instructions and Interrupts ===
 +
 
 +
The branch instructions have subtle interrupt polling behaviour. When executing a branch instruction, the 6502 checks for interrupts before fetching the operand (cycle 2).
 +
 
 +
If the branch is taken (i.e., the CPU decides to jump), it does not check for interrupts again before proceeding unless the branch crosses a page boundary (like moving from memory address $01FF to $0200).
 +
 
 +
If the branch crosses a page boundary, the CPU checks for interrupts once more before fixing the program counter.
 +
 
 +
If an interrupt is detected at any of these points (before the operand fetch or the page boundary fixup), the CPU will handle the interrupt immediately, interrupting the branch execution.
 +
 
 +
This behaviour has not been fixed in the CMOS 65C02 as this is not really a bug. It's just a subtlety that one has to keep in mind when working with time-sensitive code.
 +
 
 +
<br>
 +
 
 +
== Decimal Mode ==
 +
 
 +
BCD operations are limited to addition and subtraction using the ADC and SBC instructions.
 +
 
 +
On NMOS, when Decimal Mode is on, the ADC and SBC instructions update NF, VF and ZF based on the binary result before the decimal correction is applied. Only CF is updated correctly. On CMOS, all the flags are updated correctly, at the cost of 1 additional cycle.
 +
 
 +
On NMOS, DF is not defined after RESET. On CMOS, DF is automatically cleared on RESET.
 +
 
 +
On NMOS, DF is unchanged when entering an interrupt of any kind. This can cause unexpected bugs in the interrupt handler if Decimal Mode is on when an interrupt occurs. On CMOS, DF is automatically cleared on interrupt. Upon returning from an interrupt, the processor restores the status register from the stack, including DF.
 +
 
 +
<br>
 +
 
 +
== Half Cycles ==
 +
 
 +
The 6502 divides each clock cycle into two phases (ϕ1 and ϕ2):
 +
* During the ϕ1 half-cycle, no bus access occurs. This phase is dedicated to internal CPU operations.
 +
* During the ϕ2 half-cycle, the CPU accesses the external bus for memory reads/writes or I/O operations.
 +
 
 +
The use of half-cycles ensures that memory and I/O devices have predictable timing windows when the CPU will access the bus, while still allowing the CPU to perform internal operations in parallel.
 +
 
 +
Unlike most microprocessors, the 6502 does not make memory accesses on an "as needed" basis. It always does a fetch or store on every single clock cycle. When there isn't anything to be fetched or stored, a "garbage" fetch or store occurs. This is mainly of importance with the memory-mapped I/O devices:
 +
* On NMOS, when adding a carry to the MSB of an address, a fetch occurs at a garbage address. On CMOS, the last byte of the instruction is refetched.
 +
* On NMOS, 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. On CMOS, a second fetch is performed instead of a garbage store.
 +
 
 +
<br>
 +
 
 +
== Pipelining ==
 +
 
 +
The 6502 CPU uses some sort of pipelining. If an instruction does not store data in memory on its last cycle, the processor can fetch the opcode of the next instruction while executing the last cycle. This is very primitive as the 6502 does not have an instruction cache nor even a prefetch queue. It relies on RAM to hold all program information.
 +
 
 +
As an example, the instruction EOR #$FF truly takes 3 cycles:
 +
* On the first cycle, the opcode $49 will be fetched
 +
* During the second cycle the processor decodes the opcode and fetches the parameter #$FF
 +
* On the third cycle, the processor will perform the operation and store the result in register A, but simultaneously it fetches the opcode for the next instruction
 +
 
 +
This is why the EOR instruction effectively takes only 2 cycles.
 +
 
 +
However, this pipelining only makes sense when looking at full cycles. If we break it down into half-cycles, there's no actual overlap. In fact, it's the other way around. If the previous instruction ends with a memory write, the CPU has to wait for a half-cycle before fetching the next instruction on the next ϕ2 half-cycle.
 +
 
 +
<br>
 +
 
 +
== Adressing Modes ==
  
 
{| class="wikitable"
 
{| class="wikitable"
 +
! Addressing Mode !! Example !! Operation
 
|-
 
|-
! rowspan=2|Mnemonic !! colspan=13|Addressing Modes !! colspan=8|Flags !! rowspan=2|Operation !! rowspan=2|Description
+
| Immediate || LDA #$EA || A ← $EA
 
|-
 
|-
! ''No arg'' !! A !! #$nn !! $nnnn !! $nnnn,X !! $nnnn,Y !! ($nnnn) !! $nn !! $nn,X !! $nn,Y !! ($nn,X) !! ($nn),Y !! rel !! N !! V !! - !! B !! D !! I !! Z !! C
+
| Absolute || LDA $0314 || A ← M($0314)
 
|-
 
|-
| ADC || || || 69 || 6D || 7D || 79 || || 65 || 75 || || 61 || 71 || || N || V || - || - || - || - || Z || C || A + M + CF → A, CF || Add Memory to Accumulator with Carry
+
| Absolute,X || LDA $0314,X || A M($0314+X)
 
|-
 
|-
| AND || || || 29 || 2D || 3D || 39 || || 25 || 35 || || 21 || 31 || || N || - || - || - || - || - || Z || - || A M → A || "AND" Memory with Accumulator
+
| Absolute,Y || LDA $0314,Y || A M($0314+Y)
 
|-
 
|-
| ASL || || 0A || || 0E || 1E || || || 06 || 16 || || || || || N || - || - || - || - || - || Z || C || CF /M<sub>7</sub>...M<sub>0</sub>/ ← 0 || Arithmetic Shift Left
+
| Zeropage || LDA $02 || A ← M($02)
 
|-
 
|-
| BCC || || || || || || || || || || || || || 90 || - || - || - || - || - || - || - || - || Branch on CF = 0 || Branch on Carry Clear
+
| Zeropage,X || LDA $02,X || A ← M($02+X)
 
|-
 
|-
| BCS || || || || || || || || || || || || || B0 || - || - || - || - || - || - || - || - || Branch on CF = 1 || Branch on Carry Set
+
| Zeropage,Y || LDA $02,Y || A ← M($02+Y)
 
|-
 
|-
| BEQ || || || || || || || || || || || || || F0 || - || - || - || - || - || - || - || - || Branch on ZF = 1 || Branch on Result Zero
+
| (Zeropage,X) || LDA ($02,X) || A ← M(PTR($02+X))
 
|-
 
|-
| BIT || || || || 2C || || || || 24 || || || || || || N || V || - || - || - || - || Z || - || A ∧ M, M<sub>7</sub> → NF, M<sub>6</sub> → VF || Test Bits in Memory with Accumulator
+
| (Zeropage),Y || LDA ($02),Y || A M(PTR($02)+Y)
 +
|}
 +
 
 +
<br>
 +
 
 +
== NMOS 6502 Instruction Set ==
 +
 
 +
=== Standard instructions ===
 +
 
 +
Cycles are shown in parenthesis for each opcode. p=1 if page is crossed. t=1 if branch is taken.
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
| BMI || || || || || || || || || || || || || 30 || - || - || - || - || - || - || - || - || Branch on NF = 1 || Branch on Result Minus
+
! rowspan=2|Mnemonic !! colspan=13|Addressing Modes !! colspan=7|Flags !! rowspan=2|Operation !! rowspan=2|Description
 
|-
 
|-
| BNE || || || || || || || || || || || || || D0 || - || - || - || - || - || - || - || - || Branch on ZF = 0 || Branch on Result Not Zero
+
! ''No arg'' !! A !! #$nn !! $nnnn !! $nnnn,X !! $nnnn,Y !! ($nnnn) !! $nn !! $nn,X !! $nn,Y !! ($nn,X) !! ($nn),Y !! rel !! N !! V !! B !! D !! I !! Z !! C
 
|-
 
|-
| BPL || || || || || || || || || || || || || 10 || - || - || - || - || - || - || - || - || Branch on NF = 0 || Branch on Result Plus
+
| ADC || || || 69 (2) || 6D (4) || 7D (4+p) || 79 (4+p) || || 65 (3) || 75 (4) || || 61 (6) || 71 (5+p) || || N || V || - || - || - || Z || C || A + M + CF → A, CF || Add Memory to Accumulator with Carry
 
|-
 
|-
| BRK || 00 || || || || || || || || || || || || || - || - || - || - || - || 1 || - || - || PC + 2↓, [FFFE] → PCL, [FFFF] PCH || Break Command
+
| AND || || || 29 (2) || 2D (4) || 3D (4+p) || 39 (4+p) || || 25 (3) || 35 (4) || || 21 (6) || 31 (5+p) || || N || - || - || - || - || Z || - || A ∧ M A || "AND" Memory with Accumulator
 
|-
 
|-
| BVC || || || || || || || || || || || || || 50 || - || - || - || - || - || - || - || - || Branch on VF = 0 || Branch on Overflow Clear
+
| ASL || || 0A (2) || || 0E (6) || 1E (7) || || || 06 (5) || 16 (6) || || || || || N || - || - || - || - || Z || C || CF ← /M<sub>7</sub>...M<sub>0</sub>/ ← 0 || Arithmetic Shift Left
 
|-
 
|-
| BVS || || || || || || || || || || || || || 70 || - || - || - || - || - || - || - || - || Branch on VF = 1 || Branch on Overflow Set
+
| BCC || || || || || || || || || || || || || 90 (2+t+p) || - || - || - || - || - || - || - || Branch on CF = 0 || Branch on Carry Clear
 
|-
 
|-
| CLC || 18 || || || || || || || || || || || || || - || - || - || - || - || - || - || 0 || 0 → CF || Clear Carry Flag
+
| BCS || || || || || || || || || || || || || B0 (2+t+p) || - || - || - || - || - || - || - || Branch on CF = 1 || Branch on Carry Set
 
|-
 
|-
| CLD || D8 || || || || || || || || || || || || || - || - || - || - || 0 || - || - || - || 0 → DF || Clear Decimal Mode
+
| BEQ || || || || || || || || || || || || || F0 (2+t+p) || - || - || - || - || - || - || - || Branch on ZF = 1 || Branch on Result Zero
 
|-
 
|-
| CLI || 58 || || || || || || || || || || || || || - || - || - || - || - || 0 || - || - || 0 IF || Clear Interrupt Disable
+
| BIT || || || || 2C (4) || || || || 24 (3) || || || || || || N || V || - || - || - || Z || - || A ∧ M, M<sub>7</sub> → NF, M<sub>6</sub> VF || Test Bits in Memory with Accumulator
 
|-
 
|-
| CLV || B8 || || || || || || || || || || || || || - || 0 || - || - || - || - || - || - || 0 → VF || Clear Overflow Flag
+
| BMI || || || || || || || || || || || || || 30 (2+t+p) || - || - || - || - || - || - || - || Branch on NF = 1 || Branch on Result Minus
 
|-
 
|-
| CMP || || || C9 || CD || DD || D9 || || C5 || D5 || || C1 || D1 || || N || - || - || - || - || - || Z || C || A - M || Compare Memory and Accumulator
+
| BNE || || || || || || || || || || || || || D0 (2+t+p) || - || - || - || - || - || - || - || Branch on ZF = 0 || Branch on Result Not Zero
 
|-
 
|-
| CPX || || || E0 || EC || || || || E4 || || || || || || N || - || - || - || - || - || Z || C || X - M || Compare Index Register X To Memory
+
| BPL || || || || || || || || || || || || || 10 (2+t+p) || - || - || - || - || - || - || - || Branch on NF = 0 || Branch on Result Plus
 
|-
 
|-
| CPY || || || C0 || CC || || || || C4 || || || || || || N || - || - || - || - || - || Z || C || Y - M || Compare Index Register Y To Memory
+
| BRK || 00 (7) || || || || || || || || || || || || || - || - || 1 || - || 1 || - || - || PC + 2↓, [FFFE] → PCL, [FFFF] → PCH || Force Interrupt
 
|-
 
|-
| DEC || || || || CE || DE || || || C6 || D6 || || || || || N || - || - || - || - || - || Z || - || M - 1 → M || Decrement Memory By One
+
| BVC || || || || || || || || || || || || || 50 (2+t+p) || - || - || - || - || - || - || - || Branch on VF = 0 || Branch on Overflow Clear
 
|-
 
|-
| DEX || CA || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || X - 1 → X || Decrement Index Register X By One
+
| BVS || || || || || || || || || || || || || 70 (2+t+p) || - || - || - || - || - || - || - || Branch on VF = 1 || Branch on Overflow Set
 
|-
 
|-
| DEY || 88 || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || Y - 1 Y || Decrement Index Register Y By One
+
| CLC || 18 (2) || || || || || || || || || || || || || - || - || - || - || - || - || 0 || 0 CF || Clear Carry Flag
 
|-
 
|-
| EOR || || || 49 || 4D || 5D || 59 || || 45 || 55 || || 41 || 51 || || N || - || - || - || - || - || Z || - || A ⊻ M A || "Exclusive OR" Memory with Accumulator
+
| CLD || D8 (2) || || || || || || || || || || || || || - || - || - || 0 || - || - || - || 0 DF || Clear Decimal Mode
 
|-
 
|-
| INC || || || || EE || FE || || || E6 || F6 || || || || || N || - || - || - || - || - || Z || - || M + 1 M || Increment Memory By One
+
| CLI || 58 (2) || || || || || || || || || || || || || - || - || - || - || 0 || - || - || 0 IF || Clear Interrupt Disable
 
|-
 
|-
| INX || E8 || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || X + 1 X || Increment Index Register X By One
+
| CLV || B8 (2) || || || || || || || || || || || || || - || 0 || - || - || - || - || - || 0 VF || Clear Overflow Flag
 
|-
 
|-
| INY || C8 || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || Y + 1 → Y || Increment Index Register Y By One
+
| CMP || || || C9 (2) || CD (4) || DD (4+p) || D9 (4+p) || || C5 (3) || D5 (4) || || C1 (6) || D1 (5+p) || || N || - || - || - || - || Z || C || A - M || Compare Memory and Accumulator
 
|-
 
|-
| JMP || || || || 4C || || || 6C || || || || || || || - || - || - || - || - || - || - || - || [PC + 1] → PCL, [PC + 2] → PCH || JMP Indirect
+
| CPX || || || E0 (2) || EC (4) || || || || E4 (3) || || || || || || N || - || - || - || - || Z || C || X - M || Compare Index Register X To Memory
 
|-
 
|-
| JSR || || || || 20 || || || || || || || || || || - || - || - || - || - || - || - || - || PC + 2↓, [PC + 1] → PCL, [PC + 2] → PCH || Jump To Subroutine
+
| CPY || || || C0 (2) || CC (4) || || || || C4 (3) || || || || || || N || - || - || - || - || Z || C || Y - M || Compare Index Register Y To Memory
 
|-
 
|-
| LDA || || || A9 || AD || BD || B9 || || A5 || B5 || || A1 || B1 || || N || - || - || - || - || - || Z || - || M → A || Load Accumulator with Memory
+
| DEC || || || || CE (6) || DE (7) || || || C6 (5) || D6 (6) || || || || || N || - || - || - || - || Z || - || M - 1 M || Decrement Memory By One
 
|-
 
|-
| LDX || || || A2 || AE || || BE || || A6 || || B6 || || || || N || - || - || - || - || - || Z || - || M → X || Load Index Register X From Memory
+
| DEX || CA (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || X - 1 → X || Decrement Index Register X By One
 
|-
 
|-
| LDY || || || A0 || AC || BC || || || A4 || B4 || || || || || N || - || - || - || - || - || Z || - || M → Y || Load Index Register Y From Memory
+
| DEY || 88 (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || Y - 1 → Y || Decrement Index Register Y By One
 
|-
 
|-
| LSR || || 4A || || 4E || 5E || || || 46 || 56 || || || || || 0 || - || - || - || - || - || Z || C || 0 → /M<sub>7</sub>...M<sub>0</sub>/ CF || Logical Shift Right
+
| EOR || || || 49 (2) || 4D (4) || 5D (4+p) || 59 (4+p) || || 45 (3) || 55 (4) || || 41 (6) || 51 (5+p) || || N || - || - || - || - || Z || - || A ⊻ M → A || "Exclusive OR" Memory with Accumulator
 
|-
 
|-
| NOP || EA || || || || || || || || || || || || || - || - || - || - || - || - || - || - || No operation || No Operation
+
| INC || || || || EE (6) || FE (7) || || || E6 (5) || F6 (6) || || || || || N || - || - || - || - || Z || - || M + 1 → M || Increment Memory By One
 
|-
 
|-
| ORA || || || 09 || 0D || 1D || 19 || || 05 || 15 || || 01 || 11 || || N || - || - || - || - || - || Z || - || A ∨ M A || "OR" Memory with Accumulator
+
| INX || E8 (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || X + 1 X || Increment Index Register X By One
 
|-
 
|-
| PHA || 48 || || || || || || || || || || || || || - || - || - || - || - || - || - || - || A↓ || Push Accumulator On Stack
+
| INY || C8 (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || Y + 1 → Y || Increment Index Register Y By One
 
|-
 
|-
| PHP || 08 || || || || || || || || || || || || || - || - || - || 1 || - || - || - || - || P↓ || Push Processor Status on Stack
+
| JMP || || || || 4C (3) || || || 6C (5) || || || || || || || - || - || - || - || - || - || - || [PC + 1] → PCL, [PC + 2] → PCH || Jump
 
|-
 
|-
| PLA || 68 || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || (S)↑ A || Pull Accumulator From Stack
+
| JSR || || || || 20 (6) || || || || || || || || || || - || - || - || - || - || - || - || PC + 2↓, [PC + 1] → PCL, [PC + 2] PCH || Jump To Subroutine
 
|-
 
|-
| PLP || 28 || || || || || || || || || || || || || N || V || - || B || D || I || Z || C || (S)↑ P || Pull Processor Status From Stack
+
| LDA || || || A9 (2) || AD (4) || BD (4+p) || B9 (4+p) || || A5 (3) || B5 (4) || || A1 (6) || B1 (5+p) || || N || - || - || - || - || Z || - || M A || Load Accumulator with Memory
 
|-
 
|-
| ROL || || 2A || || 2E || 3E || || || 26 || 36 || || || || || N || - || - || - || - || - || Z || C || CF ← /M<sub>7</sub>...M<sub>0</sub>/ ← CF || Rotate One Bit Left (Memory or Accumulator)
+
| LDX || || || A2 (2) || AE (4) || || BE (4+p) || || A6 (3) || || B6 (4) || || || || N || - || - || - || - || Z || - || M → X || Load Index Register X From Memory
 
|-
 
|-
| ROR || || 6A || || 6E || 7E || || || 66 || 76 || || || || || N || - || - || - || - || - || Z || C || CF → /M<sub>7</sub>...M<sub>0</sub>/ CF || Rotate One Bit Right (Memory or Accumulator)
+
| LDY || || || A0 (2) || AC (4) || BC (4+p) || || || A4 (3) || B4 (4) || || || || || N || - || - || - || - || Z || - || M → Y || Load Index Register Y From Memory
 
|-
 
|-
| RTI || 40 || || || || || || || || || || || || || N || V || - || B || D || I || Z || C || (S)↑ P, (S)↑ → PCL, (S)↑ PCH || Return From Interrupt
+
| LSR || || 4A (2) || || 4E (6) || 5E (7) || || || 46 (5) || 56 (6) || || || || || 0 || - || - || - || - || Z || C || 0 /M<sub>7</sub>...M<sub>0</sub>/ CF || Logical Shift Right
 
|-
 
|-
| RTS || 60 || || || || || || || || || || || || || - || - || - || - || - || - || - || - || (S)↑ → PCL, (S)↑ → PCH, PC + 1 → PC || Return From Subroutine
+
| NOP || EA (2) || || || || || || || || || || || || || - || - || - || - || - || - || - || No operation || No Operation
 
|-
 
|-
| SBC || || || E9 || ED || FD || F9 || || E5 || F5 || || E1 || F1 || || N || V || - || - || - || - || Z || C || A - M - (1 - CF) → A || Subtract Memory from Accumulator with Borrow
+
| ORA || || || 09 (2) || 0D (4) || 1D (4+p) || 19 (4+p) || || 05 (3) || 15 (4) || || 01 (6) || 11 (5+p) || || N || - || - || - || - || Z || - || A M → A || "OR" Memory with Accumulator
 
|-
 
|-
| SEC || 38 || || || || || || || || || || || || || - || - || - || - || - || - || - || 1 || 1 → CF || Set Carry Flag
+
| PHA || 48 (3) || || || || || || || || || || || || || - || - || - || - || - || - || - || A↓ || Push Accumulator On Stack
 
|-
 
|-
| SED || F8 || || || || || || || || || || || || || - || - || - || - || 1 || - || - || - || 1 → DF || Set Decimal Mode
+
| PHP || 08 (3) || || || || || || || || || || || || || - || - || 1 || - || - || - || - || P↓ || Push Processor Status on Stack
 
|-
 
|-
| SEI || 78 || || || || || || || || || || || || || - || - || - || - || - || 1 || - || - || 1 IF || Set Interrupt Disable
+
| PLA || 68 (4) || || || || || || || || || || || || || N || - || - || - || - || Z || - || (S)↑ A || Pull Accumulator From Stack
 
|-
 
|-
| STA || || || || 8D || 9D || 99 || || 85 || 95 || || 81 || 91 || || - || - || - || - || - || - || - || - || A M || Store Accumulator in Memory
+
| PLP || 28 (4) || || || || || || || || || || || || || N || V || - || D || I || Z || C || (S)↑ P || Pull Processor Status From Stack
 
|-
 
|-
| STX || || || || 8E || || || || 86 || || 96 || || || || - || - || - || - || - || - || - || - || X → M || Store Index X in Memory
+
| ROL || || 2A (2) || || 2E (6) || 3E (7) || || || 26 (5) || 36 (6) || || || || || N || - || - || - || - || Z || C || CF ← /M<sub>7</sub>...M<sub>0</sub>/ ← CF || Rotate One Bit Left (Memory or Accumulator)
 
|-
 
|-
| STY || || || || 8C || || || || 84 || 94 || || || || || - || - || - || - || - || - || - || - || Y → M || Store Index Y in Memory
+
| ROR || || 6A (2) || || 6E (6) || 7E (7) || || || 66 (5) || 76 (6) || || || || || N || - || - || - || - || Z || C || CF /M<sub>7</sub>...M<sub>0</sub>/ → CF || Rotate One Bit Right (Memory or Accumulator)
 
|-
 
|-
| TAX || AA || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || A X || Transfer Accumulator to Index X
+
| RTI || 40 (6) || || || || || || || || || || || || || N || V || - || D || I || Z || C || (S)↑ → P, (S)↑ → PCL, (S)↑ PCH || Return From Interrupt
 
|-
 
|-
| TAY || A8 || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || A Y || Transfer Accumulator to Index Y
+
| RTS || 60 (6) || || || || || || || || || || || || || - || - || - || - || - || - || - || (S)↑ → PCL, (S)↑ → PCH, PC + 1 PC || Return From Subroutine
 
|-
 
|-
| TSX || BA || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || S X || Transfer Stack Pointer to Index X
+
| SBC || || || E9 (2) || ED (4) || FD (4+p) || F9 (4+p) || || E5 (3) || F5 (4) || || E1 (6) || F1 (5+p) || || N || V || - || - || - || Z || C || A - M - (1 - CF) A || Subtract Memory from Accumulator with Borrow
 
|-
 
|-
| TXA || 8A || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || X A || Transfer Index X to Accumulator
+
| SEC || 38 (2) || || || || || || || || || || || || || - || - || - || - || - || - || 1 || 1 CF || Set Carry Flag
 
|-
 
|-
| TXS || 9A || || || || || || || || || || || || || - || - || - || - || - || - || - || - || X S || Transfer Index X to Stack Pointer
+
| SED || F8 (2) || || || || || || || || || || || || || - || - || - || 1 || - || - || - || 1 DF || Set Decimal Mode
 
|-
 
|-
| TYA || 98 || || || || || || || || || || || || || N || - || - || - || - || - || Z || - || Y → A || Transfer Index Y to Accumulator
+
| SEI || 78 (2) || || || || || || || || || || || || || - || - || - || - || 1 || - || - || 1 → IF || Set Interrupt Disable
 +
|-
 +
| STA || || || || 8D (4) || 9D (5) || 99 (5) || || 85 (3) || 95 (4) || || 81 (6) || 91 (6) || || - || - || - || - || - || - || - || A → M || Store Accumulator in Memory
 +
|-
 +
| STX || || || || 8E (4) || || || || 86 (3) || || 96 (4) || || || || - || - || - || - || - || - || - || X → M || Store Index X in Memory
 +
|-
 +
| STY || || || || 8C (4) || || || || 84 (3) || 94 (4) || || || || || - || - || - || - || - || - || - || Y → M || Store Index Y in Memory
 +
|-
 +
| TAX || AA (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || A → X || Transfer Accumulator to Index X
 +
|-
 +
| TAY || A8 (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || A → Y || Transfer Accumulator to Index Y
 +
|-
 +
| TSX || BA (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || S → X || Transfer Stack Pointer to Index X
 +
|-
 +
| TXA || 8A (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || X → A || Transfer Index X to Accumulator
 +
|-
 +
| TXS || 9A (2) || || || || || || || || || || || || || - || - || - || - || - || - || - || X → S || Transfer Index X to Stack Pointer
 +
|-
 +
| TYA || 98 (2) || || || || || || || || || || || || || N || - || - || - || - || Z || - || Y → A || Transfer Index Y to Accumulator
 
|}
 
|}
  
 
=== Illegal instructions ===
 
=== Illegal instructions ===
  
The opcodes in bold are highly unstable.
+
Opcodes in red are unstable. Only 2 of those 7 opcodes ($8B, $AB) are actually unstable in the sense that they may produce a truly unpredictable result. The other 5 opcodes actually produce predictable results – but the conditions under which they do that and the produced results are a bit unexpected.
  
{| class="wikitable"
+
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
! rowspan=2|Mnemonic !! colspan=10|Addressing Modes !! colspan=8|Flags !! rowspan=2|Operation !! rowspan=2|Description
+
! rowspan=2|Mnemonic !! rowspan=2|Combines !! colspan=10|Addressing Modes !! colspan=7|Flags !! rowspan=2|Operation !! rowspan=2|Description
 
|-
 
|-
! ''No arg'' !! #$nn !! $nnnn !! $nnnn,X !! $nnnn,Y !! $nn !! $nn,X !! $nn,Y !! ($nn,X) !! ($nn),Y !! N !! V !! - !! B !! D !! I !! Z !! C
+
! ''No arg'' !! #$nn !! $nnnn !! $nnnn,X !! $nnnn,Y !! $nn !! $nn,X !! $nn,Y !! ($nn,X) !! ($nn),Y !! N !! V !! B !! D !! I !! Z !! C
 
|-
 
|-
| ANC (ANC2) || || 0B, 2B || || || || || || || || || N || - || - || - || - || - || Z || C || A ∧ M → A, NF → CF || "AND" Memory with Accumulator then Move Negative Flag to Carry Flag
+
| ANC (ANC2) || AND + ASL/ROL || || 0B, 2B (2) || || || || || || || || || N || - || - || - || - || Z || C || A ∧ M → A, NF → CF || "AND" Memory with Accumulator then Move Negative Flag to Carry Flag
 
|-
 
|-
| ARR || || 6B || || || || || || || || || N || V || - || - || - || - || Z || C || (A ∧ M) / 2 → A || "AND" Accumulator then Rotate Right
+
| ARR || AND + ROR || || 6B (2) || || || || || || || || || N || V || - || - || - || Z || C || (A ∧ M) / 2 → A || "AND" Accumulator then Rotate Right
 
|-
 
|-
| ASR (ALR) || || 4B || || || || || || || || || 0 || - || - || - || - || - || Z || C || (A ∧ M) / 2 → A || "AND" then Logical Shift Right
+
| ASR (ALR) || AND + LSR || || 4B (2) || || || || || || || || || 0 || - || - || - || - || Z || C || (A ∧ M) / 2 → A || "AND" then Logical Shift Right
 
|-
 
|-
| DCP (DCM) || || || CF || DF || DB || C7 || D7 || || C3 || D3 || N || - || - || - || - || - || Z || C || M - 1 → M, A - M || Decrement Memory By One then Compare with Accumulator
+
| DCP (DCM) || DEC + CMP || || || CF (6) || DF (7) || DB (7) || C7 (5) || D7 (6) || || C3 (8) || D3 (8) || N || - || - || - || - || Z || C || M - 1 → M, A - M || Decrement Memory By One then Compare with Accumulator
 
|-
 
|-
| ISC (ISB, INS) || || || EF || FF || FB || E7 || F7 || || E3 || F3 || N || V || - || - || - || - || Z || C || M + 1 → M, A - M → A || Increment Memory By One then SBC then Subtract Memory from Accumulator with Borrow
+
| ISC (ISB, INS) || INC + SBC || || || EF (6) || FF (7) || FB (7) || E7 (5) || F7 (6) || || E3 (8) || F3 (8) || N || V || - || - || - || Z || C || M + 1 → M, A - M → A || Increment Memory By One then SBC then Subtract Memory from Accumulator with Borrow
 
|-
 
|-
| JAM (KIL, HLT) || 02, 12, 22,
+
| JAM (KIL, HLT) || || 02, 12, 22,
 
32, 42, 52,
 
32, 42, 52,
  
 
62, 72, 92,
 
62, 72, 92,
  
B2, D2, F2
+
B2, D2, F2 (X)
|| || || || || || || || || || - || - || - || - || - || - || - || - || Stop execution || Halt the CPU
+
|| || || || || || || || || || - || - || - || - || - || - || - || Stop execution || Halt the CPU
 
|-
 
|-
| LAS (LAR) || || || || || BB || || || || || || N || - || - || - || - || - || Z || - || M ∧ S → A, X, S || "AND" Memory with Stack Pointer
+
| LAS (LAR) || STA/TXS + LDA/STX || || || || || BB (4+p) || || || || || || N || - || - || - || - || Z || - || M ∧ S → A, X, S || "AND" Memory with Stack Pointer
 
|-
 
|-
| LAX (LXA) || || '''AB''' || AF || || BF || A7 || || B7 || A3 || B3 || N || - || - || - || - || - || Z || - || M → A, X || Load Accumulator and Index Register X From Memory
+
| LAX (LXA) || LDA + LDX || || style="color: #CC0000;"|'''AB''' (2) || AF (4) || || BF (4+p) || A7 (3) || || B7 (4) || A3 (6) || B3 (5+p) || N || - || - || - || - || Z || - || M → A, X || Load Accumulator and Index Register X From Memory
 
|-
 
|-
| NOP (DOP, TOP) || 1A, 3A, 5A,
+
| NOP (DOP, TOP) || || 1A, 3A, 5A,
7A, DA, FA
+
7A, DA, FA (2)
 
|| 80, 82, 89,
 
|| 80, 82, 89,
C2, E2
+
C2, E2 (2)
|| 0C || 1C, 3C, 5C,
+
|| 0C (4) || 1C, 3C, 5C,
7C, DC, FC
+
7C, DC, FC (4+p)
|| || 04, 44, 64 || 14, 34, 54,
+
|| || 04, 44, 64 (3) || 14, 34, 54,
74, D4, F4
+
74, D4, F4 (4)
|| || || || - || - || - || - || - || - || - || - || No operation || No Operation
+
|| || || || - || - || - || - || - || - || - || No operation || No Operation
 
|-
 
|-
| RLA || || || 2F || 3F || 3B || 27 || 37 || || 23 || 33 || N || - || - || - || - || - || Z || C || CF ← /M7...M0/ ← CF, A ∧ M → A || Rotate Left then "AND" with Accumulator
+
| RLA || ROL + AND || || || 2F (6) || 3F (7) || 3B (7) || 27 (5) || 37 (6) || || 23 (8) || 33 (8) || N || - || - || - || - || Z || C || CF ← /M7...M0/ ← CF, A ∧ M → A || Rotate Left then "AND" with Accumulator
 
|-
 
|-
| RRA || || || 6F || 7F || 7B || 67 || 77 || || 63 || 73 || N || V || - || - || - || - || Z || C || CF → /M7...M0/ → CF, A + M + CF → A || Rotate Right and Add Memory to Accumulator
+
| RRA || ROR + ADC || || || 6F (6) || 7F (7) || 7B (7) || 67 (5) || 77 (6) || || 63 (8) || 73 (8) || N || V || - || - || - || Z || C || CF → /M7...M0/ → CF, A + M + CF → A || Rotate Right and Add Memory to Accumulator
 
|-
 
|-
| SAX (AXS, AAX) || || || 8F || || || 87 || || 97 || 83 || || - || - || - || - || - || - || - || - || A ∧ X → M || Store Accumulator "AND" Index Register X in Memory
+
| SAX (AXS, AAX) || STA + STX || || || 8F (4) || || || 87 (3) || || 97 (4) || 83 (6) || || - || - || - || - || - || - || - || A ∧ X → M || Store Accumulator "AND" Index Register X in Memory
 
|-
 
|-
| SBC || || EB || || || || || || || || || N || V || - || - || - || - || Z || C || A - M - ~CF → A || Subtract Memory from Accumulator with Borrow
+
| SBC (USBC) || SBC + NOP || || EB (2) || || || || || || || || || N || V || - || - || - || Z || C || A - M - ~CF → A || Subtract Memory from Accumulator with Borrow
 
|-
 
|-
| SBX (AXS, SAX) || || CB || || || || || || || || || N || - || - || - || - || - || Z || C || (A ∧ X) - M → X || Subtract Memory from Accumulator "AND" Index Register X
+
| SBX (AXS, SAX) || CMP + DEX || || CB (2) || || || || || || || || || N || - || - || - || - || Z || C || (A ∧ X) - M → X || Subtract Memory from Accumulator "AND" Index Register X
 
|-
 
|-
| SHA (AHX, AXA) || || || || || 9F || || || || || 93 || - || - || - || - || - || - || - || - || A ∧ X ∧ V → M || Store Accumulator "AND" Index Register X "AND" Value
+
| SHA (AHX, AXA) || STA/STX/STY || || || || || style="color: #CC0000;"|'''9F''' (5) || || || || || style="color: #CC0000;"|'''93''' (6) || - || - || - || - || - || - || - || A ∧ X ∧ V → M || Store Accumulator "AND" Index Register X "AND" Value
 
|-
 
|-
| SHS (TAS, XAS) || || || || || 9B || || || || || || - || - || - || - || - || - || - || - || A ∧ X → S, S ∧ (H + 1) → M || Transfer Accumulator "AND" Index Register X to Stack Pointer then Store Stack Pointer "AND" Hi-Byte In Memory
+
| SHS (TAS, XAS) || STA/TXS + LDA/TSX || || || || || style="color: #CC0000;"|'''9B''' (5) || || || || || || - || - || - || - || - || - || - || A ∧ X → S, S ∧ (H + 1) → M || Transfer Accumulator "AND" Index Register X to Stack Pointer then Store Stack Pointer "AND" Hi-Byte In Memory
 
|-
 
|-
| SHX (SXA, XAS) || || || || || 9E || || || || || || - || - || - || - || - || - || - || - || X ∧ (H + 1) → M || Store Index Register X "AND" Value
+
| SHX (SXA, XAS) || STA/STX/STY || || || || || style="color: #CC0000;"|'''9E''' (5) || || || || || || - || - || - || - || - || - || - || X ∧ (H + 1) → M || Store Index Register X "AND" Value
 
|-
 
|-
| SHY (SYA, SAY) || || || || 9C || || || || || || || - || - || - || - || - || - || - || - || Y ∧ (H + 1) → M || Store Index Register Y "AND" Value
+
| SHY (SYA, SAY) || STA/STX/STY || || || || style="color: #CC0000;"|'''9C''' (5) || || || || || || || - || - || - || - || - || - || - || Y ∧ (H + 1) → M || Store Index Register Y "AND" Value
 
|-
 
|-
| SLO (ASO) || || || 0F || 1F || 1B || 07 || 17 || || 03 || 13 || N || - || - || - || - || - || Z || C || M * 2 → M, A ∨ M → A || Arithmetic Shift Left then "OR" Memory with Accumulator
+
| SLO (ASO) || ASL + ORA || || || 0F (6) || 1F (7) || 1B (7) || 07 (5) || 17 (6) || || 03 (8) || 13 (8) || N || - || - || - || - || Z || C || M * 2 → M, A ∨ M → A || Arithmetic Shift Left then "OR" Memory with Accumulator
 
|-
 
|-
| SRE (LSE) || || || 4F || 5F || 5B || 47 || 57 || || 43 || 53 || N || - || - || - || - || - || Z || C || M / 2 → M, A ⊻ M → A || Logical Shift Right then "Exclusive OR" Memory with Accumulator
+
| SRE (LSE) || LSR + EOR || || || 4F (6) || 5F (7) || 5B (7) || 47 (5) || 57 (6) || || 43 (8) || 53 (8) || N || - || - || - || - || Z || C || M / 2 → M, A ⊻ M → A || Logical Shift Right then "Exclusive OR" Memory with Accumulator
 
|-
 
|-
| XAA (ANE) || || '''8B''' || || || || || || || || || N || - || - || - || - || - || Z || - || (A ∨ V) ∧ X ∧ M → A || Non-deterministic Operation of Accumulator, Index Register X, Memory and Bus Contents
+
| XAA (ANE) || TXA + AND || || style="color: #CC0000;"|'''8B''' (2) || || || || || || || || || N || - || - || - || - || Z || - || (A ∨ V) ∧ X ∧ M → A || Non-deterministic Operation of Accumulator, Index Register X, Memory and Bus Contents
 
|}
 
|}
  
 
<br>
 
<br>
  
== Opcode matrix ==
+
== Opcodes ==
  
 +
The 6502 follows a 3-3-2 opcode bit pattern. If we arrange the opcode table in a slightly different way than it is usually done, we can observe some interesting symmetries:
  
{| class="wikitable" style="white-space: nowrap;"
+
{| style="white-space: nowrap;"
 
|-
 
|-
|colspan=17| Addressing modes: <span style="background-color: #e0e0e0;">'''A''' - accumulator</span>, <span style="background-color: #e0ffe0;">'''#''' - immediate</span>, <span style="background-color: #ffe0e0;">'''zpg''' - zero page</span>, <span style="background-color: #e0ffff;">'''abs''' - absolute</span>, <span style="background-color: #ffe0ff;">'''ind''' - indirect</span>, <span style="background-color: #ffffe0;">'''rel''' - relative</span>. Uncolored cells are illegal opcodes.
+
|  
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 
|-
 
|-
!rowspan=2| High nibble ||colspan=16| Low nibble
+
| 00 || BRK
|-  
+
|-
! 0|| 1||  2||  3||  4||  5||  6||  7||  8||  9||  A||  B||  C||  D||  E||  F
+
| 04 || '''NOP ''zpg'''''
|-
+
|-
! 0
+
| 08 || PHP
| bgcolor=#e0e0e0|BRK
+
|-
| bgcolor=#ffe0ff|ORA (''ind'',X)
+
| 0C || '''NOP ''abs'''''
| JAM
+
|-
| SLO (''ind'',X)
+
| 10 || BPL ''rel''
| NOP ''zpg''
+
|-
| bgcolor=#ffe0e0|ORA ''zpg''
+
| 14 || '''NOP ''zpg'',X'''
| bgcolor=#ffe0e0|ASL ''zpg''
+
|-
| SLO ''zpg''
+
| 18 || CLC
| bgcolor=#e0e0e0|PHP
+
|-
| bgcolor=#e0ffe0|ORA #
+
| 1C || '''NOP ''abs'',X'''
| bgcolor=#e0e0e0|ASL A
+
|}
| ANC #
+
|
| NOP ''abs''
+
{| class="wikitable"
| bgcolor=#e0ffff|ORA ''abs''
+
! Opc !! Mnemonic
| bgcolor=#e0ffff|ASL ''abs''
+
|-
| SLO ''abs''
+
| 20 || JSR ''abs''
|-  
+
|-
! 1
+
| 24 || BIT ''zpg''
| bgcolor=#ffffe0|BPL ''rel''
+
|-
| bgcolor=#ffe0ff|ORA (''ind''),Y
+
| 28 || PLP
| JAM
+
|-
| SLO (''ind''),Y
+
| 2C || BIT ''abs''
| NOP ''zpg'',X
+
|-
| bgcolor=#ffe0e0|ORA ''zpg'',X
+
| 30 || BMI ''rel''
| bgcolor=#ffe0e0|ASL ''zpg'',X
+
|-
| SLO ''zpg'',X
+
| 34 || '''NOP ''zpg'',X'''
| bgcolor=#e0e0e0|CLC
+
|-
| bgcolor=#e0ffff|ORA ''abs'',Y
+
| 38 || SEC
| NOP
+
|-
| SLO ''abs'',Y
+
| 3C || '''NOP ''abs'',X'''
| NOP ''abs'',X
+
|}
| bgcolor=#e0ffff|ORA ''abs'',X
+
|
| bgcolor=#e0ffff|ASL ''abs'',X
+
{| class="wikitable"
| SLO ''abs'',X
+
! Opc !! Mnemonic
|-
+
|-
! 2
+
| 40 || RTI
| bgcolor=#e0ffff|JSR ''abs''
+
|-
| bgcolor=#ffe0ff|AND (''ind'',X)
+
| 44 || '''NOP ''zpg'''''
| JAM
+
|-
| RLA (''ind'',X)
+
| 48 || PHA
| bgcolor=#ffe0e0|BIT ''zpg''
+
|-
| bgcolor=#ffe0e0|AND ''zpg''
+
| 4C || JMP ''abs''
| bgcolor=#ffe0e0|ROL ''zpg''
+
|-
| RLA ''zpg''
+
| 50 || BVC ''rel''
| bgcolor=#e0e0e0|PLP
+
|-
| bgcolor=#e0ffe0|AND #
+
| 54 || '''NOP ''zpg'',X'''
| bgcolor=#e0e0e0|ROL A
+
|-
| ANC #
+
| 58 || CLI
| bgcolor=#e0ffff|BIT ''abs''
+
|-
| bgcolor=#e0ffff|AND ''abs''
+
| 5C || '''NOP ''abs'',X'''
| bgcolor=#e0ffff|ROL ''abs''
+
|}
| RLA ''abs''
+
|
|-  
+
{| class="wikitable"
! 3
+
! Opc !! Mnemonic
| bgcolor=#ffffe0|BMI ''rel''
+
|-
| bgcolor=#ffe0ff|AND (''ind''),Y
+
| 60 || RTS
| JAM
+
|-
| RLA (''ind''),Y
+
| 64 || '''NOP ''zpg'''''
| NOP ''zpg'',X
+
|-
| bgcolor=#ffe0e0|AND ''zpg'',X
+
| 68 || PLA
| bgcolor=#ffe0e0|ROL ''zpg'',X
+
|-
| RLA ''zpg'',X
+
| 6C || JMP ''zpg''
| bgcolor=#e0e0e0|SEC
+
|-
| bgcolor=#e0ffff|AND ''abs'',Y
+
| 70 || BVS ''rel''
| NOP
+
|-
| RLA ''abs'',Y
+
| 74 || '''NOP ''zpg'',X'''
| NOP ''abs'',X
+
|-
| bgcolor=#e0ffff|AND ''abs'',X
+
| 78 || SEI
| bgcolor=#e0ffff|ROL ''abs'',X
+
|-
| RLA ''abs'',X
+
| 7C || '''NOP ''abs'',X'''
|-
+
|}
! 4
+
|
| bgcolor=#e0e0e0|RTI
+
{| class="wikitable"
| bgcolor=#ffe0ff|EOR (''ind'',X)
+
! Opc !! Mnemonic
| JAM
+
|-
| SRE (''ind'',X)
+
| 80 || '''NOP #'''
| NOP ''zpg''
+
|-
| bgcolor=#ffe0e0|EOR ''zpg''
+
| 84 || STY ''zpg''
| bgcolor=#ffe0e0|LSR ''zpg''
+
|-
| SRE ''zpg''
+
| 88 || DEY
| bgcolor=#e0e0e0|PHA
+
|-
| bgcolor=#e0ffe0|EOR #
+
| 8C || STY ''abs''
| bgcolor=#e0e0e0|LSR A
+
|-
| ALR #
+
| 90 || BCC ''rel''
| bgcolor=#e0ffff|JMP ''abs''
+
|-
| bgcolor=#e0ffff|EOR ''abs''
+
| 94 || STY ''zpg'',X
| bgcolor=#e0ffff|LSR ''abs''
+
|-
| SRE ''abs''
+
| 98 || TYA
|-  
+
|-
! 5
+
| 9C ||style="color: #CC0000;"|'''SHY ''abs'',X'''
| bgcolor=#ffffe0|BVC ''rel''
+
|}
| bgcolor=#ffe0ff|EOR (''ind''),Y
+
|
| JAM
+
{| class="wikitable"
| SRE (''ind''),Y
+
! Opc !! Mnemonic
| NOP ''zpg'',X
+
|-
| bgcolor=#ffe0e0|EOR ''zpg'',X
+
| A0 || LDY #
| bgcolor=#ffe0e0|LSR ''zpg'',X
+
|-
| SRE ''zpg'',X
+
| A4 || LDY ''zpg''
| bgcolor=#e0e0e0|CLI
+
|-
| bgcolor=#e0ffff|EOR ''abs'',Y
+
| A8 || TAY
| NOP
+
|-
| SRE ''abs'',Y
+
| AC || LDY ''abs''
| NOP ''abs'',X
+
|-
| bgcolor=#e0ffff|EOR ''abs'',X
+
| B0 || BCS ''rel''
| bgcolor=#e0ffff|LSR ''abs'',X
+
|-
| SRE ''abs'',X
+
| B4 || LDY ''zpg'',X
|-
+
|-
! 6
+
| B8 || CLV
| bgcolor=#e0e0e0|RTS
+
|-
| bgcolor=#ffe0ff|ADC (''ind'',X)
+
| BC || LDY ''abs'',X
| JAM
+
|}
| RRA (''ind'',X)
+
|
| NOP ''zpg''
+
{| class="wikitable"
| bgcolor=#ffe0e0|ADC ''zpg''
+
! Opc !! Mnemonic
| bgcolor=#ffe0e0|ROR ''zpg''
+
|-
| RRA ''zpg''
+
| C0 || CPY #
| bgcolor=#e0e0e0|PLA
+
|-
| bgcolor=#e0ffe0|ADC #
+
| C4 || CPY ''zpg''
| bgcolor=#e0e0e0|ROR A
+
|-
| ARR #
+
| C8 || INY
| bgcolor=#ffe0ff|JMP (''ind'')
+
|-
| bgcolor=#e0ffff|ADC ''abs''
+
| CC || CPY ''abs''
| bgcolor=#e0ffff|ROR ''abs''
+
|-
| RRA ''abs''
+
| D0 || BNE ''rel''
|-  
+
|-
! 7
+
| D4 || '''NOP ''zpg'',X'''
| bgcolor=#ffffe0|BVS ''rel''
+
|-
| bgcolor=#ffe0ff|ADC (''ind''),Y
+
| D8 || CLD
| JAM
+
|-
| RRA (''ind''),Y
+
| DC || '''NOP ''abs'',X'''
| NOP ''zpg'',X
+
|}
| bgcolor=#ffe0e0|ADC ''zpg'',X
+
|
| bgcolor=#ffe0e0|ROR ''zpg'',X
+
{| class="wikitable"
| RRA ''zpg'',X
+
! Opc !! Mnemonic
| bgcolor=#e0e0e0|SEI
+
|-
| bgcolor=#e0ffff|ADC ''abs'',Y
+
| E0 || CPX #
| NOP
+
|-
| RRA ''abs'',Y
+
| E4 || CPX ''zpg''
| NOP ''abs'',X
+
|-
| bgcolor=#e0ffff|ADC ''abs'',X
+
| E8 || INX
| bgcolor=#e0ffff|ROR ''abs'',X
+
|-
| RRA ''abs'',X
+
| EC || CPX ''abs''
|-
+
|-
! 8
+
| F0 || BEQ ''rel''
| NOP #
+
|-
| bgcolor=#ffe0ff|STA (''ind'',X)
+
| F4 || '''NOP ''zpg'',X'''
| NOP #
+
|-
| SAX (''ind'',X)
+
| F8 || SED
| bgcolor=#ffe0e0|STY ''zpg''
+
|-
| bgcolor=#ffe0e0|STA ''zpg''
+
| FC || '''NOP ''abs'',X'''
| bgcolor=#ffe0e0|STX ''zpg''
+
|}
| SAX ''zpg''
+
| bgcolor=#e0e0e0|DEY
+
| NOP #
+
| bgcolor=#e0e0e0|TXA
+
| '''ANE #'''
+
| bgcolor=#e0ffff|STY ''abs''
+
| bgcolor=#e0ffff|STA ''abs''
+
| bgcolor=#e0ffff|STX ''abs''
+
| SAX ''abs''
+
|-
+
! 9
+
| bgcolor=#ffffe0|BCC ''rel''
+
| bgcolor=#ffe0ff|STA (''ind''),Y
+
| JAM
+
| SHA (''ind''),Y
+
| bgcolor=#ffe0e0|STY ''zpg'',X
+
| bgcolor=#ffe0e0|STA ''zpg'',X
+
| bgcolor=#ffe0e0|STX ''zpg'',Y
+
| SAX ''zpg'',Y
+
| bgcolor=#e0e0e0|TYA
+
| bgcolor=#e0ffff|STA ''abs'',Y
+
| bgcolor=#e0e0e0|TXS
+
| TAS ''abs'',Y
+
| SHY ''abs'',X
+
| bgcolor=#e0ffff|STA ''abs'',X
+
| SHX ''abs'',Y
+
| SHA ''abs'',Y
+
|-
+
! A
+
| bgcolor=#e0ffe0|LDY #
+
| bgcolor=#ffe0ff|LDA (''ind'',X)
+
| bgcolor=#e0ffe0|LDX #
+
| LAX (''ind'',X)
+
| bgcolor=#ffe0e0|LDY ''zpg''
+
| bgcolor=#ffe0e0|LDA ''zpg''
+
| bgcolor=#ffe0e0|LDX ''zpg''
+
| LAX ''zpg''
+
| bgcolor=#e0e0e0|TAY
+
| bgcolor=#e0ffe0|LDA #
+
| bgcolor=#e0e0e0|TAX
+
| '''LXA #'''
+
| bgcolor=#e0ffff|LDY ''abs''
+
| bgcolor=#e0ffff|LDA ''abs''
+
| bgcolor=#e0ffff|LDX ''abs''
+
| LAX ''abs''
+
|-
+
! B
+
| bgcolor=#ffffe0|BCS ''rel''
+
| bgcolor=#ffe0ff|LDA (''ind''),Y
+
| JAM
+
| LAX (''ind''),Y
+
| bgcolor=#ffe0e0|LDY ''zpg'',X
+
| bgcolor=#ffe0e0|LDA ''zpg'',X
+
| bgcolor=#ffe0e0|LDX ''zpg'',Y
+
| LAX ''zpg'',Y
+
| bgcolor=#e0e0e0|CLV
+
| bgcolor=#e0ffff|LDA ''abs'',Y
+
| bgcolor=#e0e0e0|TSX
+
| LAS ''abs'',Y
+
| bgcolor=#e0ffff|LDY ''abs'',X
+
| bgcolor=#e0ffff|LDA ''abs'',X
+
| bgcolor=#e0ffff|LDX ''abs'',Y
+
| LAX ''abs'',Y
+
|-  
+
! C
+
| bgcolor=#e0ffe0|CPY #
+
| bgcolor=#ffe0ff|CMP (''ind'',X)
+
| NOP #
+
| DCP (''ind'',X)
+
| bgcolor=#ffe0e0|CPY ''zpg''
+
| bgcolor=#ffe0e0|CMP ''zpg''
+
| bgcolor=#ffe0e0|DEC ''zpg''
+
| DCP ''zpg''
+
| bgcolor=#e0e0e0|INY
+
| bgcolor=#e0ffe0|CMP #
+
| bgcolor=#e0e0e0|DEX
+
| AXS #
+
| bgcolor=#e0ffff|CPY ''abs''
+
| bgcolor=#e0ffff|CMP ''abs''
+
| bgcolor=#e0ffff|DEC ''abs''
+
| DCP ''abs''
+
|-  
+
! D
+
| bgcolor=#ffffe0|BNE ''rel''
+
| bgcolor=#ffe0ff|CMP (''ind''),Y
+
| JAM
+
| DCP (''ind''),Y
+
| NOP ''zpg'',X
+
| bgcolor=#ffe0e0|CMP ''zpg'',X
+
| bgcolor=#ffe0e0|DEC ''zpg'',X
+
| DCP ''zpg'',X
+
| bgcolor=#e0e0e0|CLD
+
| bgcolor=#e0ffff|CMP ''abs'',Y
+
| NOP
+
| DCP ''abs'',Y
+
| NOP ''abs'',X
+
| bgcolor=#e0ffff|CMP ''abs'',X
+
| bgcolor=#e0ffff|DEC ''abs'',X
+
| DCP ''abs'',X
+
|-
+
! E
+
| bgcolor=#e0ffe0|CPX #
+
| bgcolor=#ffe0ff|SBC (''ind'',X)
+
| NOP #
+
| ISC (''ind'',X)
+
| bgcolor=#ffe0e0|CPX ''zpg''
+
| bgcolor=#ffe0e0|SBC ''zpg''
+
| bgcolor=#ffe0e0|INC ''zpg''
+
| ISC ''zpg''
+
| bgcolor=#e0e0e0|INX
+
| bgcolor=#e0ffe0|SBC #
+
| bgcolor=#e0e0e0|NOP
+
| SBC #
+
| bgcolor=#e0ffff|CPX ''abs''
+
| bgcolor=#e0ffff|SBC ''abs''
+
| bgcolor=#e0ffff|INC ''abs''
+
| ISC ''abs''
+
|-  
+
! F
+
| bgcolor=#ffffe0|BEQ ''rel''
+
| bgcolor=#ffe0ff|SBC (''ind''),Y
+
| JAM
+
| ISC (''ind''),Y
+
| NOP ''zpg'',X
+
| bgcolor=#ffe0e0|SBC ''zpg'',X
+
| bgcolor=#ffe0e0|INC ''zpg'',X
+
| ISC ''zpg'',X
+
| bgcolor=#e0e0e0|SED
+
| bgcolor=#e0ffff|SBC ''abs'',Y
+
| NOP
+
| ISC ''abs'',Y
+
| NOP ''abs'',X
+
| bgcolor=#e0ffff|SBC ''abs'',X
+
| bgcolor=#e0ffff|INC ''abs'',X
+
| ISC ''abs'',X
+
 
|}
 
|}
 +
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 01 || ORA (''zpg'',X)
 +
|-
 +
| 05 || ORA ''zpg''
 +
|-
 +
| 09 || ORA #
 +
|-
 +
| 0D || ORA ''abs''
 +
|-
 +
| 11 || ORA (''zpg''),Y
 +
|-
 +
| 15 || ORA ''zpg'',X
 +
|-
 +
| 19 || ORA ''abs'',Y
 +
|-
 +
| 1D || ORA ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 21 || AND (''zpg'',X)
 +
|-
 +
| 25 || AND ''zpg''
 +
|-
 +
| 29 || AND #
 +
|-
 +
| 2D || AND ''abs''
 +
|-
 +
| 31 || AND (''zpg''),Y
 +
|-
 +
| 35 || AND ''zpg'',X
 +
|-
 +
| 39 || AND ''abs'',Y
 +
|-
 +
| 3D || AND ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 41 || EOR (''zpg'',X)
 +
|-
 +
| 45 || EOR ''zpg''
 +
|-
 +
| 49 || EOR #
 +
|-
 +
| 4D || EOR ''abs''
 +
|-
 +
| 51 || EOR (''zpg''),Y
 +
|-
 +
| 55 || EOR ''zpg'',X
 +
|-
 +
| 59 || EOR ''abs'',Y
 +
|-
 +
| 5D || EOR ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 61 || ADC (''zpg'',X)
 +
|-
 +
| 65 || ADC ''zpg''
 +
|-
 +
| 69 || ADC #
 +
|-
 +
| 6D || ADC ''abs''
 +
|-
 +
| 71 || ADC (''zpg''),Y
 +
|-
 +
| 75 || ADC ''zpg'',X
 +
|-
 +
| 79 || ADC ''abs'',Y
 +
|-
 +
| 7D || ADC ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 81 || STA (''zpg'',X)
 +
|-
 +
| 85 || STA ''zpg''
 +
|-
 +
| 89 || '''NOP #'''
 +
|-
 +
| 8D || STA ''abs''
 +
|-
 +
| 91 || STA (''zpg''),Y
 +
|-
 +
| 95 || STA ''zpg'',X
 +
|-
 +
| 99 || STA ''abs'',Y
 +
|-
 +
| 9D || STA ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| A1 || LDA (''zpg'',X)
 +
|-
 +
| A5 || LDA ''zpg''
 +
|-
 +
| A9 || LDA #
 +
|-
 +
| AD || LDA ''abs''
 +
|-
 +
| B1 || LDA (''zpg''),Y
 +
|-
 +
| B5 || LDA ''zpg'',X
 +
|-
 +
| B9 || LDA ''abs'',Y
 +
|-
 +
| BD || LDA ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| C1 || CMP (''zpg'',X)
 +
|-
 +
| C5 || CMP ''zpg''
 +
|-
 +
| C9 || CMP #
 +
|-
 +
| CD || CMP ''abs''
 +
|-
 +
| D1 || CMP (''zpg''),Y
 +
|-
 +
| D5 || CMP ''zpg'',X
 +
|-
 +
| D9 || CMP ''abs'',Y
 +
|-
 +
| DD || CMP ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| E1 || SBC (''zpg'',X)
 +
|-
 +
| E5 || SBC ''zpg''
 +
|-
 +
| E9 || SBC #
 +
|-
 +
| ED || SBC ''abs''
 +
|-
 +
| F1 || SBC (''zpg''),Y
 +
|-
 +
| F5 || SBC ''zpg'',X
 +
|-
 +
| F9 || SBC ''abs'',Y
 +
|-
 +
| FD || SBC ''abs'',X
 +
|}
 +
|}
 +
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 02 || '''JAM'''
 +
|-
 +
| 06 || ASL ''zpg''
 +
|-
 +
| 0A || ASL A
 +
|-
 +
| 0E || ASL ''abs''
 +
|-
 +
| 12 || '''JAM'''
 +
|-
 +
| 16 || ASL ''zpg'',X
 +
|-
 +
| 1A || '''NOP'''
 +
|-
 +
| 1E || ASL ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 22 || '''JAM'''
 +
|-
 +
| 26 || ROL ''zpg''
 +
|-
 +
| 2A || ROL A
 +
|-
 +
| 2E || ROL ''abs''
 +
|-
 +
| 32 || '''JAM'''
 +
|-
 +
| 36 || ROL ''zpg'',X
 +
|-
 +
| 3A || '''NOP'''
 +
|-
 +
| 3E || ROL ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 42 || '''JAM'''
 +
|-
 +
| 46 || LSR ''zpg''
 +
|-
 +
| 4A || LSR A
 +
|-
 +
| 4E || LSR ''abs''
 +
|-
 +
| 52 || '''JAM'''
 +
|-
 +
| 56 || LSR ''zpg'',X
 +
|-
 +
| 5A || '''NOP'''
 +
|-
 +
| 5E || LSR ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 62 || '''JAM'''
 +
|-
 +
| 66 || ROR ''zpg''
 +
|-
 +
| 6A || ROR A
 +
|-
 +
| 6E || ROR ''abs''
 +
|-
 +
| 72 || '''JAM'''
 +
|-
 +
| 76 || ROR ''zpg'',X
 +
|-
 +
| 7A || '''NOP'''
 +
|-
 +
| 7E || ROR ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 82 || '''NOP #'''
 +
|-
 +
| 86 || STX ''zpg''
 +
|-
 +
| 8A || TXA
 +
|-
 +
| 8E || STX ''abs''
 +
|-
 +
| 92 || '''JAM'''
 +
|-
 +
| 96 || STX ''zpg'',Y
 +
|-
 +
| 9A || TXS
 +
|-
 +
| 9E ||style="color: #CC0000;"|'''SHX ''abs'',Y'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| A2 || LDX #
 +
|-
 +
| A6 || LDX ''zpg''
 +
|-
 +
| AA || TAX
 +
|-
 +
| AE || LDX ''abs''
 +
|-
 +
| B2 || '''JAM'''
 +
|-
 +
| B6 || LDX ''zpg'',Y
 +
|-
 +
| BA || TSX
 +
|-
 +
| BE || LDX ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| C2 || '''NOP #'''
 +
|-
 +
| C6 || DEC ''zpg''
 +
|-
 +
| CA || DEX
 +
|-
 +
| CE || DEC ''abs''
 +
|-
 +
| D2 || '''JAM'''
 +
|-
 +
| D6 || DEC ''zpg'',X
 +
|-
 +
| DA || '''NOP'''
 +
|-
 +
| DE || DEC ''abs'',X
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| E2 || '''NOP #'''
 +
|-
 +
| E6 || INC ''zpg''
 +
|-
 +
| EA || NOP
 +
|-
 +
| EE || INC ''abs''
 +
|-
 +
| F2 || '''JAM'''
 +
|-
 +
| F6 || INC ''zpg'',X
 +
|-
 +
| FA || '''NOP'''
 +
|-
 +
| FE || INC ''abs'',X
 +
|}
 +
|}
 +
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 03 || '''SLO (''zpg'',X)'''
 +
|-
 +
| 07 || '''SLO ''zpg'''''
 +
|-
 +
| 0B || '''ANC #'''
 +
|-
 +
| 0F || '''SLO ''abs'''''
 +
|-
 +
| 13 || '''SLO (''zpg''),Y'''
 +
|-
 +
| 17 || '''SLO ''zpg'',X'''
 +
|-
 +
| 1B || '''SLO ''abs'',Y'''
 +
|-
 +
| 1F || '''SLO ''abs'',X'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 23 || '''RLA (''zpg'',X)'''
 +
|-
 +
| 27 || '''RLA ''zpg'''''
 +
|-
 +
| 2B || '''ANC #'''
 +
|-
 +
| 2F || '''RLA ''abs'''''
 +
|-
 +
| 33 || '''RLA (''zpg''),Y'''
 +
|-
 +
| 37 || '''RLA ''zpg'',X'''
 +
|-
 +
| 3B || '''RLA ''abs'',Y'''
 +
|-
 +
| 3F || '''RLA ''abs'',X'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 43 || '''SRE (''zpg'',X)'''
 +
|-
 +
| 47 || '''SRE ''zpg'''''
 +
|-
 +
| 4B || '''ASR #'''
 +
|-
 +
| 4F || '''SRE ''abs'''''
 +
|-
 +
| 53 || '''SRE (''zpg''),Y'''
 +
|-
 +
| 57 || '''SRE ''zpg'',X'''
 +
|-
 +
| 5B || '''SRE ''abs'',Y'''
 +
|-
 +
| 5F || '''SRE ''abs'',X'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 63 || '''RRA (''zpg'',X)'''
 +
|-
 +
| 67 || '''RRA ''zpg'''''
 +
|-
 +
| 6B || '''ARR #'''
 +
|-
 +
| 6F || '''RRA ''abs'''''
 +
|-
 +
| 73 || '''RRA (''zpg''),Y'''
 +
|-
 +
| 77 || '''RRA ''zpg'',X'''
 +
|-
 +
| 7B || '''RRA ''abs'',Y'''
 +
|-
 +
| 7F || '''RRA ''abs'',X'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| 83 || '''SAX (''zpg'',X)'''
 +
|-
 +
| 87 || '''SAX ''zpg'''''
 +
|-
 +
| 8B ||style="color: #CC0000;"|'''XAA #'''
 +
|-
 +
| 8F || '''SAX ''abs'''''
 +
|-
 +
| 93 ||style="color: #CC0000;"|'''SHA (''zpg''),Y'''
 +
|-
 +
| 97 || '''SAX ''zpg'',Y'''
 +
|-
 +
| 9B ||style="color: #CC0000;"|'''SHS ''abs'',Y'''
 +
|-
 +
| 9F ||style="color: #CC0000;"|'''SHA ''abs'',Y'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| A3 || '''LAX (''zpg'',X)'''
 +
|-
 +
| A7 || '''LAX ''zpg'''''
 +
|-
 +
| AB ||style="color: #CC0000;"|'''LXA #'''
 +
|-
 +
| AF || '''LAX ''abs'''''
 +
|-
 +
| B3 || '''LAX (''zpg''),Y'''
 +
|-
 +
| B7 || '''LAX ''zpg'',Y'''
 +
|-
 +
| BB || '''LAS ''abs'',Y'''
 +
|-
 +
| BF || '''LAX ''abs'',Y'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| C3 || '''DCP (''zpg'',X)'''
 +
|-
 +
| C7 || '''DCP ''zpg'''''
 +
|-
 +
| CB || '''SBX #'''
 +
|-
 +
| CF || '''DCP ''abs'''''
 +
|-
 +
| D3 || '''DCP (''zpg''),Y'''
 +
|-
 +
| D7 || '''DCP ''zpg'',X'''
 +
|-
 +
| DB || '''DCP ''abs'',Y'''
 +
|-
 +
| DF || '''DCP ''abs'',X'''
 +
|}
 +
|
 +
{| class="wikitable"
 +
! Opc !! Mnemonic
 +
|-
 +
| E3 || '''ISC (''zpg'',X)'''
 +
|-
 +
| E7 || '''ISC ''zpg'''''
 +
|-
 +
| EB || '''SBC #'''
 +
|-
 +
| EF || '''ISC ''abs'''''
 +
|-
 +
| F3 || '''ISC (''zpg''),Y'''
 +
|-
 +
| F7 || '''ISC ''zpg'',X'''
 +
|-
 +
| FB || '''ISC ''abs'',Y'''
 +
|-
 +
| FF || '''ISC ''abs'',X'''
 +
|}
 +
|}
 +
 +
Opcodes in bold are illegal. Opcodes in red are unstable.
  
 
<br>
 
<br>
  
== Block Diagram ==
+
== Oddities ==
 +
 
 +
* On NMOS, an indirect JMP will behave unexpectedly when the indirect address crosses a page boundary, because the 6502 does not add the carry to calculate the address of the high byte. For example, JMP ($19FF) will use the contents of $19FF and $1900 for the JMP address. On CMOS, this issue was fixed, at the cost of 1 additional cycle. In our example, JMP ($19FF) will use the contents of $19FF and $2000 for the JMP address.
 +
 
 +
* Some instructions, particularly those involving branches or indexed addressing modes, incur an extra cycle if the processor has to cross a memory page boundary. This is problematic for time-sensitive code.
 +
 
 +
* Conditional jumps are only 8-bit relative. And unconditional jumps are only 16-bit absolute.
 +
 
 +
* ADC is the only command for addition. To perform an addition without carry, the carry flag must be cleared manually first. Same with SBC for subtract.
 +
 
 +
* The CLV (Clear Overflow Flag) instruction exist but not the SEV (Set Overflow Flag) instruction.
 +
 
 +
* The NOP instruction takes 2 full-cycles. This is the minimum amount of cycles an instruction can take.
 +
 
 +
* The alternate NOPs are not created equal. Some have one- or two-byte operands (which they don't do anything with), and they take different amounts of time to execute.
 +
 
 +
<br>
 +
 
 +
== Block Diagrams ==
 +
 
 +
=== Simple view ===
 +
[[File:Mcs6502-block-diagram.svg|500px]]
 +
 
 +
=== Detailed view ===
 +
[[File:CPU 6502 Detailed Block Diagram.jpg|500px]]
 +
 
 +
<br>
 +
 
 +
== CPU Pinout ==
 +
 
 +
[[File:6502CPU Pinout.gif]]
 +
 
 +
Notes:
 +
* SYNC is an output signal. It is high at T0.
 +
* S.O. is an input signal, which stands for Set Overflow. It allows the hardware to affect VF independently of the software.
 +
* Some pins are modified in CPU variants.
 +
 
 +
<br>
 +
 
 +
== Chip Variants ==
 +
 
 +
* The ROR instruction didn't exist in the very earliest (pre-1977) chips.
 +
 
 +
* The 6502 core used inside the [[NES]] is missing the Decimal Mode feature.
 +
 
 +
* The 6507 CPU, used in the [[Atari VCS]], has only 13 address lines. So it can only address 8KB instead of 64KB. It also lacks the IRQ and NMI interrupt lines.
 +
 
 +
* The 6510 CPU, used in the [[Commodore 64]], is a 6502 with an additional AEC pin that puts the bus in high impedance mode. It also includes a 6-bit I/O port that occupies addresses 0 and 1.
 +
 
 +
* The disk drive of the Commodore 64 has its own 6502 processor that acts as a floppy disk controller (FDC) and as a disk operating system (DOS) processor. It can also be used as a general coprocessor for the main system.
 +
 
 +
* The 6502C used in [[Atari 8-bit]] computer range, adds an additional HALT pin for DMA. The 6502C is otherwise a regular NMOS 6502, not to be confused with the CMOS 65C02.
 +
 
 +
* The CMOS 65C02 fixed multiple bugs of the original NMOS 6502, but also removed access to all illegal instructions. Some cycle counts have been modified and some extra instructions have been added. In fact, there are multiple implementations of the 65C02 (WDC 65C02, WDC 65C02S, Rockwell R65C02, CSG 65CE02, ...), each with its own variant of the instruction set.
 +
 
 +
* The HuC6280, used in the [[PC-Engine]] gaming console, is an improved version of the CMOS 65C02.
 +
 
 +
* The 65C816, used in the [[SNES]] and the [[Apple IIGS]], is a 16-bit version of the 65C02. It contains a compatibillity mode, enabled by default upon reset, that makes it behave like a regular 65C02.
  
[[File:Mcs6502-block-diagram.svg]]
+
* The Sony SPC700 sound CPU used inside the SNES also behaves similarly to a 6502 with some extensions. [https://snes.nesdev.org/wiki/SPC-700_instruction_set Source]
  
 
<br>
 
<br>
Line 548: Line 1,145:
 
== Links ==
 
== Links ==
 
*{{EnWiki|MOS_Technology_6502}}
 
*{{EnWiki|MOS_Technology_6502}}
 +
*[[Media:Onthe6502.pdf|On the 6502 - A brillant or sloppy design?]]
 
*[https://www.masswerk.at/6502/6502_instruction_set.html 6502 Instruction Set]
 
*[https://www.masswerk.at/6502/6502_instruction_set.html 6502 Instruction Set]
 
*[https://www.pagetable.com/c64ref/6502/?tab=2 6502 Family CPU Reference]
 
*[https://www.pagetable.com/c64ref/6502/?tab=2 6502 Family CPU Reference]
*[[Media:SY6500 - SY65C02 datasheet.pdf]]
+
*[https://llx.com/Neil/a2/opcodes.html The 6502/65C02/65C816 Instruction Set Decoded]
 +
*[https://www.nesdev.org/wiki/CPU_unofficial_opcodes Opcode matrix arrangement]
 +
*[https://www.oxyron.de/html/opcodes02.html Oxyron Opcode Matrix]
 +
*[http://www.6502.org/documents/datasheets/synertek/synertek_programming_manual.pdf Synertek SY650x programming manual (250 pages)]
 +
*[http://www.6502.org/documents/datasheets/synertek/synertek_hardware_manual.pdf Synertek SY650x hardware manual (178 pages)]
 +
*[[Media:SY6500 - SY65C02 datasheet.pdf]] - provides a detailed breakdown of the machine cycles
 
*[[Media:6502 (65xx) Microprocessor Instant Reference Card.pdf]]
 
*[[Media:6502 (65xx) Microprocessor Instant Reference Card.pdf]]
 +
*[[Media:6502-dead-cycles.pdf]]
 +
*[https://codebase64.org/doku.php?id=base:6510_instruction_timing 6510 Instruction Timing]
 
*[[Media:NoMoreSecrets-NMOS6510UnintendedOpcodes-20212412.pdf|No more secrets - NMOS 6510 Unintended Opcodes]]
 
*[[Media:NoMoreSecrets-NMOS6510UnintendedOpcodes-20212412.pdf|No more secrets - NMOS 6510 Unintended Opcodes]]
 +
*[https://www.pagetable.com/?p=39 How MOS 6502 illegal opcodes really work]
 +
*[https://youtu.be/fWqBmmPQP40 Conference - Reverse Engineering the MOS 6502 CPU]
 +
*[https://www.nesdev.org/wiki/CPU_interrupts 6502 Interrupts]
 +
*[https://floooh.github.io/2019/12/13/cycle-stepped-6502.html Cycle-stepped 6502 emulation how-to]
 +
*[https://github.com/SingleStepTests Tom Harte's SingleStepTests]
  
 
[[Category:Non CPC Computers]]
 
[[Category:Non CPC Computers]]
 
[[Category:Electronic Component]]
 
[[Category:Electronic Component]]

Latest revision as of 22:09, 20 November 2024

The 6502 CPU

The MOS Technology 6502 is an 8-bit microprocessor designed by Chuck Peddle in 1975 for MOS Technology (later purchased by Commodore). Along with the Zilog Z80, it sparked off a series of computer projects that would eventually result in the home computer revolution of the 1980s. The 6502 design was originally second-sourced by Rockwell and Synertek and later licensed to a number of companies; it is still made for embedded systems.

Originally the CPC was destined to be designed around the 6502 processor. But when Amstrad approached Locomotive Software to develop a Basic for it with a very tight deadline, Locomotive PLC, who already had a Z80 Basic in the works, urged and convinced Amstrad to switch to the Z80.


History

In 1973, Peddle worked at Motorola on developing the 6800 processor. Peddle recognized a market for a very low price microprocessor and began to champion such a design to complement the Motorola 6800. His efforts were frustrated by Motorola management and he was told to drop the project. He then left for MOS Technology, where he headed the design of the 6501.

The 6501 was pin-compatible with the 6800, meaning it could be used in the same systems without any changes. However, this led to legal trouble with Motorola, who argued that the 6501 infringed on their patents.

To resolve this, MOS Technology stopped producing the 6501 and introduced the 6502. While the 6502 was similar in design to the 6501 and 6800, it was no longer pin-compatible with the 6800, avoiding further legal issues.

Importantly, the 6502 had a much lower price point, which made it highly attractive to electronics manufacturers. Priced initially at just $25, the 6502 drastically undercut the Motorola 6800 and other competing processors like the Intel 8080, which were priced around $179 at the time. Motorola must have learnt from this lesson when they decided to sell the 68000 at $15 to Apple for the Macintosh in 1984.


Description

The 6502 microprocessor is an 8-bit CPU with an 8-bit ALU and a 16-bit address bus capable of direct access to 64KB of memory space.

Like the Z80, the 6502 is a little-endian CPU, meaning it reads 16-bit values with the least significant byte first, followed by the most significant byte. The 6502 has 151 instructions, which are composed of 56 distinct opcodes across various addressing modes.

The 6502 is an 8-bit CPU in the purest sense. Unlike the Z80, the 6502 does not have any 16-bit instructions and cannot pair its registers. To work with a 16-bit number you will need to split it in two and work with each half individually.

Although it lacks the raw processing power of processors like the Intel 80x86 or the Motorola 68000 series, the 6502 was known for its efficiency and affordability, making it a popular choice for embedded systems and early home computers. Its simple design contributed to lower manufacturing costs and simplified integration.

The 6502 chip is made up of 4528 transistors (3510 enhancement transistors and 1018 depletion pullup transistors). To put it into perspective, 64KB of DRAM contains 524288 transistors, as 1 bit of DRAM needs 1 transistor. The 6502 is mid-1970s technology while the 64KB DRAM is early-1980s technology.

Despite having so few transistors, the 6502 is generally considered at least twice as fast as the Z80 for the same clock speed Source. Three reasons explain this:

  • The 6502 has an 8-bit ALU, while the Z80 uses a 4-bit ALU.
  • The 6502 features a built-in clock doubler, allowing it to perform 1 internal operation and 1 memory access per cycle.
  • On average, a 2MHz 6502 can make 2 memory accesses per microsecond, while a 4MHz Z80 can only make 1.

This shows the design differences between the 6502 and Z80. The 6502 focused on efficiency, using its limited transistor budget for the ALU and fast memory access. In contrast, the Z80 neglected these and used more transistors for extra registers and complex instructions. However, these Z80's features, like the alternate register set, register pairs and 16-bit stack, make it easier to develop complex software.

The 6502 comes in a 40-pin DIP package. It has been produced by various manufacturers and used in a wide range of applications, from gaming consoles like the Atari VCS, Atari Lynx, Nintendo Entertainment System and PC-Engine to personal computers like the Apple II, BBC Micro, Atari XL, Oric, VIC20 and Commodore 64.


Registers

Register Size Description Notes
A (Accumulator) 8-bit Main register for arithmetic, logic, and data transfer Most operations use this register
X (Index Register X) 8-bit Used for indexing memory and loop counters Can be used for addressing modes like Indexed Indirect, Zero Page Indexed, and Absolute Indexed
Y (Index Register Y) 8-bit Used for indexing memory and loop counters Often used in Absolute and Zero Page Indexed addressing
P (Processor Status) 8-bit
  • bit7 - NF - Negative Flag: 1 when result is negative
  • bit6 - VF - Overflow Flag: 1 on signed overflow
  • bit5 - Unused: always set to 1
  • bit4 - BF - Break Flag: 1 when pushed by instructions (BRK / PHP) and 0 when pushed by interrupts (NMI / IRQ)
  • bit3 - DF - Decimal Mode Flag: 1 when CPU is in Decimal Mode
  • bit2 - IF - Interrupt Disable Flag: when 1, no interrupt will occur (except BRK and NMI)
  • bit1 - ZF - Zero Flag: 1 when all bits of a result are 0
  • bit0 - CF - Carry Flag: 1 on unsigned overflow
Flags are affected by most operations.

BF is not a physical flag implemented in a register. It only appears on the stack when the P register is pushed to it.

PHP (Push Processor Status) and PLP (Pull Processor Status) can be used to set or retrieve P directly via the stack.

Interrupts (BRK / NMI / IRQ) implicitly push P to the stack. Interrupts returning with RTI will implicitly pull P from the stack.

The effect of toggling the IF flag is delayed by 1 instruction when caused by SEI, CLI, or PLP.

S (Stack Pointer) 8-bit Points to the current location in the stack Stack is located in page 1 ($0100-$01FF), 8-bit S register is offset to this base
PC (Program Counter) 16-bit Points to the next instruction to be executed Automatically increments as instructions are executed


Memory Access

The address space that the 6502 uses is split into pages. There are 256 pages and each page is 256 bytes in size, ranging from page 0 to page 255.

In order to make up for the lack of registers, the 6502 includes a zero page addressing mode ($0000-$00FF) that uses only 1 address byte in the instruction instead of the 2 that are needed to address the full 64 KB of memory. This provides fast access to the first 256 bytes of RAM by using shorter instructions.

The stack is permanently located in page 1 ($0100-$01FF) and managed by the 8-bit stack pointer (S), with an initial value of $FF. It grows downward as data is pushed onto the stack. The stack has a 256-byte limit, and overflow occurs if not managed properly.

Instructions PHA and PHP push the accumulator and processor status onto the stack, while PLA and PLP pull them back. Subroutine calls with JSR store the return address on the stack, and RTS retrieves it to continue execution. Similarly, interrupts (BRK) push the program counter and status, while RTI restores them.


I/O Access

All I/O operations are memory-mapped. There are no port-based I/O instructions. Memory-mapped ports often have different properties than normal RAM:

  • The contents of a port can be updated by the hardware. Reading a port will not always return the same value each time it is read
  • It is also possible that reading a port will alter its contents, or alter the contents of other related ports
  • A read-only port is what it sounds like. Attempting to write to this address will not affect the contents
  • A write-only port can be written to, but reading it will result in undefined behaviour
  • Using the ports with instructions other than the Load/Store ones can be very unintuitive

This is not all negative though. Memory-mapped I/O means that:

  • The familiar instructions for accessing memory can be used for I/O, instead of learning a new set of instructions
  • No need to learn the weird partial I/O address decoding rules
  • Chips are directly accessible instead of being chained, like how the PSG chip has to be clumsily accessed through the PPI chip


Interrupts

6502 machines use the last 6 bytes of their address space to hold a vector table containing (in order) the addresses of the NMI routine, the program's start, and the IRQ routine.

On a RESET, the CPU loads the vector from $FFFC/$FFFD into the program counter and continues fetching instructions from there.

On an NMI, the CPU pushes the low byte and the high byte of the program counter as well as the processor status onto the stack, disables interrupts and loads the vector from $FFFA/$FFFB into the program counter and continues fetching instructions from there.

On an IRQ, the CPU does the same as in the NMI case, but uses the vector at $FFFE/$FFFF.

On a BRK instruction, the CPU does the same as in the IRQ case, but sets BF in the copy of the status register that is saved on the stack.

The priority sequence for interrupts, from top priority to bottom, is as follows: RESET, BRK, NMI, IRQ. Source at chapter 7.19


Interrupt hijacking

On NMOS, if NMI is asserted during the first 4 ticks of a BRK instruction, the BRK instruction will execute normally at first (PC increments will occur and P will be pushed with BF set to 1), but execution will branch to the NMI vector instead of the IRQ/BRK vector, effectively skipping the BRK instruction. On CMOS, this situation is correctly handled by executing BRK and then servicing the interrupt.

An IRQ can also hijack a BRK, though it won't be as visible since they use the same interrupt vector.

Similarly, an NMI can hijack an IRQ. But this is not usually a problem because the IRQ will normally still be asserted when the NMI returns and generate a new interrupt.


Branch instructions and Interrupts

The branch instructions have subtle interrupt polling behaviour. When executing a branch instruction, the 6502 checks for interrupts before fetching the operand (cycle 2).

If the branch is taken (i.e., the CPU decides to jump), it does not check for interrupts again before proceeding unless the branch crosses a page boundary (like moving from memory address $01FF to $0200).

If the branch crosses a page boundary, the CPU checks for interrupts once more before fixing the program counter.

If an interrupt is detected at any of these points (before the operand fetch or the page boundary fixup), the CPU will handle the interrupt immediately, interrupting the branch execution.

This behaviour has not been fixed in the CMOS 65C02 as this is not really a bug. It's just a subtlety that one has to keep in mind when working with time-sensitive code.


Decimal Mode

BCD operations are limited to addition and subtraction using the ADC and SBC instructions.

On NMOS, when Decimal Mode is on, the ADC and SBC instructions update NF, VF and ZF based on the binary result before the decimal correction is applied. Only CF is updated correctly. On CMOS, all the flags are updated correctly, at the cost of 1 additional cycle.

On NMOS, DF is not defined after RESET. On CMOS, DF is automatically cleared on RESET.

On NMOS, DF is unchanged when entering an interrupt of any kind. This can cause unexpected bugs in the interrupt handler if Decimal Mode is on when an interrupt occurs. On CMOS, DF is automatically cleared on interrupt. Upon returning from an interrupt, the processor restores the status register from the stack, including DF.


Half Cycles

The 6502 divides each clock cycle into two phases (ϕ1 and ϕ2):

  • During the ϕ1 half-cycle, no bus access occurs. This phase is dedicated to internal CPU operations.
  • During the ϕ2 half-cycle, the CPU accesses the external bus for memory reads/writes or I/O operations.

The use of half-cycles ensures that memory and I/O devices have predictable timing windows when the CPU will access the bus, while still allowing the CPU to perform internal operations in parallel.

Unlike most microprocessors, the 6502 does not make memory accesses on an "as needed" basis. It always does a fetch or store on every single clock cycle. When there isn't anything to be fetched or stored, a "garbage" fetch or store occurs. This is mainly of importance with the memory-mapped I/O devices:

  • On NMOS, when adding a carry to the MSB of an address, a fetch occurs at a garbage address. On CMOS, the last byte of the instruction is refetched.
  • On NMOS, 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. On CMOS, a second fetch is performed instead of a garbage store.


Pipelining

The 6502 CPU uses some sort of pipelining. If an instruction does not store data in memory on its last cycle, the processor can fetch the opcode of the next instruction while executing the last cycle. This is very primitive as the 6502 does not have an instruction cache nor even a prefetch queue. It relies on RAM to hold all program information.

As an example, the instruction EOR #$FF truly takes 3 cycles:

  • On the first cycle, the opcode $49 will be fetched
  • During the second cycle the processor decodes the opcode and fetches the parameter #$FF
  • On the third cycle, the processor will perform the operation and store the result in register A, but simultaneously it fetches the opcode for the next instruction

This is why the EOR instruction effectively takes only 2 cycles.

However, this pipelining only makes sense when looking at full cycles. If we break it down into half-cycles, there's no actual overlap. In fact, it's the other way around. If the previous instruction ends with a memory write, the CPU has to wait for a half-cycle before fetching the next instruction on the next ϕ2 half-cycle.


Adressing Modes

Addressing Mode Example Operation
Immediate LDA #$EA A ← $EA
Absolute LDA $0314 A ← M($0314)
Absolute,X LDA $0314,X A ← M($0314+X)
Absolute,Y LDA $0314,Y A ← M($0314+Y)
Zeropage LDA $02 A ← M($02)
Zeropage,X LDA $02,X A ← M($02+X)
Zeropage,Y LDA $02,Y A ← M($02+Y)
(Zeropage,X) LDA ($02,X) A ← M(PTR($02+X))
(Zeropage),Y LDA ($02),Y A ← M(PTR($02)+Y)


NMOS 6502 Instruction Set

Standard instructions

Cycles are shown in parenthesis for each opcode. p=1 if page is crossed. t=1 if branch is taken.

Mnemonic Addressing Modes Flags Operation Description
No arg A #$nn $nnnn $nnnn,X $nnnn,Y ($nnnn) $nn $nn,X $nn,Y ($nn,X) ($nn),Y rel N V B D I Z C
ADC 69 (2) 6D (4) 7D (4+p) 79 (4+p) 65 (3) 75 (4) 61 (6) 71 (5+p) N V - - - Z C A + M + CF → A, CF Add Memory to Accumulator with Carry
AND 29 (2) 2D (4) 3D (4+p) 39 (4+p) 25 (3) 35 (4) 21 (6) 31 (5+p) N - - - - Z - A ∧ M → A "AND" Memory with Accumulator
ASL 0A (2) 0E (6) 1E (7) 06 (5) 16 (6) N - - - - Z C CF ← /M7...M0/ ← 0 Arithmetic Shift Left
BCC 90 (2+t+p) - - - - - - - Branch on CF = 0 Branch on Carry Clear
BCS B0 (2+t+p) - - - - - - - Branch on CF = 1 Branch on Carry Set
BEQ F0 (2+t+p) - - - - - - - Branch on ZF = 1 Branch on Result Zero
BIT 2C (4) 24 (3) N V - - - Z - A ∧ M, M7 → NF, M6 → VF Test Bits in Memory with Accumulator
BMI 30 (2+t+p) - - - - - - - Branch on NF = 1 Branch on Result Minus
BNE D0 (2+t+p) - - - - - - - Branch on ZF = 0 Branch on Result Not Zero
BPL 10 (2+t+p) - - - - - - - Branch on NF = 0 Branch on Result Plus
BRK 00 (7) - - 1 - 1 - - PC + 2↓, [FFFE] → PCL, [FFFF] → PCH Force Interrupt
BVC 50 (2+t+p) - - - - - - - Branch on VF = 0 Branch on Overflow Clear
BVS 70 (2+t+p) - - - - - - - Branch on VF = 1 Branch on Overflow Set
CLC 18 (2) - - - - - - 0 0 → CF Clear Carry Flag
CLD D8 (2) - - - 0 - - - 0 → DF Clear Decimal Mode
CLI 58 (2) - - - - 0 - - 0 → IF Clear Interrupt Disable
CLV B8 (2) - 0 - - - - - 0 → VF Clear Overflow Flag
CMP C9 (2) CD (4) DD (4+p) D9 (4+p) C5 (3) D5 (4) C1 (6) D1 (5+p) N - - - - Z C A - M Compare Memory and Accumulator
CPX E0 (2) EC (4) E4 (3) N - - - - Z C X - M Compare Index Register X To Memory
CPY C0 (2) CC (4) C4 (3) N - - - - Z C Y - M Compare Index Register Y To Memory
DEC CE (6) DE (7) C6 (5) D6 (6) N - - - - Z - M - 1 → M Decrement Memory By One
DEX CA (2) N - - - - Z - X - 1 → X Decrement Index Register X By One
DEY 88 (2) N - - - - Z - Y - 1 → Y Decrement Index Register Y By One
EOR 49 (2) 4D (4) 5D (4+p) 59 (4+p) 45 (3) 55 (4) 41 (6) 51 (5+p) N - - - - Z - A ⊻ M → A "Exclusive OR" Memory with Accumulator
INC EE (6) FE (7) E6 (5) F6 (6) N - - - - Z - M + 1 → M Increment Memory By One
INX E8 (2) N - - - - Z - X + 1 → X Increment Index Register X By One
INY C8 (2) N - - - - Z - Y + 1 → Y Increment Index Register Y By One
JMP 4C (3) 6C (5) - - - - - - - [PC + 1] → PCL, [PC + 2] → PCH Jump
JSR 20 (6) - - - - - - - PC + 2↓, [PC + 1] → PCL, [PC + 2] → PCH Jump To Subroutine
LDA A9 (2) AD (4) BD (4+p) B9 (4+p) A5 (3) B5 (4) A1 (6) B1 (5+p) N - - - - Z - M → A Load Accumulator with Memory
LDX A2 (2) AE (4) BE (4+p) A6 (3) B6 (4) N - - - - Z - M → X Load Index Register X From Memory
LDY A0 (2) AC (4) BC (4+p) A4 (3) B4 (4) N - - - - Z - M → Y Load Index Register Y From Memory
LSR 4A (2) 4E (6) 5E (7) 46 (5) 56 (6) 0 - - - - Z C 0 → /M7...M0/ → CF Logical Shift Right
NOP EA (2) - - - - - - - No operation No Operation
ORA 09 (2) 0D (4) 1D (4+p) 19 (4+p) 05 (3) 15 (4) 01 (6) 11 (5+p) N - - - - Z - A ∨ M → A "OR" Memory with Accumulator
PHA 48 (3) - - - - - - - A↓ Push Accumulator On Stack
PHP 08 (3) - - 1 - - - - P↓ Push Processor Status on Stack
PLA 68 (4) N - - - - Z - (S)↑ → A Pull Accumulator From Stack
PLP 28 (4) N V - D I Z C (S)↑ → P Pull Processor Status From Stack
ROL 2A (2) 2E (6) 3E (7) 26 (5) 36 (6) N - - - - Z C CF ← /M7...M0/ ← CF Rotate One Bit Left (Memory or Accumulator)
ROR 6A (2) 6E (6) 7E (7) 66 (5) 76 (6) N - - - - Z C CF → /M7...M0/ → CF Rotate One Bit Right (Memory or Accumulator)
RTI 40 (6) N V - D I Z C (S)↑ → P, (S)↑ → PCL, (S)↑ → PCH Return From Interrupt
RTS 60 (6) - - - - - - - (S)↑ → PCL, (S)↑ → PCH, PC + 1 → PC Return From Subroutine
SBC E9 (2) ED (4) FD (4+p) F9 (4+p) E5 (3) F5 (4) E1 (6) F1 (5+p) N V - - - Z C A - M - (1 - CF) → A Subtract Memory from Accumulator with Borrow
SEC 38 (2) - - - - - - 1 1 → CF Set Carry Flag
SED F8 (2) - - - 1 - - - 1 → DF Set Decimal Mode
SEI 78 (2) - - - - 1 - - 1 → IF Set Interrupt Disable
STA 8D (4) 9D (5) 99 (5) 85 (3) 95 (4) 81 (6) 91 (6) - - - - - - - A → M Store Accumulator in Memory
STX 8E (4) 86 (3) 96 (4) - - - - - - - X → M Store Index X in Memory
STY 8C (4) 84 (3) 94 (4) - - - - - - - Y → M Store Index Y in Memory
TAX AA (2) N - - - - Z - A → X Transfer Accumulator to Index X
TAY A8 (2) N - - - - Z - A → Y Transfer Accumulator to Index Y
TSX BA (2) N - - - - Z - S → X Transfer Stack Pointer to Index X
TXA 8A (2) N - - - - Z - X → A Transfer Index X to Accumulator
TXS 9A (2) - - - - - - - X → S Transfer Index X to Stack Pointer
TYA 98 (2) N - - - - Z - Y → A Transfer Index Y to Accumulator

Illegal instructions

Opcodes in red are unstable. Only 2 of those 7 opcodes ($8B, $AB) are actually unstable in the sense that they may produce a truly unpredictable result. The other 5 opcodes actually produce predictable results – but the conditions under which they do that and the produced results are a bit unexpected.

Mnemonic Combines Addressing Modes Flags Operation Description
No arg #$nn $nnnn $nnnn,X $nnnn,Y $nn $nn,X $nn,Y ($nn,X) ($nn),Y N V B D I Z C
ANC (ANC2) AND + ASL/ROL 0B, 2B (2) N - - - - Z C A ∧ M → A, NF → CF "AND" Memory with Accumulator then Move Negative Flag to Carry Flag
ARR AND + ROR 6B (2) N V - - - Z C (A ∧ M) / 2 → A "AND" Accumulator then Rotate Right
ASR (ALR) AND + LSR 4B (2) 0 - - - - Z C (A ∧ M) / 2 → A "AND" then Logical Shift Right
DCP (DCM) DEC + CMP CF (6) DF (7) DB (7) C7 (5) D7 (6) C3 (8) D3 (8) N - - - - Z C M - 1 → M, A - M Decrement Memory By One then Compare with Accumulator
ISC (ISB, INS) INC + SBC EF (6) FF (7) FB (7) E7 (5) F7 (6) E3 (8) F3 (8) N V - - - Z C M + 1 → M, A - M → A Increment Memory By One then SBC then Subtract Memory from Accumulator with Borrow
JAM (KIL, HLT) 02, 12, 22,

32, 42, 52,

62, 72, 92,

B2, D2, F2 (X)

- - - - - - - Stop execution Halt the CPU
LAS (LAR) STA/TXS + LDA/STX BB (4+p) N - - - - Z - M ∧ S → A, X, S "AND" Memory with Stack Pointer
LAX (LXA) LDA + LDX AB (2) AF (4) BF (4+p) A7 (3) B7 (4) A3 (6) B3 (5+p) N - - - - Z - M → A, X Load Accumulator and Index Register X From Memory
NOP (DOP, TOP) 1A, 3A, 5A,

7A, DA, FA (2)

80, 82, 89,

C2, E2 (2)

0C (4) 1C, 3C, 5C,

7C, DC, FC (4+p)

04, 44, 64 (3) 14, 34, 54,

74, D4, F4 (4)

- - - - - - - No operation No Operation
RLA ROL + AND 2F (6) 3F (7) 3B (7) 27 (5) 37 (6) 23 (8) 33 (8) N - - - - Z C CF ← /M7...M0/ ← CF, A ∧ M → A Rotate Left then "AND" with Accumulator
RRA ROR + ADC 6F (6) 7F (7) 7B (7) 67 (5) 77 (6) 63 (8) 73 (8) N V - - - Z C CF → /M7...M0/ → CF, A + M + CF → A Rotate Right and Add Memory to Accumulator
SAX (AXS, AAX) STA + STX 8F (4) 87 (3) 97 (4) 83 (6) - - - - - - - A ∧ X → M Store Accumulator "AND" Index Register X in Memory
SBC (USBC) SBC + NOP EB (2) N V - - - Z C A - M - ~CF → A Subtract Memory from Accumulator with Borrow
SBX (AXS, SAX) CMP + DEX CB (2) N - - - - Z C (A ∧ X) - M → X Subtract Memory from Accumulator "AND" Index Register X
SHA (AHX, AXA) STA/STX/STY 9F (5) 93 (6) - - - - - - - A ∧ X ∧ V → M Store Accumulator "AND" Index Register X "AND" Value
SHS (TAS, XAS) STA/TXS + LDA/TSX 9B (5) - - - - - - - A ∧ X → S, S ∧ (H + 1) → M Transfer Accumulator "AND" Index Register X to Stack Pointer then Store Stack Pointer "AND" Hi-Byte In Memory
SHX (SXA, XAS) STA/STX/STY 9E (5) - - - - - - - X ∧ (H + 1) → M Store Index Register X "AND" Value
SHY (SYA, SAY) STA/STX/STY 9C (5) - - - - - - - Y ∧ (H + 1) → M Store Index Register Y "AND" Value
SLO (ASO) ASL + ORA 0F (6) 1F (7) 1B (7) 07 (5) 17 (6) 03 (8) 13 (8) N - - - - Z C M * 2 → M, A ∨ M → A Arithmetic Shift Left then "OR" Memory with Accumulator
SRE (LSE) LSR + EOR 4F (6) 5F (7) 5B (7) 47 (5) 57 (6) 43 (8) 53 (8) N - - - - Z C M / 2 → M, A ⊻ M → A Logical Shift Right then "Exclusive OR" Memory with Accumulator
XAA (ANE) TXA + AND 8B (2) N - - - - Z - (A ∨ V) ∧ X ∧ M → A Non-deterministic Operation of Accumulator, Index Register X, Memory and Bus Contents


Opcodes

The 6502 follows a 3-3-2 opcode bit pattern. If we arrange the opcode table in a slightly different way than it is usually done, we can observe some interesting symmetries:

Opc Mnemonic
00 BRK
04 NOP zpg
08 PHP
0C NOP abs
10 BPL rel
14 NOP zpg,X
18 CLC
1C NOP abs,X
Opc Mnemonic
20 JSR abs
24 BIT zpg
28 PLP
2C BIT abs
30 BMI rel
34 NOP zpg,X
38 SEC
3C NOP abs,X
Opc Mnemonic
40 RTI
44 NOP zpg
48 PHA
4C JMP abs
50 BVC rel
54 NOP zpg,X
58 CLI
5C NOP abs,X
Opc Mnemonic
60 RTS
64 NOP zpg
68 PLA
6C JMP zpg
70 BVS rel
74 NOP zpg,X
78 SEI
7C NOP abs,X
Opc Mnemonic
80 NOP #
84 STY zpg
88 DEY
8C STY abs
90 BCC rel
94 STY zpg,X
98 TYA
9C SHY abs,X
Opc Mnemonic
A0 LDY #
A4 LDY zpg
A8 TAY
AC LDY abs
B0 BCS rel
B4 LDY zpg,X
B8 CLV
BC LDY abs,X
Opc Mnemonic
C0 CPY #
C4 CPY zpg
C8 INY
CC CPY abs
D0 BNE rel
D4 NOP zpg,X
D8 CLD
DC NOP abs,X
Opc Mnemonic
E0 CPX #
E4 CPX zpg
E8 INX
EC CPX abs
F0 BEQ rel
F4 NOP zpg,X
F8 SED
FC NOP abs,X
Opc Mnemonic
01 ORA (zpg,X)
05 ORA zpg
09 ORA #
0D ORA abs
11 ORA (zpg),Y
15 ORA zpg,X
19 ORA abs,Y
1D ORA abs,X
Opc Mnemonic
21 AND (zpg,X)
25 AND zpg
29 AND #
2D AND abs
31 AND (zpg),Y
35 AND zpg,X
39 AND abs,Y
3D AND abs,X
Opc Mnemonic
41 EOR (zpg,X)
45 EOR zpg
49 EOR #
4D EOR abs
51 EOR (zpg),Y
55 EOR zpg,X
59 EOR abs,Y
5D EOR abs,X
Opc Mnemonic
61 ADC (zpg,X)
65 ADC zpg
69 ADC #
6D ADC abs
71 ADC (zpg),Y
75 ADC zpg,X
79 ADC abs,Y
7D ADC abs,X
Opc Mnemonic
81 STA (zpg,X)
85 STA zpg
89 NOP #
8D STA abs
91 STA (zpg),Y
95 STA zpg,X
99 STA abs,Y
9D STA abs,X
Opc Mnemonic
A1 LDA (zpg,X)
A5 LDA zpg
A9 LDA #
AD LDA abs
B1 LDA (zpg),Y
B5 LDA zpg,X
B9 LDA abs,Y
BD LDA abs,X
Opc Mnemonic
C1 CMP (zpg,X)
C5 CMP zpg
C9 CMP #
CD CMP abs
D1 CMP (zpg),Y
D5 CMP zpg,X
D9 CMP abs,Y
DD CMP abs,X
Opc Mnemonic
E1 SBC (zpg,X)
E5 SBC zpg
E9 SBC #
ED SBC abs
F1 SBC (zpg),Y
F5 SBC zpg,X
F9 SBC abs,Y
FD SBC abs,X
Opc Mnemonic
02 JAM
06 ASL zpg
0A ASL A
0E ASL abs
12 JAM
16 ASL zpg,X
1A NOP
1E ASL abs,X
Opc Mnemonic
22 JAM
26 ROL zpg
2A ROL A
2E ROL abs
32 JAM
36 ROL zpg,X
3A NOP
3E ROL abs,X
Opc Mnemonic
42 JAM
46 LSR zpg
4A LSR A
4E LSR abs
52 JAM
56 LSR zpg,X
5A NOP
5E LSR abs,X
Opc Mnemonic
62 JAM
66 ROR zpg
6A ROR A
6E ROR abs
72 JAM
76 ROR zpg,X
7A NOP
7E ROR abs,X
Opc Mnemonic
82 NOP #
86 STX zpg
8A TXA
8E STX abs
92 JAM
96 STX zpg,Y
9A TXS
9E SHX abs,Y
Opc Mnemonic
A2 LDX #
A6 LDX zpg
AA TAX
AE LDX abs
B2 JAM
B6 LDX zpg,Y
BA TSX
BE LDX abs,X
Opc Mnemonic
C2 NOP #
C6 DEC zpg
CA DEX
CE DEC abs
D2 JAM
D6 DEC zpg,X
DA NOP
DE DEC abs,X
Opc Mnemonic
E2 NOP #
E6 INC zpg
EA NOP
EE INC abs
F2 JAM
F6 INC zpg,X
FA NOP
FE INC abs,X
Opc Mnemonic
03 SLO (zpg,X)
07 SLO zpg
0B ANC #
0F SLO abs
13 SLO (zpg),Y
17 SLO zpg,X
1B SLO abs,Y
1F SLO abs,X
Opc Mnemonic
23 RLA (zpg,X)
27 RLA zpg
2B ANC #
2F RLA abs
33 RLA (zpg),Y
37 RLA zpg,X
3B RLA abs,Y
3F RLA abs,X
Opc Mnemonic
43 SRE (zpg,X)
47 SRE zpg
4B ASR #
4F SRE abs
53 SRE (zpg),Y
57 SRE zpg,X
5B SRE abs,Y
5F SRE abs,X
Opc Mnemonic
63 RRA (zpg,X)
67 RRA zpg
6B ARR #
6F RRA abs
73 RRA (zpg),Y
77 RRA zpg,X
7B RRA abs,Y
7F RRA abs,X
Opc Mnemonic
83 SAX (zpg,X)
87 SAX zpg
8B XAA #
8F SAX abs
93 SHA (zpg),Y
97 SAX zpg,Y
9B SHS abs,Y
9F SHA abs,Y
Opc Mnemonic
A3 LAX (zpg,X)
A7 LAX zpg
AB LXA #
AF LAX abs
B3 LAX (zpg),Y
B7 LAX zpg,Y
BB LAS abs,Y
BF LAX abs,Y
Opc Mnemonic
C3 DCP (zpg,X)
C7 DCP zpg
CB SBX #
CF DCP abs
D3 DCP (zpg),Y
D7 DCP zpg,X
DB DCP abs,Y
DF DCP abs,X
Opc Mnemonic
E3 ISC (zpg,X)
E7 ISC zpg
EB SBC #
EF ISC abs
F3 ISC (zpg),Y
F7 ISC zpg,X
FB ISC abs,Y
FF ISC abs,X

Opcodes in bold are illegal. Opcodes in red are unstable.


Oddities

  • On NMOS, an indirect JMP will behave unexpectedly when the indirect address crosses a page boundary, because the 6502 does not add the carry to calculate the address of the high byte. For example, JMP ($19FF) will use the contents of $19FF and $1900 for the JMP address. On CMOS, this issue was fixed, at the cost of 1 additional cycle. In our example, JMP ($19FF) will use the contents of $19FF and $2000 for the JMP address.
  • Some instructions, particularly those involving branches or indexed addressing modes, incur an extra cycle if the processor has to cross a memory page boundary. This is problematic for time-sensitive code.
  • Conditional jumps are only 8-bit relative. And unconditional jumps are only 16-bit absolute.
  • ADC is the only command for addition. To perform an addition without carry, the carry flag must be cleared manually first. Same with SBC for subtract.
  • The CLV (Clear Overflow Flag) instruction exist but not the SEV (Set Overflow Flag) instruction.
  • The NOP instruction takes 2 full-cycles. This is the minimum amount of cycles an instruction can take.
  • The alternate NOPs are not created equal. Some have one- or two-byte operands (which they don't do anything with), and they take different amounts of time to execute.


Block Diagrams

Simple view

Mcs6502-block-diagram.svg

Detailed view

CPU 6502 Detailed Block Diagram.jpg


CPU Pinout

6502CPU Pinout.gif

Notes:

  • SYNC is an output signal. It is high at T0.
  • S.O. is an input signal, which stands for Set Overflow. It allows the hardware to affect VF independently of the software.
  • Some pins are modified in CPU variants.


Chip Variants

  • The ROR instruction didn't exist in the very earliest (pre-1977) chips.
  • The 6502 core used inside the NES is missing the Decimal Mode feature.
  • The 6507 CPU, used in the Atari VCS, has only 13 address lines. So it can only address 8KB instead of 64KB. It also lacks the IRQ and NMI interrupt lines.
  • The 6510 CPU, used in the Commodore 64, is a 6502 with an additional AEC pin that puts the bus in high impedance mode. It also includes a 6-bit I/O port that occupies addresses 0 and 1.
  • The disk drive of the Commodore 64 has its own 6502 processor that acts as a floppy disk controller (FDC) and as a disk operating system (DOS) processor. It can also be used as a general coprocessor for the main system.
  • The 6502C used in Atari 8-bit computer range, adds an additional HALT pin for DMA. The 6502C is otherwise a regular NMOS 6502, not to be confused with the CMOS 65C02.
  • The CMOS 65C02 fixed multiple bugs of the original NMOS 6502, but also removed access to all illegal instructions. Some cycle counts have been modified and some extra instructions have been added. In fact, there are multiple implementations of the 65C02 (WDC 65C02, WDC 65C02S, Rockwell R65C02, CSG 65CE02, ...), each with its own variant of the instruction set.
  • The HuC6280, used in the PC-Engine gaming console, is an improved version of the CMOS 65C02.
  • The 65C816, used in the SNES and the Apple IIGS, is a 16-bit version of the 65C02. It contains a compatibillity mode, enabled by default upon reset, that makes it behave like a regular 65C02.
  • The Sony SPC700 sound CPU used inside the SNES also behaves similarly to a 6502 with some extensions. Source


Links