Syncopated Systems
Seriously Sound Science

On the 6502 Microprocessor

I was born and raised in Silicon Valley.

Shortly after my family moved in 1978 to Sunnyvale—roughly half-way between Apple and Atari—I became fascinated by the microcomputer revolution that started in 1977 with the introduction of the Atari Video Computer System (VCS, later known as the Atari 2600) and Byte Magazine’s “1977 Trinity” of home computers: Apple II, Commodore PET 2001, and Tandy/Radio Shack TRS-80.

Most of these were made possible by the 6502 (“sixty-five oh two”) microprocessor that MOS Technology created in 1975.

The 6502 was the CPU (central processing unit) in both the Apple II and the Commodore PET 2001. One of its variants, 6507, was the CPU in the Atari Video Computer System that popularized cartridge-based video games, which were introduced in 1976 by the Fairchild Channel F Video Entertainment System (VES). (A Fairchild F8 microprocessor was its CPU. The TRS-80’s CPU was a Zilog Z80, which I pronounce “zee eighty” and was released in 1976.)

The popular designs of 6502 and its variants were licensed for manufacture by others including Rockwell International and Synertek.

In 1979, the Atari 400 and Atari 800 computers were introduced using a revised 6502, the 6502B made by Synertek (Atari part number C014377-03). Later units and their successors used a custom 6502 variant that Atari named Sally (Atari part number C014806), which appears to be the basis for the 6502C. (Note that the “C” suffix indicates the third revision—and fourth version—of the mainstream 6502, not the 65C02, which was a CMOS version.)

Some of my neighbors got Atari computers, and one of the key developers of Atari BASIC and Atari DOS had grown up across the street.

After using a borrowed single-board computer (with an RCA 1802 microprocessor) to learn a bit about machine code (hexadecimal representations of instructions and data), I got an Atari 800, became active in the local community of Atari users (largely through the Bay Area Atari Users Group, BAAUG), set up shop repairing Atari products, worked at Atari providing customer technical support (a summer job between my last two years of high school), and about 1.5 years later started working for Atari’s founder, Nolan Bushnell.

Not long afterward, while in college I tested games for Activision and Infocom labels (for Mediagenic) on PCs and the 1985 Nintendo Entertainment System, which used variants of the 6502 made by Ricoh.

Later, while working for video game developer Iguana Entertainment—and moving with it to Austin, Texas—I created interface hardware to enable software-development, including versions for its 1990 successor, the Super Nintendo Entertainment System (SNES), which for its CPU used a modernized derivative of the 6502 based on the Western Design Center (WDC) 65C816 (“sixty-five-see-eight-sixteen”) released in 1983. (The 65C816 was also the CPU in the Apple IIgs released in 1986, which I saw in use at Mediagenic for early development of SNES games.)

Roots in the Motorola 6800

Based in Valley Forge, Pennsylvania, MOS Technology was formed in 1969 by three former executives of General Instrument.

After Motorola released its 6800 (“sixty-eight hundred”) microprocessor in 1974, several of its former designers wished not to be relocated by Motorola from Mesa, Arizona to Austin, Texas. So, they instead joined MOS Technology and in 1975 they created both the 6502 and its sibling the 6501 as simpler, lower-cost, and higher-performance alternatives to the 6800. Though neither the 6501 nor 6502 were compatible with 6800 software, the 6501 could be used as a pin-compatible replacement for the 6800. Both the 6501 and the 6502 were designed to be compatible with support chips for the 6800; for example, the 1976 Apple Computer 1 included both a 6502 CPU and a 6820 PIA (peripheral interface adapter).

In September 1975, the 6501 and the 6502 cost only $20 and $25 (respectively), prompting Motorola in October 1975 to reduce the price of its 6800 from $175 to $69.

In November 1975, Motorola sued MOS Technology, seeking injunction to stop MOS Technology from making and selling microprocessors, claiming patent infringement and misappropriation of trade secrets through seven of its former employees who joined MOS Technology. The pin-compatible 6501 did not survive. (I recall that, when I was a kid becoming interested in computers circa 1980, one of my favorite stores carried adapter modules that would allow a 6502 to be plugged into a circuit board designed for a 6800 microprocessors, allowing a 6502 to nearly mimic the functions of a 6501.)

