6502 Family CPU Reference

by Michael Steil. [github.com/mist64/c64ref, rev fd22ad3, 2025-03-12]

NV-BDIZC
----

ADC - Add Memory to Accumulator with Carry

Operation: A + M + C → A, C

This instruction adds the value of memory and carry from the previous operation to the value of the accumulator and stores the result in the accumulator.

This instruction affects the accumulator; sets the carry flag when the sum of a binary add exceeds 255 or when the sum of a decimal add exceeds 99, otherwise carry is reset. The overflow flag is set when the sign or bit 7 is changed due to the result exceeding +127 or -128, otherwise overflow is reset. The negative flag is set if the accumulator result contains bit 7 on, otherwise the negative flag is reset. The zero flag is set if the accumulator result is 0, otherwise the zero flag is reset.

Note on the MOS 6502:

In decimal mode, the N, V and Z flags are not consistent with the decimal result.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateADC #$nn$6922
AbsoluteADC $nnnn$6D34
X-Indexed AbsoluteADC $nnnn,X$7D34+p
Y-Indexed AbsoluteADC $nnnn,Y$7934+p
Zero PageADC $nn$6523
X-Indexed Zero PageADC $nn,X$7524
X-Indexed Zero Page IndirectADC ($nn,X)$6126
Zero Page Indirect Y-IndexedADC ($nn),Y$7125+p

p: =1 if page is crossed.

NV-BDIZC
------

AND - "AND" Memory with Accumulator

Operation: A ∧ M → A

The AND instruction transfer the accumulator and memory to the adder which performs a bit-by-bit AND operation and stores the result back in the accumulator.

This instruction affects the accumulator; sets the zero flag if the result in the accumulator is 0, otherwise resets the zero flag; sets the negative flag if the result in the accumulator has bit 7 on, otherwise resets the negative flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateAND #$nn$2922
AbsoluteAND $nnnn$2D34
X-Indexed AbsoluteAND $nnnn,X$3D34+p
Y-Indexed AbsoluteAND $nnnn,Y$3934+p
Zero PageAND $nn$2523
X-Indexed Zero PageAND $nn,X$3524
X-Indexed Zero Page IndirectAND ($nn,X)$2126
Zero Page Indirect Y-IndexedAND ($nn),Y$3125+p

p: =1 if page is crossed.

NV-BDIZC
-----

ASL - Arithmetic Shift Left

Operation: C ← /M7...M0/ ← 0

The shift left instruction shifts either the accumulator or the address memory location 1 bit to the left, with the bit 0 always being set to 0 and the input bit 7 being stored in the carry flag. ASL either shifts the accumulator left 1 bit or is a read/modify/write instruction that affects only memory.

The instruction does not affect the overflow bit, sets N equal to the result bit 7 (bit 6 in the input), sets Z flag if the result is equal to 0, otherwise resets Z and stores the input bit 7 in the carry flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AccumulatorASL A$0A12
AbsoluteASL $nnnn$0E36
X-Indexed AbsoluteASL $nnnn,X$1E37
Zero PageASL $nn$0625
X-Indexed Zero PageASL $nn,X$1626

NV-BDIZC
--------

BCC - Branch on Carry Clear

Operation: Branch on C = 0

This instruction tests the state of the carry bit and takes a conditional branch if the carry bit is reset.

It affects no flags or registers other than the program counter and then only if the C flag is not on.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBCC $nnnn$9022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
--------

BCS - Branch on Carry Set

Operation: Branch on C = 1

This instruction takes the conditional branch if the carry flag is on.

BCS does not affect any of the flags or registers except for the program counter and only then if the carry flag is on.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBCS $nnnn$B022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
--------

BEQ - Branch on Result Zero

Operation: Branch on Z = 1

This instruction could also be called "Branch on Equal."

It takes a conditional branch whenever the Z flag is on or the previous result is equal to 0.

BEQ does not affect any of the flags or registers other than the program counter and only then when the Z flag is set.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBEQ $nnnn$F022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
-----

BIT - Test Bits in Memory with Accumulator

Operation: A ∧ M, M7 → N, M6 → V

This instruction performs an AND between a memory location and the accumulator but does not store the result of the AND into the accumulator.

