Execution Times
Opcode execution times are measured in clock cycles. Many instructions require one extra cycle for execution if a page boundary is crossed; these are indicated by a + following the time values shown.
ADC – Add Memory to Accumulator with Carry
A + M + C -> A, C N V D I Z C + + - - + + MODE SYNTAX HEX DEC LEN TIM Immediate ADC #$44 $69 105 2 2 Zero Page ADC $44 $65 101 2 3 Zero Page,X ADC $44,X $75 117 2 4 Absolute ADC $4400 $6D 109 3 4 Absolute,X ADC $4400,X $7D 125 3 4+ Absolute,Y ADC $4400,Y $79 121 3 4+ (Indirect,X) ADC ($44,X) $61 97 2 6 (Indirect),Y ADC ($44),Y $71 113 2 5+
AND – Bitwise AND Operand with Accumulator
A AND M -> A N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Immediate AND #$44 $29 41 2 2 Zero Page AND $44 $25 37 2 3 Zero Page,X AND $44,X $35 53 2 4 Absolute AND $4400 $2D 45 3 4 Absolute,X AND $4400,X $3D 61 3 4+ Absolute,Y AND $4400,Y $39 57 3 4+ (Indirect,X) AND ($44,X) $21 33 2 6 (Indirect),Y AND ($44),Y $31 49 2 5+
ASL – Arithmetic Shift Left (Memory or Accumulator)
C <- [76543210] <- 0 N V D I Z C + - - - + + MODE SYNTAX HEX DEC LEN TIM Accumulator ASL A $0A 10 1 2 Zero Page ASL $44 $06 6 2 5 Zero Page,X ASL $44,X $16 22 2 6 Absolute ASL $4400 $0E 14 3 6 Absolute,X ASL $4400,X $1E 30 3 7
BIT – Test Bits in Memory with Accumulator
A AND M N V D I Z C + + - - + - MODE SYNTAX HEX DEC LEN TIM Zero Page BIT $44 $24 36 2 3 Absolute BIT $4400 $2C 44 3 4BIT sets the Z flag as though the value in the address tested were ANDed with the accumulator. The N and V flags are set to match bits 7 and 6 respectively in the value stored at the tested address.
Branch Instructions
All branches are relative and have a length of two bytes. The second byte represents a displacement of -128 to +127 bytes from the next instruction.
Branches are dependent on the status of the flag bits when the Opcode is encountered. A branch not taken requires two machine cycles. Add one if the branch is taken and add one more if the branch crosses a page boundary.
MNEMONIC HEX DEC N V D I Z C BPL (Branch on Plus) $10 16 0 - - - - - BMI (Branch on Minus) $30 48 1 - - - - - BVC (Branch on Overflow Clear) $50 80 - 0 - - - - BVS (Branch on Overflow Set) $70 112 - 1 - - - - BCC (Branch on Carry Clear) $90 144 - - - - - 0 BCS (Branch on Carry Set) $B0 176 - - - - - 1 BNE (Branch on Not Equal) $D0 208 - - - - 0 - BEQ (Branch on Equal) $F0 240 - - - - 1 -There is no BRA (Branch Always) instruction but it can be easily emulated by branching on the basis of a known condition. One of the best flags to use for this purpose is the oVerflow which is unchanged by all but addition and subtraction operations.
BRK – Break
MODE SYNTAX HEX DEC LEN TIM N V D I Z C Implied BRK $00 0 1 7 - - - 1 - -BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct.
Related: NOP
CMP – Compare Accumulator with Operand
A - M N V D I Z C + - - - + + MODE SYNTAX HEX DEC LEN TIM Immediate CMP #$44 $C9 201 2 2 Zero Page CMP $44 $C5 197 2 3 Zero Page,X CMP $44,X $D5 213 2 4 Absolute CMP $4400 $CD 205 3 4 Absolute,X CMP $4400,X $DD 221 3 4+ Absolute,Y CMP $4400,Y $D9 217 3 4+ (Indirect,X) CMP ($44,X) $C1 193 2 6 (Indirect),Y CMP ($44),Y $D1 209 2 5+Compare sets flags as if a subtraction had been carried out. If the value in the accumulator is equal or greater than the compared value, the Carry will be set. The equal (Z) and negative (N) flags will be set based on equality or lack thereof and the sign (i.e. A ≥ $80) of the accumulator.
Related: Branching
CPX – Compare X Register with Operand
X - M N V D I Z C + - - - + + MODE SYNTAX HEX DEC LEN TIM Immediate CPX #$44 $E0 224 2 2 Zero Page CPX $44 $E4 228 2 3 Absolute CPX $4400 $EC 236 3 4Operation and flag results are identical to equivalent mode accumulator CMP ops.
Related: Branching, LDX, INX, DEX
CPY – Compare Y Register with Operand
Y - M N V D I Z C + - - - + + MODE SYNTAX HEX DEC LEN TIM Immediate CPY #$44 $C0 192 2 2 Zero Page CPY $44 $C4 196 2 3 Absolute CPY $4400 $CC 204 3 4Operation and flag results are identical to equivalent mode accumulator CMP ops.
Related: Branching, LDY, INY, DEY
DEC – Decrement Memory
M - 1 -> M N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Zero Page DEC $44 $C6 198 2 5 Zero Page,X DEC $44,X $D6 214 2 6 Absolute DEC $4400 $CE 206 3 6 Absolute,X DEC $4400,X $DE 222 3 7
EOR – Exclusive OR Operand with Accumulator
A EOR M -> A N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Immediate EOR #$44 $49 73 2 2 Zero Page EOR $44 $45 69 2 3 Zero Page,X EOR $44,X $55 85 2 4 Absolute EOR $4400 $4D 77 3 4 Absolute,X EOR $4400,X $5D 93 3 4+ Absolute,Y EOR $4400,Y $59 89 3 4+ (Indirect,X) EOR ($44,X) $41 65 2 6 (Indirect),Y EOR ($44),Y $51 81 2 5+
Flag (Processor Status) Instructions
These instructions are implied mode, have a length of one byte and require two machine cycles.
MNEMONIC HEX DEC N V D I Z C CLC (Clear Carry) $18 24 - - - - - 0 SEC (Set Carry) $38 56 - - - - - 1 CLI (Clear Interrupt) $58 88 - - - 0 - - SEI (Set Interrupt) $78 120 - - - 1 - - CLV (Clear Overflow) $B8 184 - 0 - - - - CLD (Clear Decimal) $D8 216 - - 0 - - - SED (Set Decimal) $F8 248 - - 1 - - -
INC – Increment Memory
M + 1 -> M N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Zero Page INC $44 $E6 230 2 5 Zero Page,X INC $44,X $F6 246 2 6 Absolute INC $4400 $EE 238 3 6 Absolute,X INC $4400,X $FE 254 3 7
JMP – Jump to Memory Location
N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Absolute JMP $4400 $4C 76 3 3 Indirect JMP ($4400) $6C 108 3 5JMP transfers program execution to the following address (absolute) or to the location contained in the following address (indirect).
NOTE: An indirect jump should never use a vector beginning on the last byte of a page.
For example if address $3000 contains $40, $30FF contains $80, and $3100 contains $50, the result of JMP ($30FF) will be a transfer of control to $4080 rather than $5080 as you intended i.e. the 6502 took the low byte of the address from $30FF and the high byte from $3000.
Related: JSR
JSR – Jump to Subroutine
N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Absolute JSR $4400 $20 32 3 6JSR pushes the address-1 of the next operation on to the stack before transferring program control to the following address. Subroutines are normally terminated by a RTS op code.
LDA – Load Accumulator with Operand
M -> A N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Immediate LDA #$44 $A9 169 2 2 Zero Page LDA $44 $A5 165 2 3 Zero Page,X LDA $44,X $B5 181 2 4 Absolute LDA $4400 $AD 173 3 4 Absolute,X LDA $4400,X $BD 189 3 4+ Absolute,Y LDA $4400,Y $B9 185 3 4+ (Indirect,X) LDA ($44,X) $A1 161 2 6 (Indirect),Y LDA ($44),Y $B1 177 2 5+Related: STA
LDX – Load X Register with Operand
M -> X N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Immediate LDX #$44 $A2 162 2 2 Zero Page LDX $44 $A6 166 2 3 Zero Page,Y LDX $44,Y $B6 182 2 4 Absolute LDX $4400 $AE 174 3 4 Absolute,Y LDX $4400,Y $BE 190 3 4+Related: STX, INX, DEX
LDY – Load Y Register with Operand
M -> Y N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Immediate LDY #$44 $A0 160 2 2 Zero Page LDY $44 $A4 164 2 3 Zero Page,X LDY $44,X $B4 180 2 4 Absolute LDY $4400 $AC 172 3 4 Absolute,X LDY $4400,X $BC 188 3 4+Related: STY, INY, DEY
LSR – Logical Shift Right (Memory or Accumulator)
0 -> [76543210] -> C N V D I Z C 0 - - - + + MODE SYNTAX HEX DEC LEN TIM Accumulator LSR A $4A 74 1 2 Zero Page LSR $44 $46 70 2 5 Zero Page,X LSR $44,X $56 86 2 6 Absolute LSR $4400 $4E 78 3 6 Absolute,X LSR $4400,X $5E 94 3 7
NOP – No Operation
N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Implied NOP $EA 234 1 2NOP is sometimes used to reserve space for future modifications or effectively comment-out existing instructions.
Related: BRK
ORA – Bitwise OR Operand with Accumulator
A OR M -> A N V D I Z C + - - - + - MODE SYNTAX HEX DEC LEN TIM Immediate ORA #$44 $09 0 2 2 Zero Page ORA $44 $05 5 2 3 Zero Page,X ORA $44,X $15 21 2 4 Absolute ORA $4400 $0D 13 3 4 Absolute,X ORA $4400,X $1D 29 3 4+ Absolute,Y ORA $4400,Y $19 25 3 4+ (Indirect,X) ORA ($44,X) $01 1 2 6 (Indirect),Y ORA ($44),Y $11 17 2 5+
Register Instructions
These instructions are implied mode, have a length of one byte and require two machine cycles.
N V D I Z C + - - - + - MNEMONIC HEX DEC OPERATION INX (Increment X) $E8 232 X + 1 -> X DEX (Decrement X) $CA 202 X - 1 -> X INY (Increment Y) $C8 200 Y + 1 -> Y DEY (Decrement Y) $88 136 Y - 1 -> Y TAX (Transfer A to X) $AA 170 A -> X TXA (Transfer X to A) $8A 138 X -> A TAY (Transfer A to Y) $A8 168 A -> Y TYA (Transfer Y to A) $98 152 Y -> A
Related: INC, DEC, LDX, LDY, STX, STY
ROL – Rotate Left (Memory or Accumulator)
C <- [76543210] <- C N V D I Z C + - - - + + MODE SYNTAX HEX DEC LEN TIM Accumulator ROL A $2A 42 1 2 Zero Page ROL $44 $26 38 2 5 Zero Page,X ROL $44,X $36 54 2 6 Absolute ROL $4400 $2E 46 3 6 Absolute,X ROL $4400,X $3E 62 3 7
ROR – Rotate Right (Memory or Accumulator)
C -> [76543210] -> C N V D I Z C + - - - + + MODE SYNTAX HEX DEC LEN TIM Accumulator ROR A $6A 106 1 2 Zero Page ROR $44 $66 102 2 5 Zero Page,X ROR $44,X $76 118 2 6 Absolute ROR $4400 $6E 110 3 6 Absolute,X ROR $4400,X $7E 126 3 7
RTI – Return from Interrupt
pull SR, pull PC N V D I Z C from stack MODE SYNTAX HEX DEC LEN TIM Implied RTI $40 64 1 6RTI retrieves the Processor Status Word (flags) and the Program Counter from the stack in that order (interrupts push the PC first and then the PSW).
Note that unlike RTS, the return address on the stack is the actual address rather than the address-1.
RTS – Return from Subroutine
pull PC, PC+1 -> PC N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Implied RTS $60 96 1 6RTS pulls the top two bytes off the stack (low byte first) and transfers program control to that address+1. It is used, as expected, to exit a subroutine invoked via JSR which pushed the address-1.
Related: JSR
SBC – Subtract with Carry
A - M - C̅ -> A N V D I Z C + + - - + + MODE SYNTAX HEX DEC LEN TIM Immediate SBC #$44 $E9 233 2 2 Zero Page SBC $44 $E5 229 2 3 Zero Page,X SBC $44,X $F5 245 2 4 Absolute SBC $4400 $ED 237 3 4 Absolute,X SBC $4400,X $FD 253 3 4+ Absolute,Y SBC $4400,Y $F9 249 3 4+ (Indirect,X) SBC ($44,X) $E1 225 2 6 (Indirect),Y SBC ($44),Y $F1 241 2 5+SBC results are dependent on the setting of the Carry flag and the Decimal flag. In decimal mode, subtraction is carried out on the assumption that the values involved are packed BCD (Binary Coded Decimal).
The Carry flag is normally set before subtracting. If the carry is cleared by the operation, it indicates that a borrow has occurred.
Stack Instructions
These instructions are implied mode, have a length of one byte and require machine cycles as indicated. The stack is always on page one ($100-$1FF) and works top down.
MNEMONIC HEX DEC TIM N V D I Z C PHA (Push Accumulator) $48 72 3 - - - - - - PLA (Pull Accumulator) $68 104 4 + - - - + - PHP (Push Processor status) $08 8 3 - - - - - - PLP (Pull Processor status) $28 40 4 from stack TXS (Transfer X to Stack ptr) $9A 154 2 - - - - - - TSX (Transfer Stack ptr to X) $BA 186 2 + - - - + -
STA – Store Accumulator to Memory
A -> M N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Zero Page STA $44 $85 133 2 3 Zero Page,X STA $44,X $95 149 2 4 Absolute STA $4400 $8D 141 3 4 Absolute,X STA $4400,X $9D 157 3 5 Absolute,Y STA $4400,Y $99 153 3 5 (Indirect,X) STA ($44,X) $81 129 2 6 (Indirect),Y STA ($44),Y $91 145 2 6Related: LDA
STX – Store X Register to Memory
X -> M N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Zero Page STX $44 $86 134 2 3 Zero Page,Y STX $44,Y $96 150 2 4 Absolute STX $4400 $8E 142 3 4Related: LDX
STY – Store Y Register to Memory
Y -> M N V D I Z C - - - - - - MODE SYNTAX HEX DEC LEN TIM Zero Page STY $44 $84 132 2 3 Zero Page,X STY $44,X $94 148 2 4 Absolute STY $4400 $8C 140 3 4Related: LDY
Updated: September 8, 2024