Instruction Set Architecture

The original NMOS version of the 6502 has 151 legal opcodes. Out of the total number of possible opcodes, ilegal opcodes have been found to be sometimes useful.

The ISA included in this page will cover the legal opcodes. Ilegal opcodes may be added in the future as an extension to this page.

The instructions can be categorized according to the type of operation they perform. We can distinguish between the following categories:

  • Logical and bit manipulation operations. Operations such as AND, OR, XOR, etc.
  • Arithmetic operations. Operations such as ADD, SUBSTRACT, INCREMENT, etc.
  • Data shifting instructions. Shift values in registers. Can be either logical, arithmetic or rotation instructions.
  • Program control flow operations. Control the flow of the program. They allow to set/modify the value of the program counter.
  • Memory transfer operations. Transfers memory between different parts of the system (Mainly processor and main memory).

Logical and bit manipulation operations

Logical operations

MnemonicOpcodeAddressing modeModified FlagsDescription
AND29'hImmediateN, ZAnd M with A: A AND M -> A
25'hZeropage
35'hZeropage, X-Indexed
2D'hAbsolute
3D'hAbsolute, X-Indexed
39'hAbsolute, Y-Indexed
21'hX-Indexed, Indirect
31'hIndirect, Y-Indexed
ORA09'hImmediateN, ZOr M with A. A OR M -> A.
05'hZeropage
15'hZeropage, X-Indexed
0D'hAbsolute
1D'hAbsolute, X-Indexed
19'hAbsolute, Y-Indexed
01'hX-Indexed, Indirect
11'hIndirect, Y-Indexed
EOR49'hImmediateN, ZExclusive or A with M. (A XOR M) -> A.
45'hZeropage
55'hZeropage, X-Indexed
4D'hAbsolute
5D'hAbsolute, X-Indexed
59'hAbsolute, Y-Indexed
41'hX-Indexed, Indirect
51'hIndirect, Y-Indexed

Comparison operations

MnemonicOpcodeAddressing modeModified FlagsDescription
CMPC9'hImmediateN, Z, CCompare M with A. (A-M). Result is not stored.
C5'hZeropage
D5'hZeropage, X-Indexed
CD'hAbsolute
DD'hAbsolute, X-Indexed
D9'hAbsolute, Y-Indexed
C1'hX-Indexed, Indirect
D1'hIndirect, Y-Indexed
CPXE0'hImmediateN, Z, CCompare M and X. (X - M). The result is not stored.
E4'hZeropage
EC'hAbsolute
CPYC0'hImmediateN, Z, CCompare M and Y. (Y - M). The result is not stored.
C4'hZeropage
CC'hAbsolute
NOPEA'hImpliedNOP.

Bit manipulation operations

MnemonicOpcodeAddressing modeModified FlagsDescription
BIT24'hZeropageN, Z, VM7 -> N, M6 -> V, (M AND A == 0) -> Z.
2C'hAbsolute
CLC18'hImpliedClear C flag.
CLDD8'hImpliedClear D flag.
CLI58'hImpliedClear I flag.
CLVB8'hImpliedClear O flag.
SEC38'hImpliedCSet C flag.
SEDF8'hImpliedDSet D flag.
SEI78'hImpliedISet I flag.

Arithmetic Operations

Add/substract

MnemonicOpcodeAddressing modeModified FlagsDescription
ADC69'hImmediateN, Z, C, VAdd with carry: A + M + C -> A, C.
65'hZeropage
75'hZeropage, X-Indexed
6D'hAbsolute
7D'hAbsolute, X-Indexed
79'hAbsolute, Y-Indexed
61'hX-Indexed, Indirect
71'hIndirect, Y-Indexed
SBCE9'hImmediateN, Z, C, VSubtract M from A with borrow. (A - M - Cbar) -> A.
E5'hZeropage
F5'hZeropage, X-Indexed
ED'hAbsolute
FD'hAbsolute, X-Indexed
F9'hAbsolute, Y-Indexed
E1'hX-Indexed, Indirect
F1'hIndirect, Y-Indexed

Increment/Decrement

MnemonicOpcodeAddressing modeModified FlagsDescription
INCE6'hZeropageN, ZIncrement M by one. (M + 1) -> M.
F6'hZeropage, X-Indexed
EE'hAbsolute
FE'hAbsolute, X-Indexed
INXE8'hImpliedN, ZIncrement X by one. (X + 1) -> X.
INYC8'hImpliedN, ZIncrement Y by one. (Y + 1) -> Y.
DECC6'hZeropageN, ZDecrement M by one. (M - 1) -> M.
D6'hZeropage, X-Indexed
CE'hAbsolute
DE'hAbsolute, X-Indexed
DEXCA'hImpliedN, ZDecrement X by one. (X - 1) -> X.
DEY88'hImpliedN, ZDecrement Y by one. (Y - 1) -> Y.