The bit instruction affects the N flag with N being set to the value of bit 7 of the memory being tested, the V flag with V being set equal to bit 6 of the memory being tested and Z being set by the result of the AND operation between the accumulator and the memory if the result is Zero, Z is reset otherwise. It does not affect the accumulator.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteBIT $nnnn$2C34
Zero PageBIT $nn$2423

NV-BDIZC
--------

BMI - Branch on Result Minus

Operation: Branch on N = 1

This instruction takes the conditional branch if the N bit is set.

BMI does not affect any of the flags or any other part of the machine other than the program counter and then only if the N bit is on.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBMI $nnnn$3022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
--------

BNE - Branch on Result Not Zero

Operation: Branch on Z = 0

This instruction could also be called "Branch on Not Equal." It tests the Z flag and takes the conditional branch if the Z flag is not on, indicating that the previous result was not zero.

BNE does not affect any of the flags or registers other than the program counter and only then if the Z flag is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBNE $nnnn$D022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
--------

BPL - Branch on Result Plus

Operation: Branch on N = 0

This instruction is the complementary branch to branch on result minus. It is a conditional branch which takes the branch when the N bit is reset (0). BPL is used to test if the previous result bit 7 was off (0) and branch on result minus is used to determine if the previous result was minus or bit 7 was on (1).

The instruction affects no flags or other registers other than the P counter and only affects the P counter when the N bit is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBPL $nnnn$1022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
-----1--

BRK - Break Command

Operation: PC + 2↓, [FFFE] → PCL, [FFFF] → PCH

The break command causes the microprocessor to go through an interrupt sequence under program control. This means that the program counter of the second byte after the BRK. is automatically stored on the stack along with the processor status at the beginning of the break instruction. The microprocessor then transfers control to the interrupt vector.

Other than changing the program counter, the break instruction changes no values in either the registers or the flags.

Note on the MOS 6502:

If an IRQ happens at the same time as a BRK instruction, the BRK instruction is ignored.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedBRK $0017

NV-BDIZC
--------

BVC - Branch on Overflow Clear

Operation: Branch on V = 0

This instruction tests the status of the V flag and takes the conditional branch if the flag is not set.

BVC does not affect any of the flags and registers other than the program counter and only when the overflow flag is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBVC $nnnn$5022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
--------

BVS - Branch on Overflow Set

Operation: Branch on V = 1

This instruction tests the V flag and takes the conditional branch if V is on.

BVS does not affect any flags or registers other than the program, counter and only when the overflow flag is set.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
RelativeBVS $nnnn$7022+t+p

p: =1 if page is crossed.
t: =1 if branch is taken.

NV-BDIZC
-------0

CLC - Clear Carry Flag

Operation: 0 → C

This instruction initializes the carry flag to a 0. This operation should normally precede an ADC loop. It is also useful when used with a ROL instruction to clear a bit in memory.

This instruction affects no registers in the microprocessor and no flags other than the carry flag which is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedCLC $1812

NV-BDIZC
----0---

CLD - Clear Decimal Mode

Operation: 0 → D

This instruction sets the decimal mode flag to a 0. This all subsequent ADC and SBC instructions to operate as simple operations.

CLD affects no registers in the microprocessor and no flags other than the decimal mode flag which is set to a 0.

Note on the MOS 6502:

The value of the decimal mode flag is indeterminate after a RESET.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedCLD $D812

NV-BDIZC
-----0--

CLI - Clear Interrupt Disable

Operation: 0 → I

This instruction initializes the interrupt disable to a 0. This allows the microprocessor to receive interrupts.

It affects no registers in the microprocessor and no flags other than the interrupt disable which is cleared.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedCLI $5812

NV-BDIZC
-0------

CLV - Clear Overflow Flag

Operation: 0 → V

This instruction clears the overflow flag to a 0. This command is used in conjunction with the set overflow pin which can change the state of the overflow flag with an external signal.

CLV affects no registers in the microprocessor and no flags other than the overflow flag which is set to a 0.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedCLV $B812

NV-BDIZC
-----

CMP - Compare Memory and Accumulator

Operation: A - M

This instruction subtracts the contents of memory from the contents of the accumulator.

The use of the CMP affects the following flags: Z flag is set on an equal comparison, reset otherwise; the N flag is set or reset by the result bit 7, the carry flag is set when the value in memory is less than or equal to the accumulator, reset when it is greater than the accumulator. The accumulator is not affected.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateCMP #$nn$C922
AbsoluteCMP $nnnn$CD34
X-Indexed AbsoluteCMP $nnnn,X$DD34+p
Y-Indexed AbsoluteCMP $nnnn,Y$D934+p
Zero PageCMP $nn$C523
X-Indexed Zero PageCMP $nn,X$D524
X-Indexed Zero Page IndirectCMP ($nn,X)$C126
Zero Page Indirect Y-IndexedCMP ($nn),Y$D125+p

