6502 Assembler
The assembly language of the MOS Technology 6502, the inexpensive 8-bit microprocessor launched in 1975 that powered the Apple II, Commodore 64, BBC Micro, Atari 2600 and Nintendo Entertainment System.
Created by MOS Technology design team led by Chuck Peddle (6502 chip designed by Bill Mensch)
6502 Assembler is the assembly language of the MOS Technology 6502, an 8-bit microprocessor launched in September 1975. When it came out, the 6502 was far cheaper than any competing processor. It sold for less than one-sixth the price of Motorola’s 6800 or Intel’s 8080. That low price put it inside the Apple II, the Commodore PET, VIC-20 and 64, the Atari 2600 and Atari 8-bit computers, the BBC Micro and the Nintendo Entertainment System. For roughly fifteen years, 6502 assembly was the language behind a large share of the world’s home computers and video games. It has 56 instructions, three registers and a heavy reliance on the first 256 bytes of memory. That small, regular instruction set made it one of the most widely learned assembly languages ever. It is still written today by retro game developers, demoscene coders and hobbyists building their own computers.
History & Origins
From Motorola to MOS Technology
The 6502 grew out of Motorola’s 6800 project. Chuck Peddle joined Motorola in 1973 to work on the 6800 family. He came to believe that a much cheaper processor could open markets the 6800 was priced out of. Peddle and several colleagues left for MOS Technology, a Pennsylvania chipmaker. There they designed two processors on one core. The 6501 fit the 6800’s socket, while the 6502 used a new pinout with an on-chip clock oscillator. Rod Orgill designed the 6501 and Bill Mensch the 6502.
The team cut costs by removing features. They dropped one of the 6800’s two accumulators, shrank the stack pointer from 16 bits to 8, and trimmed the 6800’s 72 instructions to 56. The result was not software-compatible with the 6800. It used a different instruction set, different registers and mostly different addressing modes, so it needed its own assembly language.
The WESCON Launch (1975)
MOS planned to sell its first production run directly to engineers at the Western Electronics Show and Convention (WESCON), which opened in San Francisco on 16 September 1975. Exhibitors were not allowed to sell on the show floor. MOS rented a suite at the St. Francis Hotel instead and sold chips there, stored in large jars. The 6502 cost $25, and a documentation package cost another $10. Buyers were encouraged to photocopy the documents. That was a cheap way to spread the programming model, and with it the language, among engineers.
The early documentation listed only 55 instructions. The rotate-right instruction ROR was missing because the first chips did not support it. Customers asked for it, and the second edition of the MCS6500 Microcomputer Family Programming Manual (document 6500-50A, January 1976) promised ROR in 6502 chips from 1976. On the earliest chips, that opcode does something else rather than a broken rotate. This gave rise to a lasting myth that the first 6502s had a “ROR bug.”
On 3 November 1975 Motorola sought an injunction against MOS and sued it for patent infringement and misappropriation of trade secrets. Running short of money, MOS settled in March 1976: it withdrew the 6501, paid Motorola $200,000 and cross-licensed patents. By November 1976 Commodore had bought the company. Commodore kept selling the chip, and Rockwell and Synertek became second sources.
Getting Programmers to the Chip
MOS knew engineers needed hardware to learn on. It produced the MDT650 development system and, in 1976, the KIM-1 single-board computer. The KIM-1 reportedly sold for $245 and was aimed at engineers, but it caught on with hobbyists. Rockwell followed in 1978 with the AIM-65, whose monitor ROM included an assembler and disassembler.
Then the home computers arrived. The Apple I used the 6502 in 1976. The Apple II went on sale on 10 June 1977, and its Integer BASIC ROMs included a machine-code monitor, a “mini-assembler” and a disassembler. Steve Wozniak had hand-assembled the monitor as the machine’s first program. With the Commodore PET and the Atari VCS also shipping in 1977, 6502 assembly quickly became the main low-level language of personal computing.
Design Philosophy
6502 assembly reflects the chip’s goal of doing as much as possible with as few transistors as possible:
- Very few registers. The programmer gets an 8-bit accumulator (
A), two 8-bit index registers (XandY), an 8-bit stack pointer, a status register and a 16-bit program counter. Nothing else. - Memory as registers. Instructions that use the zero page (addresses
$0000–$00FF) need only a one-byte address, so they are shorter and faster. 6502 programmers treat the zero page much as programmers on other CPUs treat extra registers. - A small, regular instruction set. There are 56 mnemonics spread over 151 valid opcodes. Every mnemonic is three letters, and the register is part of the name (
INX,TAY,PHA) rather than an operand. - A fixed stack. The hardware stack always sits in page one (
$0100–$01FF) and is 256 bytes deep, so deep recursion is impractical.
Key Features
Registers and Flags
| Register | Size | Role |
|---|---|---|
| A | 8-bit | Accumulator; all arithmetic and logic results land here |
| X | 8-bit | Index register; used for indexed and (zp,X) indirect addressing |
| Y | 8-bit | Index register; used for indexed and (zp),Y indirect addressing |
| S | 8-bit | Stack pointer, offset into page $01 |
| P | 8-bit | Status flags: N (negative), V (overflow), B (break), D (decimal), I (interrupt disable), Z (zero), C (carry) |
| PC | 16-bit | Program counter |
Addressing Modes
The same mnemonic assembles to different opcodes depending on how its operand is written. The notation below follows the MOS convention used by most assemblers:
| Mode | Example | Bytes | Meaning |
|---|---|---|---|
| Implied | INX | 1 | Operand is built into the instruction |
| Accumulator | ASL A | 1 | Operate on the accumulator |
| Immediate | LDA #$10 | 2 | Load the constant $10 |
| Zero page | LDA $80 | 2 | Load from address $0080 |
| Zero page indexed | LDA $80,X | 2 | Load from $0080 + X |
| Absolute | LDA $C000 | 3 | Load from a full 16-bit address |
| Absolute indexed | LDA $2000,Y | 3 | Load from $2000 + Y |
| Indexed indirect | LDA ($40,X) | 2 | Pointer found at zero page $40 + X |
| Indirect indexed | LDA ($40),Y | 2 | Pointer found at $40/$41, then add Y |
| Relative | BNE LOOP | 2 | Signed 8-bit branch offset |
| Indirect | JMP ($FFFC) | 3 | Jump through a 16-bit vector |
The (zp),Y mode is the workhorse for handling strings and arrays. You store a 16-bit pointer in the zero page and step through the data with Y.
Syntax Conventions
In the MOS style that most 6502 assemblers follow, $ marks hexadecimal, % marks binary and # marks an immediate value. Labels start in the first column and comments begin with a semicolon. Multi-byte values are stored little-endian. The example below copies a zero-terminated string and converts upper-case ASCII letters to lower case along the way:
| |
Because the CPU has no 16-bit arithmetic, wider numbers are handled one byte at a time, with the carry flag linking the bytes:
| |
Decimal Mode
The 6502 can do addition and subtraction directly in binary-coded decimal. After SED, adding $01 to $99 gives $00 with the carry set, instead of $9A. Ricoh’s NES variant left this feature out. The N, V and Z flags are undefined in decimal mode on NMOS chips. The processor also does not clear decimal mode when an interrupt arrives, so interrupt handlers that do arithmetic must set or clear the D flag themselves. The Commodore 64’s KERNAL reportedly did not handle this, so programs doing BCD arithmetic had to disable or re-vector interrupts. The CMOS derivatives clear the D flag automatically on reset and interrupts.
Quirks Every 6502 Programmer Learns
- The
JMP ($xxFF)page-wrap. If an indirect jump vector sits at the last byte of a page, the NMOS 6502 reads the high byte of the target from the start of the same page, not the next page. The 65C02 fixed this. - Undocumented opcodes. Only 151 of the 256 possible opcodes are defined. The remaining 105 do various unintended things on NMOS chips, from combining two instructions to locking up the processor. The behavior varies by manufacturer, but some programmers still used these “illegal” opcodes to save bytes.
JSRpushes the return address minus one. The address on the stack points at the last byte of theJSRinstruction, andRTSadds one when it pulls it back. Code that reads inline parameters after aJSRhas to account for this.- Page-crossing penalties. An indexed read whose address crosses a page boundary takes an extra clock cycle. That matters in timing-critical code such as Atari 2600 display kernels.
Assemblers and Tools
6502 code has been assembled on everything from the target machine itself to modern cross-development workstations:
Built-in assemblers. The Apple II mini-assembler lived in ROM. BBC BASIC on the BBC Micro accepted 6502 assembly inline between square brackets inside a BASIC program:
1 2 3 4 5 6 710 P%=&2000 20 [OPT 2 30 LDA #65 \ ASCII "A" 40 JSR &FFEE \ OSWRCH: print character 50 RTS 60 ] 70 CALL &2000When Acorn moved to ARM, later versions of BBC BASIC replaced the inline 6502 assembler with an ARM one.
Native assemblers for the Apple II, Commodore and Atari machines, sold commercially and as type-in listings through the late 1970s and 1980s.
Modern cross-assemblers. One of the most widely used is ca65, part of the cc65 suite. Ullrich von Bassewitz first announced the suite in November 1998, building on a C compiler that John R. Dunning had adapted for the Atari 8-bit machines in 1989. It supports the 6502, 65C02 and 65C816 and can be used without the C compiler. The cc65 project’s last tagged release was V2.19 in November 2020, but its GitHub repository was still receiving commits in August 2026.
Evolution
The 65C02
Bill Mensch left MOS in 1977 and founded the Western Design Center (WDC) in 1978. WDC began developing a CMOS version of the 6502 in 1981, with samples appearing around early 1983. The 65C02 fixed the indirect-jump page wrap and the undefined decimal-mode flags. It also added instructions that 6502 programmers had long worked around: BRA (branch always), STZ (store zero), PHX/PHY/PLX/PLY, TSB/TRB, and INC A/DEC A. Several previously undefined opcodes became real instructions, so NMOS programs that relied on undocumented opcodes may fail on a 65C02.
In a June 1983 Softalk article, Robert Wagner estimated that rewriting an average 6502 assembly program with the new instructions could make it about 10–15 percent smaller. He expected a similar speed gain, mainly because fewer instructions mean fewer memory accesses. That was his estimate, not a measured benchmark. Power use also fell sharply. According to Taylor and Watford (Personal Computer World, July 1984), at a 1 MHz clock the 65C02 draws about 20 mW, against about 450 mW for the NMOS original at the same speed.
The 65C816
Apple wanted a 6502-compatible processor that could address more memory, so WDC began the 16-bit 65C816 in 1982. The design was finished in March 1984 and fully released in 1985. The chip starts in an emulation mode that runs most 6502 and 65C02 code with the same cycle timings, though NMOS undocumented opcodes do not work. After CLC followed by XCE, it switches to native mode, with 16-bit A, X, Y and stack pointer, 24-bit addressing through bank registers, and a relocatable “direct page” replacing the fixed zero page. 65C816 assembly is a superset of documented 6502 assembly. The chip powered the Apple IIGS and, in modified form, the Super Nintendo.
Current Relevance
The original NMOS 6502 and the machines built around it belong to history, so this encyclopedia lists 6502 Assembler as Historical. The language itself is far from extinct, though:
- WDC still sells the W65C02S in DIP, PLCC and QFP packages and offers it as a Verilog RTL core for FPGA development. Over the decades the 65C02 has been widely used in embedded systems. Citing WDC, Wikipedia puts its estimated production in the hundreds of millions.
- Retro and homebrew game development for the NES, Atari 2600, Commodore 64, Apple II and BBC Micro remains active, with ca65 and similar cross-assemblers as the usual tools.
- Software archaeology has turned landmark 6502 programs into readable texts. Mechner’s Prince of Persia source is on GitHub, and Mark Moxon’s bbcelite.com presents fully annotated versions of Ian Bell’s original Elite sources.
- Teaching. The 6502’s small instruction set and visible register model still make it a popular first assembly language for understanding how CPUs work.
Why It Matters
6502 assembly was the language of the first home computer boom. The chip’s price made machines like the Apple II, Commodore 64 and BBC Micro affordable. Because those machines had little memory and slow BASIC interpreters, anything ambitious, whether games, operating systems, word processors or demos, had to be written in assembly. A generation of programmers learned how computers really work by poking at the zero page, counting clock cycles and fitting programs into a few kilobytes.
Many landmark programs were written in it. Elite squeezed a 3D space game into a BBC Micro, and Prince of Persia brought fluid rotoscoped animation to the Apple II. Atari 2600 and NES games defined the early console industry within tight hardware limits. The language even reached popular culture: in The Terminator (1984), the killer cyborg’s vision display scrolls 6502 assembly listings.
Its descendants, the 65C02 and 65C816, carried the same programming model into the Apple IIGS, the Super Nintendo and decades of embedded devices. Half a century after WESCON, a program written for the 1975 instruction set can still be assembled with maintained tools and run on 65C02 chips that are still being manufactured.
Timeline
Notable Uses & Legacy
Elite (BBC Micro)
David Braben and Ian Bell wrote the 1984 space-trading game in 6502 assembly, squeezing a wireframe 3D engine into the BBC Micro's memory. Their original sources are now annotated line by line at bbcelite.com.
Prince of Persia (Apple II)
Jordan Mechner wrote the game in 6502 assembly between 1985 and 1989. The source, recovered from old floppy disks, was released on GitHub in 2012.
Atari 2600 Games
Atari VCS cartridges were written in assembly for the 6507, a cut-down 6502 that can address only 8 KB. Programmers had to generate the TV picture line by line in software, a practice documented in the MIT Press book Racing the Beam.
Nintendo Entertainment System
NES and Famicom games target Ricoh's 2A03/2A07, a second-source 6502 that lacks binary-coded decimal mode but adds on-die sound generation and joypad and sprite-transfer hardware, all programmed in 6502 assembly.
Home Computer Firmware
System ROMs such as the Apple II Monitor and the Commodore 64 KERNAL (running on the 6502-derived 6510) were 6502 assembly programs. The Apple II Reference Manual of January 1978 printed the complete Monitor ROM source listing.
The Terminator (1984)
The T-800's heads-up display in James Cameron's film scrolls 6502 assembly listings. Retrocomputing researchers have traced the code to Apple II programs published in Nibble magazine.