Data shifting instructions

MnemonicOpcodeAddressing modeModified FlagsDescription
LSR4A'hAccumulatorN(0), Z, CLogical shift right (1 bit).
46'hZeropage
56'hZeropage, X-Indexed
4E'hAbsolute
5E'hAbsolute, X-Indexed
ASL0A'hAccumulatorN, Z, CArithmetic shift left by one bit (M or A).
06'hZeropage
16'hZeropage, X-Indexed
0E'hAbsolute
1E'hAbsolute, X-Indexed
ROL2A'hAccumulatorN, Z, CRotate one bit left (Circular rotation, including C bit).
26'hZeropage
36'hZeropage, X-Indexed
2E'hAbsolute
3E'hAbsolute, X-Indexed
ROR6A'hAccumulatorN, Z, CRotate one bit left (Circular rotation, including C bit).
66'hZeropage
76'hZeropage, X-Indexed
6E'hAbsolute
7E'hAbsolute, X-Indexed

Program control flow operations

Jump instructions (Absolute Address)

MnemonicOpcodeAddressing modeModified FlagsDescription
JMP4C'hAbsoluteJump to the M location.
6C'hIndirect

Branch instructions (Relative to PC)

MnemonicOpcodeAddressing modeModified FlagsDescription
BCSB0'hRelativeBranch if C is set.
BCC90'hRelativeBranch if C is clear.
BEQF0'hRelativeBranch if Z is set.
BNED0'hRelativeBranch if Z is clear
BMI30'hRelativeBranch if N is set
BPL10'hRelativeBranch if N is clear
BVS70'hRelativeBranch if V is set
BVC50'hRelativeBranch if V is clear

Subroutines

MnemonicOpcodeAddressing modeModified FlagsDescription
JSR20'hAbsoluteJump to subrutine (Saves return address in the stack)
RTS60'hImpliedReturns from subroutine. Pulls PC from SP

Interrupts

MnemonicOpcodeAddressing modeModified FlagsDescription
BRK00'hImpliedITriggers a software interrupt. Pushes the PC+2 and SP to the stack
RTI40'hImpliedFrom SPReturns from the current ISR. Pulls P and PC

Memory transfer operations

Load/Store from/to memory

MnemonicOpcodeAddressing modeModified FlagsDescription
LDAA9'hImmediateN, ZLoads the A with M.
A5'hZeropage
B5'hZeropage, X-Indexed
AD'hAbsolute
BD'hAbsolute, X-Indexed
B9'hAbsolute, Y-Indexed
A1'hX-Indexed, Indirect
B1'hIndirect, Y-Indexed
STA85'hZeropageStores the A in M.
95'hZeropage, X-Indexed
8D'hAbsolute
9D'hAbsolute, X-Indexed
99'hAbsolute, Y-Indexed
81'hX-Indexed, Indirect
91'hIndirect, Y-Indexed
LDXA2'hImmediateN, ZLoads the X register with M.
A6'hZeropage
B6'hZeropage, Y-Indexed
AE'hAbsolute
BE'hAbsolute, Y-Indexed
STX86'hZeropageStores the X register in M.
96'hZeropage, Y-Indexed
8E'hAbsolute
LDYA0'hImmediateN, ZLoads the Y register with M.
A4'hZeropage
B4'hZeropage, X-Indexed
AC'hAbsolute
BC'hAbsolute, X-Indexed
STY84'hZeropageStores the Y register in M.
94'hZeropage, X-Indexed
8C'hAbsolute

Register data transfer operations

MnemonicOpcodeAddressing modeModified FlagsDescription
TAXAA'hImpliedTransfer A to X. A -> X.
TXA8A'hImpliedTransfer X to A. X -> A.
TAYA8'hImpliedTransfer A to Y. A -> Y.
TYA98'hImpliedTransfer Y to A. Y -> A.
TSXBA'hImpliedTransfer SP to X. SP -> X.
TXS9A'hImpliedTransfer X to SP. X -> SP.

Stack operations

MnemonicOpcodeAddressing modeModified FlagsDescription
PHA48'hImpliedPush A to the stack.
PLA68'hImpliedPull A from the stack.
PHP08'hImpliedPush P to the stack.
PLP28'hImpliedPull P from the stack.