p: =1 if page is crossed.

NV-BDIZC
-----

CPX - Compare Index Register X To Memory

Operation: X - M

This instruction subtracts the value of the addressed memory location from the content of index register X using the adder but does not store the result; therefore, its only use is to set the N, Z and C flags to allow for comparison between the index register X and the value in memory.

The CPX instruction does not affect any register in the machine; it also does not affect the overflow flag. It causes the carry to be set on if the absolute value of the index register X is equal to or greater than the data from memory. If the value of the memory is greater than the content of the index register X, carry is reset. If the results of the subtraction contain a bit 7, then the N flag is set, if not, it is reset. If the value in memory is equal to the value in index register X, the Z flag is set, otherwise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateCPX #$nn$E022
AbsoluteCPX $nnnn$EC34
Zero PageCPX $nn$E423

NV-BDIZC
-----

CPY - Compare Index Register Y To Memory

Operation: Y - M

This instruction performs a two's complement subtraction between the index register Y and the specified memory location. The results of the subtraction are not stored anywhere. The instruction is strictly used to set the flags.

CPY affects no registers in the microprocessor and also does not affect the overflow flag. If the value in the index register Y is equal to or greater than the value in the memory, the carry flag will be set, otherwise it will be cleared. If the results of the subtraction contain bit 7 on the N bit will be set, otherwise it will be cleared. If the value in the index register Y and the value in the memory are equal, the zero flag will be set, otherwise it will be cleared.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateCPY #$nn$C022
AbsoluteCPY $nnnn$CC34
Zero PageCPY $nn$C423

NV-BDIZC
------

DEC - Decrement Memory By One

Operation: M - 1 → M

This instruction subtracts 1, in two's complement, from the contents of the addressed memory location.

The decrement instruction does not affect any internal register in the microprocessor. It does not affect the carry or overflow flags. If bit 7 is on as a result of the decrement, then the N flag is set, otherwise it is reset. If the result of the decrement is 0, the Z flag is set, other­wise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteDEC $nnnn$CE36
X-Indexed AbsoluteDEC $nnnn,X$DE37
Zero PageDEC $nn$C625
X-Indexed Zero PageDEC $nn,X$D626

NV-BDIZC
------

DEX - Decrement Index Register X By One

Operation: X - 1 → X

This instruction subtracts one from the current value of the index register X and stores the result in the index register X.

DEX does not affect the carry or overflow flag, it sets the N flag if it has bit 7 on as a result of the decrement, otherwise it resets the N flag; sets the Z flag if X is a 0 as a result of the decrement, otherwise it resets the Z flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedDEX $CA12

NV-BDIZC
------

DEY - Decrement Index Register Y By One

Operation: Y - 1 → Y

This instruction subtracts one from the current value in the index register Y and stores the result into the index register Y. The result does not affect or consider carry so that the value in the index register Y is decremented to 0 and then through 0 to FF.

Decrement Y does not affect the carry or overflow flags; if the Y register contains bit 7 on as a result of the decrement the N flag is set, otherwise the N flag is reset. If the Y register is 0 as a result of the decrement, the Z flag is set otherwise the Z flag is reset. This instruction only affects the index register Y.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedDEY $8812

NV-BDIZC
------

EOR - "Exclusive OR" Memory with Accumulator

Operation: A ⊻ M → A

The EOR instruction transfers the memory and the accumulator to the adder which performs a binary "EXCLUSIVE OR" on a bit-by-bit basis and stores the result in the accumulator.

This instruction affects the accumulator; sets the zero flag if the result in the accumulator is 0, otherwise resets the zero flag sets the negative flag if the result in the accumulator has bit 7 on, otherwise resets the negative flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateEOR #$nn$4922
AbsoluteEOR $nnnn$4D34
X-Indexed AbsoluteEOR $nnnn,X$5D34+p
Y-Indexed AbsoluteEOR $nnnn,Y$5934+p
Zero PageEOR $nn$4523
X-Indexed Zero PageEOR $nn,X$5524
X-Indexed Zero Page IndirectEOR ($nn,X)$4126
Zero Page Indirect Y-IndexedEOR ($nn),Y$5125+p