MOS Technology was acquired in November 1976 by Commodore International (parent of Commodore Business Machines, which later made the PET, VIC-20, Commodore 64, and others), with the condition that the 6502 designer Chuck Peddle would become Commodore’s chief engineer. (I was lucky enough to meet Chuck Peddle briefly in 2016.)

6800’s Legacy

In 1979, Motorola launched its 68000 microprocessor, which dominated much of the second generation of microcomputers as the CPU in Apple Macintosh (1984), Atari ST and Commodore Amiga (both 1985), and the Sega Genesis video game console (circa 1989). It could have been in the IBM PC (1982), though the popular story was that the 68000 wasn’t ready in time to meet IBM’s development timeline. (In 1988, my manager at IBM claimed it had been a marketing decision to use the less-powerful Intel 8088 so that the IBM PC would not be able to compete against its line of workstations.)

Around 1984, Motorola had released microcontrollers based on the 6800, including the popular 68HC11 (“HC” for “high-speed CMOS”) that I had began experimenting with around 1989 after buying a development kit it sold me for $68.11.

After Motorola spun off part of its Semiconductor Products Division in 2004 to create Austin-based Freescale Semiconductor, in or around 2007 I had interviewed to become the program manager for its ColdFire product line, which Motorola had launched in 1994 to offer embedded microcontroller versions of the 68000 series microprocessors it launched in 1979, extending the 6800 microprocessor line. (Though I wasn’t successful in landing the job, I still feel honored to have been interviewed as a candidate.)

How Processors Became Microprocessors

Microprocessors are a type of integrated circuit, which is a type of semiconductor device that integrates many components of a larger electronic circuit into a single device.

Integrated Circuits and Silicon Chips

Integrated circuits are fabricated on flat round wafers sliced from an ingot and then fabricated through processes that combine printing (as through electron-beam lithography from reticles for each process layer), doping, and growing non-conductive oxides. When wafer fabrication is complete, the wafer is scored in two directions along the boundaries of each rectangular (sometimes square) die. While still on the wafer, each die is tested; the bad ones are marked for exclusion and the good ones are removed as “chips” from the wafer and usually packaged with a leadframe so that it may be mounted more easily on a printed circuit board (PCB). Some applications (such as early digital wristwatches) use a process known as chip on board (COB) to mount chips directly to printed circuit boards, where they are wire bonded and encapsulated.

Though germanium or other semiconducting elements may be used, many chips were made from silicon and are therefore called silicon chips. Many early silicon chips were made in California’s Santa Clara Valley, leading to its now-popular metonym Silicon Valley.

The Blocks from which a Computer is Built

The first commercially-available transistorized computers (second-generation computers) became available in the late 1950s. Many computer companies then built transistor-based interchangeable modules to perform basic logic functions on printed circuit board assemblies.

My father worked for one of these companies, Control Data Corporation, and I started learning about electronics and computers with some of the transistor-based assemblies it discarded.

The first computer based on silicon integrated circuits was the Apollo Guidance Computer (AGC), which was introduced in 1966 and enabled people to visit the Moon beginning in 1969.

Small-Scale Integration

The logic chips in the Apollo Guidance Computer are an example of small-scale integration (SSI), through which small numbers of multiple transistors on single chips integrate a function of a larger of a circuit.

The designers of the Apollo Guidance Computer’s original architecture (Block I) were able to simplify their task of qualifying components for spaceflight by building it using only one type of device, which contained two isolated (dual) triple-input NOR gates. This was possible because NOR gates (and NAND gates) are universal logic gates from which any other gate can be made. (Some other types of integrated circuits were added to the later Block II design.)

(These NOR devices were fabricated by Fairchild Semiconductor, at what I believe was either of its Silicon Valley facilities—in north Mountain View or on Bernal Road in south San Jose—which were both later among many Environmental Protection Agency toxic waste Superfund sites in Silicon Valley directly attributable to the early semiconductor industry that gave it its name.)

