6502 ASM

6502 Processor Instruction Set

6502 Registers & Status Flags

A (Accumulator)

8-bit primary register

X (Index X)

8-bit index register

Y (Index Y)

8-bit index register

SP (Stack Pointer)

8-bit ($0100-$01FF)

PC (Program Counter)

16-bit address

P (Status Register)

NV-BDIZC flags

Status Register (P) Flags

BitFlagNameDescription
7NNegativeSet if result bit 7 is set
6VOverflowSet on signed overflow
5-UnusedAlways 1
4BBreakSet when BRK executed
3DDecimalBinary/Decimal mode
2IInterruptIRQ disable
1ZZeroSet if result is zero
0CCarryCarry/Borrow flag

Addressing Modes

ModeFormatExampleBytesDescription
Immediate#nnLDA #$FF2Use value nn
Zero PagennLDA $442Address $00nn
Zero Page,Xnn,XLDA $44,X2Address $00nn+X
Zero Page,Ynn,YLDX $44,Y2Address $00nn+Y
AbsolutennnnLDA $C0003Address $nnnn
Absolute,Xnnnn,XLDA $C000,X3Address $nnnn+X
Absolute,Ynnnn,YLDA $C000,Y3Address $nnnn+Y
Indirect(nnnn)JMP ($FFFC)3Address at $nnnn
Indexed Indirect(nn,X)LDA ($44,X)2Address at $00nn+X
Indirect Indexed(nn),YLDA ($44),Y2Address at $00nn, then +Y
Implied-INX1No operand
AccumulatorAROL A1Operate on A
RelativennBEQ $062PC + signed nn

Load/Store Operations

MnemonicOperationFlagsModesCycles
LDALoad Accumulator (A = M)N Zimm, zp, zpx, abs, abx, aby, idx, idy2-6
LDXLoad X Register (X = M)N Zimm, zp, zpy, abs, aby2-4
LDYLoad Y Register (Y = M)N Zimm, zp, zpx, abs, abx2-4
STAStore Accumulator (M = A)-zp, zpx, abs, abx, aby, idx, idy3-6
STXStore X Register (M = X)-zp, zpy, abs3-4
STYStore Y Register (M = Y)-zp, zpx, abs3-4

Register Transfers

MnemonicOperationFlagsCycles
TAXTransfer A to X (X = A)N Z2
TAYTransfer A to Y (Y = A)N Z2
TXATransfer X to A (A = X)N Z2
TYATransfer Y to A (A = Y)N Z2
TSXTransfer SP to X (X = SP)N Z2
TXSTransfer X to SP (SP = X)-2

Stack Operations

MnemonicOperationFlagsCyclesNotes
PHAPush A on Stack-3SP--
PHPPush P on Stack-3SP--
PLAPull A from StackN Z4SP++
PLPPull P from StackAll4SP++
Stack grows downward from $01FF to $0100

Arithmetic Operations

MnemonicOperationFlagsModesCycles
ADCAdd with Carry (A = A + M + C)N V Z Cimm, zp, zpx, abs, abx, aby, idx, idy2-6
SBCSubtract with Carry (A = A - M - !C)N V Z Cimm, zp, zpx, abs, abx, aby, idx, idy2-6
Always set carry before subtraction (SEC) and clear before addition (CLC) unless using carry intentionally

Logical Operations

MnemonicOperationFlagsModesCycles
ANDLogical AND (A = A & M)N Zimm, zp, zpx, abs, abx, aby, idx, idy2-6
ORALogical OR (A = A | M)N Zimm, zp, zpx, abs, abx, aby, idx, idy2-6
EORExclusive OR (A = A ^ M)N Zimm, zp, zpx, abs, abx, aby, idx, idy2-6

Shifts & Rotates

MnemonicOperationFlagsModesCycles
ASLArithmetic Shift Left (C ← [76543210] ← 0)N Z Cacc, zp, zpx, abs, abx2-7
LSRLogical Shift Right (0 → [76543210] → C)N Z Cacc, zp, zpx, abs, abx2-7
ROLRotate Left (C ← [76543210] ← C)N Z Cacc, zp, zpx, abs, abx2-7
RORRotate Right (C → [76543210] → C)N Z Cacc, zp, zpx, abs, abx2-7

Increments & Decrements

MnemonicOperationFlagsModesCycles
INCIncrement Memory (M = M + 1)N Zzp, zpx, abs, abx5-7
INXIncrement X (X = X + 1)N Zimpl2
INYIncrement Y (Y = Y + 1)N Zimpl2
DECDecrement Memory (M = M - 1)N Zzp, zpx, abs, abx5-7
DEXDecrement X (X = X - 1)N Zimpl2
DEYDecrement Y (Y = Y - 1)N Zimpl2

Branch Instructions

MnemonicOperationConditionCycles
BCCBranch if Carry ClearC = 02-4
BCSBranch if Carry SetC = 12-4
BEQBranch if Equal (Zero)Z = 12-4
BNEBranch if Not EqualZ = 02-4
BMIBranch if Minus (Negative)N = 12-4
BPLBranch if Plus (Positive)N = 02-4
BVCBranch if Overflow ClearV = 02-4
BVSBranch if Overflow SetV = 12-4
Branches take 2 cycles if not taken, 3 if taken, 4 if page boundary crossed

Jumps & Calls

MnemonicOperationFlagsModesCycles
JMPJump to Address-abs, ind3-5
JSRJump to Subroutine-abs6
RTSReturn from Subroutine-impl6
RTIReturn from InterruptAllimpl6