p: =1 if page is crossed.

NV-BDIZC
------

INC - Increment Memory By One

Operation: M + 1 → M

This instruction adds 1 to the contents of the addressed memory location.

The increment memory instruction does not affect any internal registers and does not affect the carry or overflow flags. If bit 7 is on as the result of the increment,N is set, otherwise it is reset; if the increment causes the result to become 0, the Z flag is set on, otherwise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteINC $nnnn$EE36
X-Indexed AbsoluteINC $nnnn,X$FE37
Zero PageINC $nn$E625
X-Indexed Zero PageINC $nn,X$F626

NV-BDIZC
------

INX - Increment Index Register X By One

Operation: X + 1 → X

Increment X adds 1 to the current value of the X register. This is an 8-bit increment which does not affect the carry operation, therefore, if the value of X before the increment was FF, the resulting value is 00.

INX does not affect the carry or overflow flags; it sets the N flag if the result of the increment has a one in bit 7, otherwise resets N; sets the Z flag if the result of the increment is 0, otherwise it resets the Z flag.

INX does not affect any other register other than the X register.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedINX $E812

NV-BDIZC
------

INY - Increment Index Register Y By One

Operation: Y + 1 → Y

Increment Y increments or adds one to the current value in the Y register, storing the result in the Y register. As in the case of INX the primary application is to step thru a set of values using the Y register.

The INY does not affect the carry or overflow flags, sets the N flag if the result of the increment has a one in bit 7, otherwise resets N, sets Z if as a result of the increment the Y register is zero otherwise resets the Z flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedINY $C812

NV-BDIZC
--------

JMP - JMP Indirect

Operation: [PC + 1] → PCL, [PC + 2] → PCH

This instruction establishes a new value for the program counter.

It affects only the program counter in the microprocessor and affects no flags in the status register.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteJMP $nnnn$4C33
Absolute IndirectJMP ($nnnn)$6C35

NV-BDIZC
--------

JSR - Jump To Subroutine

Operation: PC + 2↓, [PC + 1] → PCL, [PC + 2] → PCH

This instruction transfers control of the program counter to a subroutine location but leaves a return pointer on the stack to allow the user to return to perform the next instruction in the main program after the subroutine is complete. To accomplish this, JSR instruction stores the program counter address which points to the last byte of the jump instruction onto the stack using the stack pointer. The stack byte contains the program count high first, followed by program count low. The JSR then transfers the addresses following the jump instruction to the program counter low and the program counter high, thereby directing the program to begin at that new address.

The JSR instruction affects no flags, causes the stack pointer to be decremented by 2 and substitutes new values into the program counter low and the program counter high.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteJSR $nnnn$2036

NV-BDIZC
------

LDA - Load Accumulator with Memory

Operation: M → A

When instruction LDA is executed by the microprocessor, data is transferred from memory to the accumulator and stored in the accumulator.

LDA affects the contents of the accumulator, does not affect the carry or overflow flags; sets the zero flag if the accumulator is zero as a result of the LDA, otherwise resets the zero flag; sets the negative flag if bit 7 of the accumulator is a 1, other­ wise resets the negative flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateLDA #$nn$A922
AbsoluteLDA $nnnn$AD34
X-Indexed AbsoluteLDA $nnnn,X$BD34+p
Y-Indexed AbsoluteLDA $nnnn,Y$B934+p
Zero PageLDA $nn$A523
X-Indexed Zero PageLDA $nn,X$B524
X-Indexed Zero Page IndirectLDA ($nn,X)$A126
Zero Page Indirect Y-IndexedLDA ($nn),Y$B125+p

p: =1 if page is crossed.

NV-BDIZC
------

LDX - Load Index Register X From Memory

Operation: M → X

Load the index register X from memory.

LDX does not affect the C or V flags; sets Z if the value loaded was zero, otherwise resets it; sets N if the value loaded in bit 7 is a 1; otherwise N is reset, and affects only the X register.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateLDX #$nn$A222
AbsoluteLDX $nnnn$AE34
Y-Indexed AbsoluteLDX $nnnn,Y$BE34+p
Zero PageLDX $nn$A623
Y-Indexed Zero PageLDX $nn,Y$B624

p: =1 if page is crossed.

NV-BDIZC
------