(In 2019, as part of a celebration of the 50th anniversary of the first people landing on the Moon, for some friends I designed a printed circuit board that connected to and helped some friends restore an Apollo Guidance Computer to operation. Shortly afterward, I happened to meet Margaret Hamilton, who directed software engineering for the Apollo Program and for her work received the Presidential Medal of Freedom from Barack Obama in 2016.)

Types of Transistor Logic

These devices used a resistor-transistor logic (RTL) configuration, through which resistors are used to bias nodes of a circuit toward a binary logic state’s voltage level when not actively driven by a transistor toward the voltage level representing the other binary state.

Texas Instruments had introduced a series of SSI integrated circuits with transistor-transistor logic (TTL) by 1973, when it released its (uniquely hardcover) TTL Data Book for Design Engineers.

As I entered my teenage years, my friend (and formerly my father’s office mate while at the Sunnyvale office of Control Data Corporation) LaFarr Stuart “loaned” me a copy of this book (which I still have and treasure) along with a logic trainer kit made by Digital Equipment Corporation (DEC) and likely intended for college students. My junior high school had once been a high school, so I was able to borrow from its library a copy of Don Lancaster’s 1974 The TTL Cookbook.

One key benefit of TTL is that it doesn’t need as much power to operate as RTL (and DTL, which is diode-transistor logic). This is because the addition of a second transistor effectively shuts off power to the output when the other transistor drives it.

The term TTL describes the configuration of the devices to create the logic circuit, not their construction. Although the first TTL devices used bipolar junction transistors (BJTs), TTL also includes later devices made using field-effect transistors (FETs) including those made using metal-oxide-silicon (MOS) processes, sometimes called MOSFETs.

A key benefit of MOSFETs is that they switch based on voltage levels, not varying flows of current as in BJTs. So, MOSFET circuits are more power efficient than similar circuits constructed from BJTs.

Using MOSFETs, a TTL configuration requires types of both negative-channel MOS (NMOS) and positive-channel MOS (PMOS), a combination called complimentary metal-oxide-silicon (CMOS).

Note that the 6502, 6502A, 6502B, and 6502C were NMOS devices. The WDC 65C02 was a later CMOS device. (The 6502 was released in 1975 and 6502B was used in early Atari 8-bit computers starting in 1979. The 65C02 was released in 1983.)

6502 Architecture

The 6502 design follows the Von Neumann (Princeton) architecture pattern (established in 1945), which essentially doesn’t differentiate addresses for instructions and data as it would had it employed Harvard architecture.

While operating, a 6502 follows a program (ordered list) of instructions to copy data between its registers (X index, Y index, an accumulator, stack pointer, and processor status register) and locations it can address containing random-access memories (including read-only memory, or ROM) or other devices. With this data, it performs simple arithmetic operations and determines which paths of its program to execute.

Processor Status Register Flags

The 6502’s processor status register uses 7 bits as flags to detect and enable certain conditions. These flags are arranged in the order { N V - B D I Z C }, further described in the following table.

BitPlaceFlagDescription
7128NNegative detected if set (N==1)
664VoVerflow detected if set (V==1)
532-unused
416BBreak detected if set (B==1)
38DDecimal (packed binary-coded decimal, BCD) mode enabled if set (D==1)
24IInterrupts enabled if set (I==1)
12ZZero detected if set (Z==1)
01CCarry

Instruction Set

To perform its operations, the 6502 uses a set of 56 instructions. (The first version of the 6502 had only 55 instructions, with the ROR instruction added to later versions.)

Operation Codes

Microprocessors use a number to represent each combintation of intruction and the format it can use for each operation, which are often variations in addressing mode modes available to use the instruction. These numbers are called operation codes, a term often shortened to “op codes” or “opcodes”.

The 6502 (and any other microprocessor that stores opcodes as single 8-bit bytes) can have up to 256 (28) of them. For its 56 instructions and their variants, the 6502 uses only 151 of the 256 possible opcodes. In contrast, the more-expensive Motorola 6800 from which the 6502 was allegedly derived included 197 opcodes to represent 72 instructions and their variations. (If a microprocessor of this era would encounter and attempt to execute an undocumented opcode, its behavior would be likely undesirable and potentially unpredictable.)

