Skip to main content

MOS 6502 Instruction Set Reference

Processor: MOS Technology 6502 Architecture: 8-bit Addressing: 16-bit address bus (64KB) Released: 1975

Overview

The MOS 6502 is an 8-bit microprocessor with a 16-bit address space. It features a simple, elegant instruction set with 56 instructions and 13 addressing modes.

Registers

  • A - Accumulator (8-bit)
  • X - X Index Register (8-bit)
  • Y - Y Index Register (8-bit)
  • SP - Stack Pointer (8-bit, page 1: $0100-$01FF)
  • PC - Program Counter (16-bit)
  • P - Processor Status Flags (8-bit)

Status Flags (P Register)

BitFlagNameDescription
7NNegativeSet if bit 7 of result is set
6VOverflowSet on signed arithmetic overflow
5-(Unused)Always 1
4BBreakSet when BRK instruction executed
3DDecimalDecimal mode flag (BCD arithmetic)
2IInterrupt DisableSet to disable IRQ interrupts
1ZZeroSet if result is zero
0CCarryCarry/borrow flag

Addressing Modes

ModeSyntaxExampleDescription
Implied-TAXNo operand needed
AccumulatorALSR AOperates on accumulator
Immediate#$nnLDA #$42Operand is constant value
Zero Page$nnLDA $80Address in page 0 ($00-$FF)
Zero Page,X$nn,XLDA $80,XZero page address + X
Zero Page,Y$nn,YLDX $80,YZero page address + Y
Absolute$nnnnLDA $2000Full 16-bit address
Absolute,X$nnnn,XLDA $2000,XAbsolute address + X
Absolute,Y$nnnn,YLDA $2000,YAbsolute address + Y
Indirect($nnnn)JMP ($2000)Address stored at location
Indexed Indirect($nn,X)LDA ($80,X)(Zero page + X) pointer
Indirect Indexed($nn),YLDA ($80),Y(Zero page pointer) + Y
RelativelabelBNE loopPC-relative branch (-128 to +127)

Instruction Set by Category

Load/Store Operations

MnemonicDescriptionFlagsBytesCycles
LDALoad AccumulatorN Z2-32-5
LDXLoad X RegisterN Z2-32-4
LDYLoad Y RegisterN Z2-32-4
STAStore Accumulator-2-33-5
STXStore X Register-2-33-4
STYStore Y Register-2-33-4

Register Transfer

MnemonicDescriptionFlagsBytesCycles
TAXTransfer A to XN Z12
TAYTransfer A to YN Z12
TXATransfer X to AN Z12
TYATransfer Y to AN Z12
TSXTransfer SP to XN Z12
TXSTransfer X to SP-12

Stack Operations

MnemonicDescriptionFlagsBytesCycles
PHAPush Accumulator-13
PHPPush Processor Status-13
PLAPull AccumulatorN Z14
PLPPull Processor StatusAll14

Arithmetic Operations

MnemonicDescriptionFlagsBytesCycles
ADCAdd with CarryN V Z C2-32-5
SBCSubtract with CarryN V Z C2-32-5
INCIncrement MemoryN Z2-35-6
INXIncrement XN Z12
INYIncrement YN Z12
DECDecrement MemoryN Z2-35-6
DEXDecrement XN Z12
DEYDecrement YN Z12

Logical Operations

MnemonicDescriptionFlagsBytesCycles
ANDLogical ANDN Z2-32-5
ORALogical ORN Z2-32-5
EORLogical XORN Z2-32-5
BITBit TestN V Z2-33-4

Shift and Rotate

MnemonicDescriptionFlagsBytesCycles
ASLArithmetic Shift LeftN Z C1-32-6
LSRLogical Shift RightN Z C1-32-6
ROLRotate LeftN Z C1-32-6
RORRotate RightN Z C1-32-6

Comparison Operations

MnemonicDescriptionFlagsBytesCycles
CMPCompare AccumulatorN Z C2-32-5
CPXCompare X RegisterN Z C2-32-4
CPYCompare Y RegisterN Z C2-32-4

Branch Instructions

MnemonicDescriptionFlagsBytesCycles
BCCBranch if Carry Clear-22-4
BCSBranch if Carry Set-22-4
BEQBranch if Equal (Z=1)-22-4
BNEBranch if Not Equal (Z=0)-22-4
BMIBranch if Minus (N=1)-22-4
BPLBranch if Plus (N=0)-22-4
BVCBranch if Overflow Clear-22-4
BVSBranch if Overflow Set-22-4

Jump and Subroutine

MnemonicDescriptionFlagsBytesCycles
JMPJump-33-5
JSRJump to Subroutine-36
RTSReturn from Subroutine-16
RTIReturn from InterruptAll16

Flag Operations

MnemonicDescriptionFlagsBytesCycles
CLCClear Carry FlagC=012
CLDClear Decimal ModeD=012
CLIClear Interrupt DisableI=012
CLVClear Overflow FlagV=012
SECSet Carry FlagC=112
SEDSet Decimal ModeD=112
SEISet Interrupt DisableI=112

System Operations

MnemonicDescriptionFlagsBytesCycles
BRKForce BreakB=1, I=117
NOPNo Operation-12

