# 6502 instruction set

The 6502 instruction set

For each instruction is given the mnemonic, the description of what does the instruction, a symbolic description of what the instruction is doing, the affected status flag, and finaly the various adressing mode available for that instruction with the corresponding opcode.

Symbols:

- A - Accumulator
- C - Carry flag
- D - Decimal mode flag
- I - Interupt flag
- M - Memory
- X - X index register
- Y - Y index register
- V - Overflow flag
- Z - Zero flag

ADC

Add to Accumulator with Carry
A+M+C -> A,C
N, Z, C, V

- $69 - ADC #aa
- $65 - ADC aa
- $75 - ADC aa,X
- $6D - ADC aaaa
- $7D - ADC aaaa,X

AND

AND Memory with Accumulator
A and M -> A
N, Z

- $29 - AND #aa
- $25 - AND aa
- $35 - AND aa,X
- $2D - AND aaaa
- $3D - AND aaaa,X
- $39 - AND aaaa,Y
- $21 - AND (aa,X)
- $31 - AND (aa),Y

ASL

Arithmetic Shift Left

               +-+-+-+-+-+-+-+-+
          C <- |7|6|5|4|3|2|1|0| <- 0
               +-+-+-+-+-+-+-+-+

N, Z, C

- $0A - ASL A
- $06 - ASL aa
- $16 - ASL aa,X
- $0E - ASL aaaa
- $1E - ASL aaaa,X

BCC

Branch on Carry Clear
branch on C=0
no flags

- $90 - BCC aa

BCS

Branch on Carry Set
branch on C=1
no flags

- $B0 - BCS aa

BEQ

Branch Zero Set
branch on Z=1
no flags

- $F0 - BEQ aa

BIT

Test Bits in Memory with Accumulator
A and M, M7 -> N, M6 -> V (neither A nor M are altered)
N=M7, V=M6, Z=1 if A and M = 0

- $24 - BIT aa
- $2C - BIT aaaa

BMI

Branch on Result Minus
branch on N=1
no flags

- $30 - BMI aa

BNE

Branch on Z reset
branch on Z=0
no flags

- $D0 - BNE aa

BPL

Branch on Result Plus
branch on N=0
no flags

- $10 - BPL aa

BRK

Force a Break
forced interrupt
B=1, I=1

- $00 - BRK

BVC

Branch on Overflow Clear
branch on V=0
no flags

- $50 - BVC aa

BVS

Branch on Overflow Set
branch on V=1
no flags

- $70 - BVS aa

CLC

Clear Carry Flag
0 -> C
C=0

- $18 - CLC

CLD

Clear Decimal Mode
0 -> D
D=0

- $D8 - CLD

CLI

Clear Interrupt Disable
0 -> I
I=0

- $58 - CLI

CLV

Clear Overflow Flag
0 -> V
V=0

- $B8 - CLV

CMP

Compare Memory and Accumulator
A compared with M
A, X, or Y < Memory ---> N=1, Z=0, C=0

- $C9 - CMP #aa
- $C5 - CMP aa
- $D5 - CMP aa,X
- $CD - CMP aaaa
- $DD - CMP aaaa,X
- $D9 - CMP aaaa,Y
- $C1 - CMP (aa,X)
- $D1 - CMP (aa),Y

CPX

Compare Memory and X register
X compared with M
A, X, or Y < Memory ---> N=1, Z=0, C=0

- $E0 - CPX #aa
- $E4 - CPX aa
- $EC - CPX aaaa

CPY

Compare Memory and Y register
Y compare with M
A, X, or Y < Memory ---> N=1, Z=0, C=0

- $C0 - CPY #aa
- $C4 - CPY aa
- $CC - CPY aaaa

DEC

Decrement Memory by One
M - 1 -> M
N, Z

- $C6 - DEC aa
- $D6 - DEC aa,X
- $CE - DEC aaaa
- $DE - DEC aaaa,X

DEX

Decrement X
X - 1 -> X
N, Z

- $CA - DEX

DEY

Decrement Y
Y - 1 -> Y
N, Z

- $88 - DEY

EOR

Exclusive-OR Memory with Accumulator
A xor M -> A
N, Z

- $49 - EOR #aa
- $45 - EOR $aa
- $55 - EOR $aa,X
- $4D - EOR $aaaa
- $5D - EOR $aaaa,X
- $59 - EOR $aaaa,Y
- $41 - EOR ($aa,X)
- $51 - EOR ($aa),Y

INC

Increment Memory by one
M + 1 -> M
N, Z

- $E6 - INC $aa
- $F6 - INC $aa,X
- $EE - INC $aaaa
- $FE - INC $aaaa,X

INX

Increment X by one
X + 1 -> X
N, Z

- $E8 - INX

INY