Opcode Maps

The instructions and their variations have often been presented in tables often called “opcode maps”. These generally present terse information about each opcode (a mnemonic abbreviation and little else) in square tables of 16 columns by 16 rows, arranged in numerical order based on each opcode number’s lowest 4 bits (corresponding to the least-significant of its two hexadecimal digits) along one axis and the highest 4 bits (the most-significant digit, or MSD) along the other. (Groups of consecutive 4 bits are sometimes referred to as a nibble or nybble, apparently depending on whether one sees it as 4 bits or half a byte.)

Key to colors used to represent addressing modes in the table that follows:

Length Addressing Modes
1 byte: implied accumulator
2 bytes: relative immediate
2 bytes: zero page zero page,X zero page,Y
2 bytes:   indirect,X indirect,Y
3 bytes: indirect    
3 bytes: absolute absolute,X absolute,Y

Note that dark gray areas indicate operation codes that are undefined for the 6502.

The thick black borders indicate that the JSR and indirect JMP instructions deviate somewhat from the pattern.

MSD
← Hexadecimal Least-Significant Digit (LSD) →
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 BEQ 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  
Length: 1,2 (3) 2 2 N/A 2 2 2 N/A 1 2,3 1 N/A 3 3 3 N/A

The Trouble with Opcode Maps

For most users, I believe that tables of opcodes arranged by their machine code numbers is about as useful as a table that presents information about the known chemical elements arranged by their colors. Generally, these tables help only if you have only an opcode number and need its mnemonic abbreviation; they make it difficult to infer logical connections between opcodes of similar functions and addressing modes (though some can often be done through color coding).

So, some re-arrangement is in order.

A Better Order for Instruction Bits

Like other microprocessors, especially those of early economical design, the 6502 encodes into a single word (in this case, an 8-bit byte) both the function of the instruction and variations in addressing modes.

Unfortunately for users of square opcode maps, some of the bits used to form one number aren’t adjacent; in the 6502, the 8 bits of an opcode (with the most-significant bit first, on the left) follow the pattern AAABBBCC, where BBB represents the addressing mode. The remaining bits specify the function to be performed. (I expect that there were economic benefits behind such choices when the 6502 was being designed.)

These last bits, I will describe as the code (or number) that defines the instruction.

Rather than keep the groups of bits in their original order to form the pattern AAACC, I find that maps of 6502 opcodes are easier to understand in the order CCAAA. Thus, I present them using that order to form the following table. For simplicity, I keep the bits within those groups in the same order.

For example, the instruction with mnemonic code NOP is represented numerically as hexadecimal 0xEA or binary 11101010. Divided into groups using the pattern AAABBBCC, this is 111 010 10. Swapping the order of groups AAA and CC yields the instruction code 10 111 (23) with the address mode remaining in group BBB as 010 (2), which in the following table correlate to the headings for rows and columns, respectively.

In the table that follows, instructions are organized into groups as below, some with backgrounds color-coded to indicate types of instructions (rather than their addressing mode), as listed below. Additionally, superscript annotations indicate that one or two cycle(s) more (than the minimum number of a given range) will be required when (B) a conditional branch is taken and/or (P) crossing a page boundary.

8instructions that each are available with 7-8 (roughly all) addressing modes (rows 8-15)
12instructions that each are available with 3-5 (roughly half of) addressing modes (rows 4-7, 16-23)
2instructions that each are available with 2 addressing modes (BIT & JMP, in rows 1-3)
8register instructions
8branch instructions
7status instructions
6stack instructions
5other instructions (BRK, JSR, RTI, RTS, NOP)
56total

As in the previous table, addressing modes are highlighted using the same colors and the thick black borders indicate that the JSR and indirect JMP instructions deviate somewhat from the pattern.

Instr.
Code
← Addressing Mode →
0 1 2 3 4 5 6 7
0 BRKBReaK – affects flag B   PHPPusH Processor status – affects flags ?   BPLBranch on PLus – no flags affected   CLCCLear Carry – assigns flag C=0  
BRK
implied
1 byte
7 cycles

00

PHP
implied
1 byte
3 cycles

08