LDY - Load Index Register Y From Memory

Operation: M → Y

Load the index register Y from memory.

LDY does not affect the C or V flags, sets the N flag if the value loaded in bit 7 is a 1, otherwise resets N, sets Z flag if the loaded value is zero otherwise resets Z and only affects the Y register.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateLDY #$nn$A022
AbsoluteLDY $nnnn$AC34
X-Indexed AbsoluteLDY $nnnn,X$BC34+p
Zero PageLDY $nn$A423
X-Indexed Zero PageLDY $nn,X$B424

p: =1 if page is crossed.

NV-BDIZC
0-----

LSR - Logical Shift Right

Operation: 0 → /M7...M0/ → C

This instruction shifts either the accumulator or a specified memory location 1 bit to the right, with the higher bit of the result always being set to 0, and the low bit which is shifted out of the field being stored in the carry flag.

The shift right instruction either affects the accumulator by shifting it right 1 or is a read/modify/write instruction which changes a specified memory location but does not affect any internal registers. The shift right does not affect the overflow flag. The N flag is always reset. The Z flag is set if the result of the shift is 0 and reset otherwise. The carry is set equal to bit 0 of the input.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AccumulatorLSR A$4A12
AbsoluteLSR $nnnn$4E36
X-Indexed AbsoluteLSR $nnnn,X$5E37
Zero PageLSR $nn$4625
X-Indexed Zero PageLSR $nn,X$5626

NV-BDIZC
--------

NOP - No Operation

Operation: No operation

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedNOP $EA12

NV-BDIZC
------

ORA - "OR" Memory with Accumulator

Operation: A ∨ M → A

The ORA instruction transfers the memory and the accumulator to the adder which performs a binary "OR" on a bit-by-bit basis and stores the result in the accumulator.

This instruction affects the accumulator; sets the zero flag if the result in the accumulator is 0, otherwise resets the zero flag; sets the negative flag if the result in the accumulator has bit 7 on, otherwise resets the negative flag.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateORA #$nn$0922
AbsoluteORA $nnnn$0D34
X-Indexed AbsoluteORA $nnnn,X$1D34+p
Y-Indexed AbsoluteORA $nnnn,Y$1934+p
Zero PageORA $nn$0523
X-Indexed Zero PageORA $nn,X$1524
X-Indexed Zero Page IndirectORA ($nn,X)$0126
Zero Page Indirect Y-IndexedORA ($nn),Y$1125+p

p: =1 if page is crossed.

NV-BDIZC
--------

PHA - Push Accumulator On Stack

Operation: A↓

This instruction transfers the current value of the accumulator to the next location on the stack, automatically decrementing the stack to point to the next empty location.

The Push A instruction only affects the stack pointer register which is decremented by 1 as a result of the operation. It affects no flags.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedPHA $4813

NV-BDIZC
--------

PHP - Push Processor Status On Stack

Operation: P↓

This instruction transfers the contents of the processor status register unchanged to the stack, as governed by the stack pointer.

The PHP instruction affects no registers or flags in the microprocessor.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedPHP $0813

NV-BDIZC
------

PLA - Pull Accumulator From Stack

Operation: A↑

This instruction adds 1 to the current value of the stack pointer and uses it to address the stack and loads the contents of the stack into the A register.

The PLA instruction does not affect the carry or overflow flags. It sets N if the bit 7 is on in accumulator A as a result of instructions, otherwise it is reset. If accumulator A is zero as a result of the PLA, then the Z flag is set, otherwise it is reset. The PLA instruction changes content of the accumulator A to the contents of the memory location at stack register plus 1 and also increments the stack register.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedPLA $6814

NV-BDIZC
--

PLP - Pull Processor Status From Stack

Operation: P↑

This instruction transfers the next value on the stack to the Processor Status register, thereby changing all of the flags and setting the mode switches to the values from the stack.

The PLP instruction affects no registers in the processor other than the status register. This instruction could affect all flags in the status register.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedPLP $2814

NV-BDIZC
-----

ROL - Rotate Left

Operation: C ← /M7...M0/ ← C

The rotate left instruction shifts either the accumulator or addressed memory left 1 bit, with the input carry being stored in bit 0 and with the input bit 7 being stored in the carry flags.