Increment Y by one
Y + 1 -> Y
N, Z

- $C8 - INY

JMP

Jump

- $4C - JMP $aaaa
- $6C - JMP ($aaaa)

JSR

Jump to subroutine

- $20 - JSR $aaaa

LDA

Load Accumulator with memory
M -> A
N, Z

- $A9 - LDA #aa
- $A5 - LDA $aa
- $B5 - LDA $aa,X
- $AD - LDA $aaaa
- $BD - LDA $aaaa,X
- $B9 - LDA $aaaa,Y
- $A1 - LDA ($aa,X)
- $B1 - LDA ($aa),Y

LDX

Load X with Memory
M -> X
N, Z

- $A2 - LDX #aa
- $A6 - LDX $aa
- $B6 - LDX $aa,Y
- $AE - LDX $aaaa
- $BE - LDX $aaaa,Y

LDY

Load Y with Memory
M -> Y
N, Z

- $A0 - LDY #aa
- $A4 - LDY $aa
- $B4 - LDY $aa,X
- $AC - LDY $aaaa
- $BC - LDY $aaaa,X

LSR

Logical Shift Right

         +-+-+-+-+-+-+-+-+
    0 -> |7|6|5|4|3|2|1|0| -> C
         +-+-+-+-+-+-+-+-+

N, Z, C

- $4A - LSR A
- $46 - LSR $aa
- $56 - LSR $aa,X
- $4E - LSR $aaaa
- $5E - LSR $aaaa,X

NOP

No Operation

- $EA - NOP

ORA

OR Memory with Accumulator
A or M -> A
N, Z

- $09 - ORA #aa
- $05 - ORA $aa
- $15 - ORA $aa,X
- $0D - ORA $aaaa
- $1D - ORA $aaaa,X
- $19 - ORA $aaaa,Y
- $01 - ORA ($aa,X)
- $11 - ORA ($aa),Y

PHA

Push Accumulator on Stack
A -> Stack

- $48 - PHA

PHP

Push Processor Status on Stack
P -> Stack

- $08 - PHP

PLA

Pull Accumulator from Stack
Stack -> A
N, Z

- $68 - PLA

PLP

Pull Processor Status from Stack
Stack -> P
P from stack

- $28 - PLP

ROL

Rotate Left

         +-+-+-+-+-+-+-+-+
    C <- |7|6|5|4|3|2|1|0| <- C
         +-+-+-+-+-+-+-+-+

N, Z, C

- $2A - ROL A
- $26 - ROL $aa
- $36 - ROL $aa,X
- $2E - ROL $aaaa
- $3E - ROL $aaaa,X

ROR

Rotate Right

         +-+-+-+-+-+-+-+-+
    C -> |7|6|5|4|3|2|1|0| -> C
         +-+-+-+-+-+-+-+-+

N, Z, C

- $6A - ROR A
- $66 - ROR $aa
- $76 - ROR $aa,X
- $6E - ROR $aaaa
- $7E - ROR $aaaa,X

RTI

Return from Interrupt

- $40 - RTI

RTS

Return from Subroutine

- $60 - RTS

SBC

Subtract from Accumulator with Carry
A - M - ~C -> A (~C is NOT C)
N, Z, C, V

- $E9 - SBC #aa
- $E5 - SBC $aa
- $F5 - SBC $aa,X
- $ED - SBC $aaaa
- $FD - SBC $aaaa,X
- $F9 - SBC $aaaa,Y
- $E1 - SBC ($aa,X)
- $F1 - SBC ($aa),Y

SEC

Set Carry Flag

- $38 - SEC

SED

Set Decimal Mode

- $F8 - SED

SEI

Set Interrupt Disable

- $78 - SEI

STA

Store Accumulator in Memory

- $85 - STA $aa
- $95 - STA $aa,X
- $8D - STA $aaaa
- $9D - STA $aaaa,X
- $99 - STA $aaaa,Y
- $81 - STA ($aa,X)
- $91 - STA ($aa),Y

STX

Store X in Memory

- $86 - STX $aa
- $96 - STX $aa,Y
- $8E - STX $aaaa

STY

Store Y in Memory

- $84 - STY $aa
- $94 - STY $aa,X
- $8C - STY $aaaa

TAX

Transfer Accumulator to X
A -> X
N, Z

- $AA - TAX

TAY

Transfer Accumulator to Y
A -> Y
N, Z

- $A8 - TAY

TSX

Transfer Stack to X
S -> X
N, Z

- $BA - TSX

TXA

Transfer X to Accumulator
X -> A
N, Z

- $8A - TXA

TXS

Transfer X to Stack
X -> S
N, Z

- $9A - TXS

TYA

Transfer Y to Accumulator
Y -> A
N, Z

- $98 - TYA