BPL #$hh
relative
2 bytes
2-4 cyclesB,P

10

CLC
implied
1 byte
2 cycles

18

1 BITtest BITs – affects flags N V Z
JSRJump to SubRoutine – no flags affected BIT $hh
zero page
2 bytes
3 cycles

24

PLPPuLl (pop) Processor status – affects flags ? BIT $hhhh
absolute
3 bytes
4 cycles

2C

BMIBranch on MInus – no flags affected   SECSEt Carry – assigns flag C=1  
JSR $hhhh
absolute
3 bytes
6 cycles

20

PLP
implied
1 byte
4 cycles

28

BMI #$hh
relative
2 bytes
2-4 cyclesB,P

30

SEC
implied
1 byte
2 cycles

38

2 RTIReTurn from Interrupt – affects all flags N V B D I Z C   PHAPusH Accumulator – affects flags ? JMPJuMP – no flags affected BVCBranch on oVerflow Clear – no flags affected   CLICLear Interrupt – assigns flag I=0  
RTI
implied
1 byte
6 cycles

40

PHA
implied
1 byte
3 cycles

48

JMP $hhhh
absolute
3 bytes
3 cycles

4C

BVC #$hh
relative
2 bytes
2-4 cyclesB,P

50

CLI
implied
1 byte
2 cycles

58

3 RTSReTurn from Subroutine – no flags affected   PLAPuLl (pop) Accumulator – affects flags ? JMPJuMP – no flags affected BVSBranch on oVerflow Set – no flags affected   SEISEt Interrupt – assigns flag I=1  
RTS
implied
1 byte
6 cycles

60

PLA
implied
1 byte
4 cycles

68

JMP ($hhhh)
indirect
3 bytes
5 cycles

6C

BVS #$hh
relative
2 bytes
2-4 cyclesB,P

70

SEI
implied
1 byte
2 cycles

78

4 STYSTore Y register – no flags affected
  STY $hh
zero page
2 bytes
3 cycles

84

DEYDEcrement Y – affects flags N Z STY $hhhh
absolute
3 bytes
4 cycles

AC

BCCBranch on Carry Clear – no flags affected STY $hh,X
zero page,X
2 bytes
4 cycles

94

TYATransfer Y to A – affects flags N Z  
DEY
implied
1 byte
2 cycles

88

BCC #$hh
relative
2 bytes
2-4 cyclesB,P

90

TYA
implied
1 byte
2 cycles

98

5 LDYLoaD Y register – affects flags N Z
LDY #$hh
immediate
2 bytes
3 cycles

A0

LDY $hh
zero page
2 bytes
3 cycles

A4

TAYTransfer A to Y – affects flags N Z LDY $hhhh
absolute
3 bytes
4 cycles

AC

BCSBranch on Carry Set – no flags affected LDY $hh,X
zero page,X
2 bytes
4 cycles

B4

CLVCLear oVerflow – assigns flag V=0 LDY $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

BC

TAY
implied
1 byte
2 cycles

A8

BCS #$hh
relative
2 bytes
2-4 cyclesB,P

B0

CLV
implied
1 byte
2 cycles

B8

6 CPYComPare Y register – affects flags N Z C
CPY $hh
immediate
2 bytes
2 cycles

C0

CPY $hh
zero page
2 bytes
3 cycles

C4

INYINcrement Y – affects flags N Z CPY $hhhh
absolute
3 bytes
4 cycles

CC

BNEBranch on Not Equal – no flags affected   CLDCLear Decimal – assigns flag D=0  
INY
implied
1 byte
2 cycles

C8

BNE #$hh
relative
2 bytes
2-4 cyclesB,P

D0

CLD
implied
1 byte
2 cycles

D8

7 CPXComPare X register – affects flags N Z C
CPX $hh
immediate
2 bytes
2 cycles

E0

CPX $hh
zero page
2 bytes
3 cycles

E4

INXINcrement X – affects flags N Z CPX $hhhh
absolute
3 bytes
4 cycles

EC

BEQBranch on EQual – no flags affected   SEDSEt Decimal – assigns flag D=1  
INX
implied
1 byte
2 cycles

E8