Status Flag Operations

MnemonicOperationFlag EffectCycles
CLCClear CarryC = 02
CLDClear DecimalD = 02
CLIClear Interrupt DisableI = 02
CLVClear OverflowV = 02
SECSet CarryC = 12
SEDSet DecimalD = 12
SEISet Interrupt DisableI = 12

Compare Instructions

MnemonicOperationFlagsModesCycles
CMPCompare A with MemoryN Z Cimm, zp, zpx, abs, abx, aby, idx, idy2-6
CPXCompare X with MemoryN Z Cimm, zp, abs2-4
CPYCompare Y with MemoryN Z Cimm, zp, abs2-4
Compare sets flags as if subtraction occurred: C=1 if register ≥ memory

Bit Test

MnemonicOperationFlagsModesCycles
BITBit Test A with MemoryN V Zzp, abs3-4
BIT sets N to bit 7, V to bit 6, and Z if (A & M) = 0

System Functions

MnemonicOperationFlagsCyclesNotes
BRKForce Break (Software Interrupt)B I7Pushes PC+2, P; jumps to IRQ vector
NOPNo Operation-2Do nothing for 2 cycles

Common Illegal/Undocumented Opcodes

MnemonicOperationHex CodesDescription
LAXLDA + LDX$A7, $B7, $AF, $BF, $A3, $B3Load A and X simultaneously
SAXStore A & X$87, $97, $8F, $83Store (A AND X) to memory
DCPDEC + CMP$C7, $D7, $CF, $DF, $DB, $C3, $D3Decrement then compare
ISBINC + SBC$E7, $F7, $EF, $FF, $FB, $E3, $F3Increment then subtract
SLOASL + ORA$07, $17, $0F, $1F, $1B, $03, $13Shift left then OR
RLAROL + AND$27, $37, $2F, $3F, $3B, $23, $33Rotate left then AND
⚠️ Illegal opcodes are not guaranteed to work on all 6502 variants!

Opcode Quick Reference

By Hex Value (Official Opcodes)

    x0  x1  x2  x3  x4  x5  x6  x7  x8  x9  xA  xB  xC  xD  xE  xF
0x  BRK ORA --- --- --- ORA ASL --- PHP ORA ASL --- --- ORA ASL ---
1x  BPL ORA --- --- --- ORA ASL --- CLC ORA --- --- --- ORA ASL ---
2x  JSR AND --- --- BIT AND ROL --- PLP AND ROL --- BIT AND ROL ---
3x  BMI AND --- --- --- AND ROL --- SEC AND --- --- --- AND ROL ---
4x  RTI EOR --- --- --- EOR LSR --- PHA EOR LSR --- JMP EOR LSR ---
5x  BVC EOR --- --- --- EOR LSR --- CLI EOR --- --- --- EOR LSR ---
6x  RTS ADC --- --- --- ADC ROR --- PLA ADC ROR --- JMP ADC ROR ---
7x  BVS ADC --- --- --- ADC ROR --- SEI ADC --- --- --- ADC ROR ---
8x  --- STA --- --- STY STA STX --- DEY --- TXA --- STY STA STX ---
9x  BCC STA --- --- STY STA STX --- TYA STA TXS --- --- STA --- ---
Ax  LDY LDA LDX --- LDY LDA LDX --- TAY LDA TAX --- LDY LDA LDX ---
Bx  BCS LDA --- --- LDY LDA LDX --- CLV LDA TSX --- LDY LDA LDX ---
Cx  CPY CMP --- --- CPY CMP DEC --- INY CMP DEX --- CPY CMP DEC ---
Dx  BNE CMP --- --- --- CMP DEC --- CLD CMP --- --- --- CMP DEC ---
Ex  CPX SBC --- --- CPX SBC INC --- INX SBC NOP --- CPX SBC INC ---
Fx  BEQ SBC --- --- --- SBC INC --- SED SBC --- --- --- SBC INC ---
            

Cycle Counts by Addressing Mode

InstructionImmZPZP,X/YAbsAbs,X/Y(Ind,X)(Ind),Y
LDA/LDX/LDY23444+65+
STA/STX/STY-344566
ADC/SBC23444+65+
AND/ORA/EOR23444+65+
CMP/CPX/CPY23444+65+
INC/DEC-5667--
ASL/LSR/ROL/ROR2*5667--
+ = Add 1 cycle if page boundary crossed
* = Accumulator mode

Interrupt Vectors

VectorAddressTriggered By
NMI$FFFA-$FFFBNon-Maskable Interrupt
RESET$FFFC-$FFFDSystem Reset
IRQ/BRK$FFFE-$FFFFInterrupt Request / BRK

Programming Tips

Zero Page Optimization: Use zero page for frequently accessed variables - saves 1 byte and 1+ cycles per access
Branch vs Jump: Use branches for short jumps (±127 bytes) - saves 1 byte and cycles
Loop Counters: Count down to zero when possible - DEX/DEY automatically set Z flag
16-bit Operations: Store low byte first (little-endian) for 16-bit values
Fast Clear: LDA #0 / STA addr is faster than INC/DEC to zero
Multiply by 2: ASL is faster than ADC with itself
Test for Zero/Negative: Most instructions set N and Z flags - no need for explicit CMP #0
Reference Note: This cheat sheet covers the NMOS 6502. The 65C02 (CMOS) adds additional instructions and addressing modes. The 65816 extends to 16-bit with many more features.