The ROL instruction either shifts the accumulator left 1 bit and stores the carry in accumulator bit 0 or does not affect the internal registers at all. The ROL instruction sets carry equal to the input bit 7, sets N equal to the input bit 6 , sets the Z flag if the result of the rotate is 0, otherwise it resets Z and does not affect the overflow flag at all.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AccumulatorROL A$2A12
AbsoluteROL $nnnn$2E36
X-Indexed AbsoluteROL $nnnn,X$3E37
Zero PageROL $nn$2625
X-Indexed Zero PageROL $nn,X$3626

NV-BDIZC
-----

ROR - Rotate Right

Operation: C → /M7...M0/ → C

The rotate right instruction shifts either the accumulator or addressed memory right 1 bit with bit 0 shifted into the carry and carry shifted into bit 7.

The ROR instruction either shifts the accumulator right 1 bit and stores the carry in accumulator bit 7 or does not affect the internal registers at all. The ROR instruction sets carry equal to input bit 0, sets N equal to the input carry and sets the Z flag if the result of the rotate is 0; otherwise it resets Z and does not affect the overflow flag at all.

(Available on Microprocessors after June, 1976)

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AccumulatorROR A$6A12
AbsoluteROR $nnnn$6E36
X-Indexed AbsoluteROR $nnnn,X$7E37
Zero PageROR $nn$6625
X-Indexed Zero PageROR $nn,X$7626

NV-BDIZC
--

RTI - Return From Interrupt

Operation: P↑ PC↑

This instruction transfers from the stack into the microprocessor the processor status and the program counter location for the instruction which was interrupted. By virtue of the interrupt having stored this data before executing the instruction and the fact that the RTI reinitializes the microprocessor to the same state as when it was interrupted, the combination of interrupt plus RTI allows truly reentrant coding.

The RTI instruction reinitializes all flags to the position to the point they were at the time the interrupt was taken and sets the program counter back to its pre-interrupt state. It affects no other registers in the microprocessor.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedRTI $4016

NV-BDIZC
--------

RTS - Return From Subroutine

Operation: PC↑, PC + 1 → PC

This instruction loads the program count low and program count high from the stack into the program counter and increments the program counter so that it points to the instruction following the JSR. The stack pointer is adjusted by incrementing it twice.

The RTS instruction does not affect any flags and affects only PCL and PCH.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedRTS $6016

NV-BDIZC
----

SBC - Subtract Memory from Accumulator with Borrow

Operation: A - M - ~C → A

This instruction subtracts the value of memory and borrow from the value of the accumulator, using two's complement arithmetic, and stores the result in the accumulator. Borrow is defined as the carry flag complemented; therefore, a resultant carry flag indicates that a borrow has not occurred.

This instruction affects the accumulator. The carry flag is set if the result is greater than or equal to 0. The carry flag is reset when the result is less than 0, indicating a borrow. The over­flow flag is set when the result exceeds +127 or -127, otherwise it is reset. The negative flag is set if the result in the accumulator has bit 7 on, otherwise it is reset. The Z flag is set if the result in the accumulator is 0, otherwise it is reset.

Note on the MOS 6502:

In decimal mode, the N, V and Z flags are not consistent with the decimal result.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImmediateSBC #$nn$E922
AbsoluteSBC $nnnn$ED34
X-Indexed AbsoluteSBC $nnnn,X$FD34+p
Y-Indexed AbsoluteSBC $nnnn,Y$F934+p
Zero PageSBC $nn$E523
X-Indexed Zero PageSBC $nn,X$F524
X-Indexed Zero Page IndirectSBC ($nn,X)$E126
Zero Page Indirect Y-IndexedSBC ($nn),Y$F125+p

p: =1 if page is crossed.

NV-BDIZC
-------1

SEC - Set Carry Flag

Operation: 1 → C

This instruction initializes the carry flag to a 1. This operation should normally precede a SBC loop. It is also useful when used with a ROL instruction to initialize a bit in memory to a 1.

This instruction affects no registers in the microprocessor and no flags other than the carry flag which is set.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedSEC $3812

NV-BDIZC
----1---

SED - Set Decimal Mode

Operation: 1 → D

This instruction sets the decimal mode flag D to a 1. This makes all subsequent ADC and SBC instructions operate as a decimal arithmetic operation.

SED affects no registers in the microprocessor and no flags other than the decimal mode which is set to a 1.

Note on the MOS 6502:

The value of the decimal mode flag is indeterminate after a RESET.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedSED $F812

NV-BDIZC
-----1--