BEQ #$hh
relative
2 bytes
2-4 cyclesB,P

F0

SED
implied
1 byte
2 cycles

F8

8 ORAbitwise OR with Accumulator – affects flags N Z
ORA ($hh,X)
indirect,X
2 bytes
6 cycles

01

ORA $hh
zero page
2 bytes
3 cycles

05

ORA #$hh
immediate
2 bytes
4 cycles

09

ORA $hhhh
absolute
3 bytes
5-6 cyclesP

0D

ORA ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

11

ORA $hh,X
zero page,X
2 bytes
4 cycles

15

ORA $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

19

ORA $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

1D

9 ANDbitwise AND with accumulator – affects flags N Z
AND ($hh,X)
indirect,X
2 bytes
6 cycles

21

AND $hh
zero page
2 bytes
3 cycles

25

AND #$hh
immediate
2 bytes
4 cycles

29

AND $hhhh
absolute
3 bytes
5-6 cyclesP

2D

AND ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

31

AND $hh,X
zero page,X
2 bytes
4 cycles

35

AND $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

39

AND $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

3D

10 EORbitwise Exclusive OR – affects flags N Z
EOR ($hh,X)
indirect,X
2 bytes
6 cycles

41

EOR $hh
zero page
2 bytes
3 cycles

45

EOR #$hh
immediate
2 bytes
4 cycles

49

EOR $hhhh
absolute
3 bytes
5-6 cyclesP

4D

EOR ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

51

EOR $hh,X
zero page,X
2 bytes
4 cycles

55

EOR $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

59

EOR $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

5D

11 ADCADd with Carry – affects flags N V Z C
ADC ($hh,X)
indirect,X
2 bytes
6 cycles

61

ADC $hh
zero page
2 bytes
3 cycles

65

ADC #$hh
immediate
2 bytes
4 cycles

69

ADC $hhhh
absolute
3 bytes
5-6 cyclesP

6D

ADC ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

71

ADC $hh,X
zero page,X
2 bytes
4 cycles

75

ADC $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

79

ADC $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

7D

12 STASTore Accumulator – no flags affected
STA ($hh,X)
indirect,X
2 bytes
6 cycles

81

STA $hh
zero page
2 bytes
3 cycles

85

  STA $hhhh
absolute
3 bytes
5-6 cyclesP

8D

STA ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

91

STA $hh,X
zero page,X
2 bytes
4 cycles

95

STA $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

99

STA $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

9D

13 LDALoaD Accumulator – affects flags N Z
LDA ($hh,X)
indirect,X
2 bytes
6 cycles

A1

LDA $hh
zero page
2 bytes
3 cycles

A5

LDA #$hh
immediate
2 bytes
4 cycles

A9

LDA $hhhh
absolute
3 bytes
5-6 cyclesP

AD

LDA ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

B1

LDA $hh,X
zero page,X
2 bytes
4 cycles

B5

LDA $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

B9

LDA $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

BD

14 CMPCoMPare accumulator – no flags affected
CMP ($hh,X)
indirect,X
2 bytes
6 cycles

C1

CMP $hh
zero page
2 bytes
3 cycles

C5

CMP #$hh
immediate
2 bytes
4 cycles

C9

CMP $hhhh
absolute
3 bytes
5-6 cyclesP

CD

CMP ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

D1

CMP $hh,X
zero page,X
2 bytes
4 cycles

D5

CMP $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

D9

CMP $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

DD

15 SBCSuBtract with Carry – affects flags N V Z C
SBC ($hh,X)
indirect,X
2 bytes
6 cycles

E1

SBC $hh
zero page
2 bytes
3 cycles

E5

SBC #$hh
immediate
2 bytes
4 cycles

E9

SBC $hhhh
absolute
3 bytes
5-6 cyclesP

ED

SBC ($hh),Y
indirect,Y
2 bytes
5-6 cyclesP

F1

SBC $hh,X
zero page,X
2 bytes
4 cycles

F5

SBC $hhhh,Y
absolute,Y
3 bytes
4-5 cyclesP

F9

SBC $hhhh,X
absolute,X
3 bytes
4-5 cyclesP

FD