Instruction Details

ADC - Add with Carry

Operation: A = A + M + C

Description: Adds the contents of memory and the carry flag to the accumulator.

Addressing Modes:

ADC #$42      ; Immediate
ADC $80 ; Zero Page
ADC $80,X ; Zero Page,X
ADC $2000 ; Absolute
ADC $2000,X ; Absolute,X
ADC $2000,Y ; Absolute,Y
ADC ($80,X) ; Indexed Indirect
ADC ($80),Y ; Indirect Indexed

Flags Affected: N V Z C

Notes: In decimal mode (D=1), performs BCD addition.

AND - Logical AND

Operation: A = A & M

Description: Performs bitwise AND between accumulator and memory.

Addressing Modes:

AND #$42      ; Immediate
AND $80 ; Zero Page
AND $80,X ; Zero Page,X
AND $2000 ; Absolute
AND $2000,X ; Absolute,X
AND $2000,Y ; Absolute,Y
AND ($80,X) ; Indexed Indirect
AND ($80),Y ; Indirect Indexed

Flags Affected: N Z

ASL - Arithmetic Shift Left

Operation: C ← [7][6][5][4][3][2][1][0] ← 0

Description: Shifts all bits left one position. Bit 0 is set to 0 and bit 7 is shifted into the carry flag.

Addressing Modes:

ASL A         ; Accumulator
ASL $80 ; Zero Page
ASL $80,X ; Zero Page,X
ASL $2000 ; Absolute
ASL $2000,X ; Absolute,X

Flags Affected: N Z C

BCC - Branch if Carry Clear

Operation: Branch if C = 0

Description: If the carry flag is clear, adds the relative displacement to the program counter.

Addressing Mode:

BCC label     ; Relative (-128 to +127 bytes)

Flags Affected: None

Cycles: 2 if no branch, 3 if branch taken, 4 if branch crosses page boundary

BIT - Bit Test

Operation: N = M[7], V = M[6], Z = !(A & M)

Description: Tests bits in memory with accumulator. Sets N and V from memory bits 7 and 6. Sets Z if (A & M) is zero.

Addressing Modes:

BIT $80       ; Zero Page
BIT $2000 ; Absolute

Flags Affected: N V Z

BRK - Force Break

Operation: PC+2↓, [PC+1:PC]=[FFFE:FFFF]

Description: Forces an interrupt. Pushes PC+2 and status register to stack, then loads interrupt vector from $FFFE/$FFFF.

Addressing Mode:

BRK           ; Implied

Flags Affected: B I

Notes: Sets B flag to distinguish from hardware IRQ.

JMP - Jump

Operation: PC = address

Description: Sets the program counter to the specified address.

Addressing Modes:

JMP $2000     ; Absolute
JMP ($2000) ; Indirect

Flags Affected: None

Notes: Indirect mode has a page boundary bug - if address is $xxFF, high byte is fetched from $xx00 instead of $xx+1:00.

JSR - Jump to Subroutine

Operation: PC+2↓, PC = address

Description: Pushes the address of the next instruction minus one to the stack, then jumps to the subroutine.

Addressing Mode:

JSR $2000     ; Absolute

Flags Affected: None

Cycles: 6

LDA - Load Accumulator

Operation: A = M

Description: Loads a byte from memory into the accumulator.

Addressing Modes:

LDA #$42      ; Immediate
LDA $80 ; Zero Page
LDA $80,X ; Zero Page,X
LDA $2000 ; Absolute
LDA $2000,X ; Absolute,X
LDA $2000,Y ; Absolute,Y
LDA ($80,X) ; Indexed Indirect
LDA ($80),Y ; Indirect Indexed

Flags Affected: N Z

SBC - Subtract with Carry

Operation: A = A - M - !C

Description: Subtracts memory and the inverse of carry from the accumulator.

Addressing Modes:

SBC #$42      ; Immediate
SBC $80 ; Zero Page
SBC $80,X ; Zero Page,X
SBC $2000 ; Absolute
SBC $2000,X ; Absolute,X
SBC $2000,Y ; Absolute,Y
SBC ($80,X) ; Indexed Indirect
SBC ($80),Y ; Indirect Indexed

Flags Affected: N V Z C

Notes: In decimal mode (D=1), performs BCD subtraction. Carry flag is set if no borrow occurred.

Timing Notes

  • Cycles listed are typical. Add 1 cycle for page boundary crossing on indexed modes.
  • Add 1 cycle for branches taken, 2 cycles if branch crosses page boundary.
  • Stack operations (PHA, PLA, PHP, PLP, JSR, RTS, RTI, BRK) are slower due to stack access.

Bugs and Quirks

  1. JMP Indirect Page Boundary Bug: If the low byte of the indirect address is $FF, the high byte is fetched from $xx00 instead of $(xx+1)00.

  2. Decimal Mode Flags: In decimal mode, N, V, and Z flags may be invalid after ADC/SBC.

  3. ROR/ROL Timing: These instructions take 1 extra cycle when operating on memory.

References

  • MOS Technology 6502 Programming Manual (1976)
  • 6502 Assembly Language Programming by Lance Leventhal (1979)
  • Western Design Center W65C02S Datasheet

See Also