SEI - Set Interrupt Disable

Operation: 1 → I

This instruction initializes the interrupt disable to a 1. It is used to mask interrupt requests during system reset operations and during interrupt commands.

It affects no registers in the microprocessor and no flags other than the interrupt disable which is set.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedSEI $7812

NV-BDIZC
--------

STA - Store Accumulator in Memory

Operation: A → M

This instruction transfers the contents of the accumulator to memory.

This instruction affects none of the flags in the processor status register and does not affect the accumulator.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteSTA $nnnn$8D34
X-Indexed AbsoluteSTA $nnnn,X$9D35
Y-Indexed AbsoluteSTA $nnnn,Y$9935
Zero PageSTA $nn$8523
X-Indexed Zero PageSTA $nn,X$9524
X-Indexed Zero Page IndirectSTA ($nn,X)$8126
Zero Page Indirect Y-IndexedSTA ($nn),Y$9126

NV-BDIZC
--------

STX - Store Index Register X In Memory

Operation: X → M

Transfers value of X register to addressed memory location.

No flags or registers in the microprocessor are affected by the store operation.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteSTX $nnnn$8E34
Zero PageSTX $nn$8623
Y-Indexed Zero PageSTX $nn,Y$9624

NV-BDIZC
--------

STY - Store Index Register Y In Memory

Operation: Y → M

Transfer the value of the Y register to the addressed memory location.

STY does not affect any flags or registers in the microprocessor.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
AbsoluteSTY $nnnn$8C34
Zero PageSTY $nn$8423
X-Indexed Zero PageSTY $nn,X$9424

NV-BDIZC
------

TAX - Transfer Accumulator To Index X

Operation: A → X

This instruction takes the value from accumulator A and transfers or loads it into the index register X without disturbing the content of the accumulator A.

TAX only affects the index register X, does not affect the carry or overflow flags. The N flag is set if the resultant value in the index register X has bit 7 on, otherwise N is reset. The Z bit is set if the content of the register X is 0 as a result of the operation, otherwise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedTAX $AA12

NV-BDIZC
------

TAY - Transfer Accumulator To Index Y

Operation: A → Y

This instruction moves the value of the accumulator into index register Y without affecting the accumulator.

TAY instruction only affects the Y register and does not affect either the carry or overflow flags. If the index register Y has bit 7 on, then N is set, otherwise it is reset. If the content of the index register Y equals 0 as a result of the operation, Z is set on, otherwise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedTAY $A812

NV-BDIZC
------

TSX - Transfer Stack Pointer To Index X

Operation: S → X

This instruction transfers the value in the stack pointer to the index register X.

TSX does not affect the carry or overflow flags. It sets N if bit 7 is on in index X as a result of the instruction, otherwise it is reset. If index X is zero as a result of the TSX, the Z flag is set, other­ wise it is reset. TSX changes the value of index X, making it equal to the content of the stack pointer.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedTSX $BA12

NV-BDIZC
------

TXA - Transfer Index X To Accumulator

Operation: X → A

This instruction moves the value that is in the index register X to the accumulator A without disturbing the content of the index register X.

TXA does not affect any register other than the accumulator and does not affect the carry or overflow flag. If the result in A has bit 7 on, then the N flag is set, otherwise it is reset. If the resultant value in the accumulator is 0, then the Z flag is set, other­ wise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedTXA $8A12

NV-BDIZC
--------

TXS - Transfer Index X To Stack Pointer

Operation: X → S

This instruction transfers the value in the index register X to the stack pointer.

TXS changes only the stack pointer, making it equal to the content of the index register X. It does not affect any of the flags.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedTXS $9A12

NV-BDIZC
------

TYA - Transfer Index Y To Accumulator

Operation: Y → A

This instruction moves the value that is in the index register Y to accumulator A without disturbing the content of the register Y.

TYA does not affect any other register other than the accumulator and does not affect the carry or overflow flag. If the result in the accumulator A has bit 7 on, the N flag is set, otherwise it is reset. If the resultant value in the accumulator A is 0, then the Z flag is set, otherwise it is reset.

Addressing ModeAssembly Language FormOpcodeNo. BytesNo. Cycles
ImpliedTYA $9812


Load/Store
Transfer
Stack
Shift
Logic
Arithmetic
Arithmetic: Inc/Dec
Control Flow
Control Flow: Branch
Flags
KIL
NOP