16 ASLArithmetic Shift Left – affects flags N Z C
  ASL $hh
zero page
2 bytes
5 cycles

06

ASL A
accumulator
1 byte
2 cycles

0A

ASL $hhhh
absolute
3 bytes
6 cycles

0E

  ASL $hh,X
zero page,X
2 bytes
6 cycles

16

  ASL $hhhh,X
absolute,X
3 bytes
7 cycles

1E

17 ROLROtate Left – affects flags N Z C
  ROL $hh
zero page
2 bytes
5 cycles

26

ROL A
accumulator
1 byte
2 cycles

2A

ROL $hhhh
absolute
3 bytes
6 cycles

2E

  ROL $hh,X
zero page,X
2 bytes
6 cycles

36

  ROL $hhhh,X
absolute,X
3 bytes
7 cycles

3E

18 LSRLogical Shift Right – affects flags N Z C
  LSR $hh
zero page
2 bytes
5 cycles

46

LSR A
accumulator
1 byte
2 cycles

4A

LSR $hhhh
absolute
3 bytes
6 cycles

4E

  LSR $hh,X
zero page,X
2 bytes
6 cycles

56

  LSR $hhhh,X
absolute,X
3 bytes
7 cycles

5E

19 RORROtate Right – affects flags N Z C
  ROR $hh
zero page
2 bytes
5 cycles

66

ROR A
accumulator
1 byte
2 cycles

6A

ROR $hhhh
absolute
3 bytes
6 cycles

6E

  ROR $hh,X
zero page,X
2 bytes
6 cycles

76

  ROR $hhhh,X
absolute,X
3 bytes
7 cycles

7E

20 STXSTore X register – no flags affected
  STX $hh
zero page
2 bytes
3 cycles

86

TXATransfer X to A – affects flags N Z STX $hhhh
absolute
3 bytes
4 cycles

8E

  STX $hh,Y
zero page,Y
2 bytes
4 cycles

96

TXSTransfer X to Stack ptr – affects flags N Z  
TXA
implied
1 byte
2 cycles

8A

TXS
implied
1 byte
2 cycles

9A

21 LDXLoaD X register – affects flags N Z
LDX #$hh
immediate
2 bytes
3 cycles

A2

LDX $hh
zero page
2 bytes
3 cycles

A6

TAXTransfer A to X – affects flags N Z LDX $hhhh
absolute
3 bytes
4 cycles

AE

  LDX $hh,Y
zero page,Y
2 bytes
4 cycles

B6

TSXTransfer Stack ptr to X – affects flags N Z LDX $hhhh,X
absolute,Y
3 bytes
4-5 cyclesP

BE

TAX
implied
1 byte
2 cycles

AA

TSX
implied
1 byte
2 cycles

BA

22 DECSTore Y register – no flags affected
  DEC $hh
zero page
2 bytes
5 cycles

C6

DEXDEcrement X – affects flags N Z DEC $hhhh
absolute
3 bytes
6 cycles

CE

  DEC $hh,X
zero page,X
2 bytes
6 cycles

D6

  DEC $hhhh,X
absolute,X
3 bytes
7 cycles

DE

DEX
implied
1 byte
2 cycles

CA

23 INCSTore Y register – no flags affected
  INC $hh
zero page
2 bytes
5 cycles

E6

NOPNo OPeration – no flags affected INC $hhhh
absolute
3 bytes
6 cycles

EE

  INC $hh,X
zero page,X
2 bytes
6 cycles

F6

  INC $hhhh,X
absolute,X
3 bytes
7 cycles

FE

NOP
implied
1 byte
2 cycles

EA

24                
25                
26                
27                
28                
29                
30                
31                

What Can Opcode Timing Reveal About the 6502?

You might have noticed that most of the instructions require at least one cycle more than the number of bytes loaded for the opcode and any parameters. For example, a NOP or any register or status instruction requires 1 byte and 2 cycles. (A notable exception is JMP absolute.)

Where to Load the Next Byte?

The next byte fetched via the data bus could be stored in the single-byte register for instruction, X, Y, or stack pointer, or the low or high byte of the accumulator, the high byte of the accumulator, program counter, or an indirection register.