NES CPU: 6502


Registers

Abbrevations A X Y S P PC
Names Accumulator X Register Y Register Stack Pointer Status Register Program Counter
Size 8-bit 8-bit 8-bit 8-bit 8-bit 16-bit
Comments general purpose, ALU general purpose, index register general purpose, index register used to push to/ pull from tde stack contains several flags; see below address of the current instruction

Flags

Bit 7 6 5 4 3 2 1 0
Abbrevation N V - B D I Z C
Name Negative Overflow Unused Unused Decimal Interrupt Disable Zero Carry
Set/Reset CLV SED, CLD SEI, CLI SEC, CLC
Comment bit 7 of the result of an operation (sign bit) set by ADC and SBC if signed result would have overflown unused; always 1 technically unused; but when P is pushed to the stack, this bit may be either 0 or 1, depending on the instruction: Note: when P is pushed, the I flag is set as well (unless the operation was PHP) no effect on the NES when set, all interrupts except NMI are inhibited;
automatically set when an IRQ occurs, and restored by the interrupt handler's RTI
clearing this flag when an IRQ is pending causes the interrupt to trigger immediately
set if the result of an operation is equal to 0 set to the carry of the addition by ADC;
set if no borrow was the result ("greater than or equal to") by SBC and CMP;
set to the bit shifted out by ASL, LSR, ROL, and ROR
Download as JSON Download as CSV

Addressing Modes + Cycle timings

Download as JSON
Registers: The table is divided up into 4 columns: Operation pseudo-code (C-like): If there is additional information for a certain steps, it is marked with one or more asterisks* and explained below the table.

Implicit (IMP)

Instructions:
(BRK, RTI, RTS, PHA, PHP, PHA, and PHP have an implicit addressing mode, but work differently)
Example: PHP or ASL A
Operation: data = A (depending on the operation; not actually stored in the data register)

Immediate (IMM)

Instructions:
Example: ORA #$69
Operation: data = arg (8-bit)

Indirect (IND)

Instructions:
Example: JMP ($CAFE)
Operation: PC = [arg] (16-bit)

Relative (REL)

Instructions:
Example: BEQ label   (label is converted into a signed offset by the compiler)
Operation: PC = PC + arg (8-bit, signed)

Absolute (ABS)

(JMP and JSR have an absolute addressing mode, but work differently)
Example: ADC $4269
Operation: data = [arg] (16-bit)

Read

Instructions:

Read-Modify-Write

Instructions:

Write

Instructions:

Absolute indexed X/Y (ABX, ABY)

Note: I represents either the X or Y register, depending on the mode.
Example: LDX $1234,X or EOR $5566,Y
Operation: data = [arg + I] (16-bit)

Read

Instructions:

Read-Modify-Write

Instructions:
Note: This mode does not exist for ABY (for official opcodes)

Write

Instructions:

Zero Page (ZPG)

Example: CMP $7F
Operation: data = [arg] (8-bit)

Read

Instructions:

Read-Modify-Write

Instructions:

Write

Instructions:

Zero Page indexed X/Y (ZPX, ZPY)

Note: I represents either the X or Y register, depending on the mode.
Example: STY $EE,X or LAX $DD,Y
Operation: data = [(arg + I) & $FF] (8-bit)

Read

Instructions:

Read-Modify-Write

Instructions:
Note: This mode does not exist for ZPY (for official opcodes)

Write

Instructions:

Indexed Indirect X (IZX)

Example: LDA ($AB,X)
Operation: data = [[(arg + X) & $FF] + ([(arg + X + 1) & $FF] << 8)] (8-bit)

Read

Instructions:

Read-Modify-Write

Instructions:

Write

Instructions:

Indirect Indexed Y (IZY)

Example: SBC ($EF),X
Operation: data = [[arg] + ([(arg + 1) & $FF] << 8) + Y] (8-bit)

Read

Instructions:

Read-Modify-Write

Instructions:

Write

Instructions:

Uncategorized

These instructions don't follow the rules of the addressing modes above, despite some of them being labeled as such (e.g. JMP abs)

BRK

Operation: [S--] = PCH; [S--] = PCL; [S--] = P; PC = [$FFFE] | ([$FFFF] << 8)
(see B flag for more information)

RTI

Operation: P = [++S]; PC = ([++S] << 8) | [++S]
(see I flag for more information)

RTS

Operation: PC = ([++S] << 8) | [++S]

PHA, PHP

Operation: [S--] = A/P
(see B flag for more information)

PLA, PLP

Operation: A/P = [++S]

JSR

Example: JSR $BEEF
Operation: [S--] = PCH; [S--] = PCL; PC = arg (16-bit)

JMP

Example: JMP $BABE
Operation: PC = arg (16-bit)

Instructions

Operation pseudo-code (C-like):
Mnemonic Operation NV-BDIZC

Unofficial Instructions

Mnemonic Operation NV-BDIZC Stability
Some of the illegal opcodes are just combinations of two operations: Quirks with other operations:

Interrupts

Work in progress!

Sources

These are the sources I used to gather all this information: