UP | HOME

Everything Filip knows: 6502

Table of Contents

This is my first attempt at making a personal Wiki. See the contact page for my E-Mail in case you know any fixes, additional information, and if you know how to improve this page.

1. Overview

The 6502, formally "MOS Technology 6502" is an immensely popular, mid 70s (1975) microprocessor. Like most processors at the time, the 6502 was 8-bit, meaning the arithmetic logic unit of the processor can work with a 8-bit long data unit at one step (such as data unit is called a "data word" or "word" for short). It's also based on a CISC architecture (Complex Instruction Set Computer), thus some instructions for it consist out of smaller, less complex instructions. The 6502's byte-order is little Endian, storing the least significant byte in the smallest address. See Everything Filip knows: Endianness for more on that topic. Due to it's comparatively low price, it saw huge success in computers at the time, such as:

  • The Nintendo Entertainment System (NES) and the Family Computer (Famicom) respectively (Ricoh 2A03 derivative running at 1.79 clock speed)
  • Apple I (MOS 6502 running at 1MHz clock speed)
  • Apple II (MOS 6502 running at 1.023 MHz clock speed)
  • Commodore PET 2001 (MOS 6502 running at 1MHz clock speed)
  • VC 20 (MOS 6502 running at 1.108MHz (PAL) clock speed, or 1.02MHz (NTSC)
  • Atari 800 (MOS 6502B running at 1.79MHz (NTSC), or 1.77MHz (PAL)
  • BBC Micro (MOS 6502 running at 2MHz)

The 6502 has in total 56 instructions. It runs on a maximal clock speed of 1MHz to 3MHz.

2. Registers

The 6502 employs six different registers, each having a particular purpose, though the Accumulator, the Index X, and Index Y can be used as general purpose registers too. The Accumulator is used for calculations mostly and there are special instructions to operate on it. There is the X and Y registers used as indices. The Program Counter, that points to the next instruction in memory. The Stack Pointer points to the top of the stack, but unlike on amd64 systems, there is no stack base pointer. And lastly, the Status Register is a special register to display so-called flags, indicators of the result from the last action. Each bit in the Status Register is a flag, which can be either on or off. As the register-width is 8-bit, there are 8 different flags: Carry, Zero, Interrupt Disable, Decimal, Break, Unused, Overflow, and Negative.

3. Emulation

To run a program written for the 6502, you'll probably have to use an emulator. It's cheaper and will not have to deal with annoying idiosyncracies of the original machines, which is probably an advantage, if you're not into retro hardware.

Sim65 is part of the same suite of software as the cc65, the ca65, and the ld65 are, and does what it is supposed to do (simulate the 6502) sufficiently well. If you're interested in the NES's 6502, FCEUX works, probably as good as any other comparable emulator. It reads iNES ROM files (files ending in .nes, that established themselves as the de-facto standard for ROM files for NES emulation). Using those tools is very straightforward and well documented, so I'm going to omit a how-to guide.

4. How to program it

When programming the 6502, you are presented with essentially three choice, them being: 6502 Assembly, C with CC65, and some rather obscure options like using some Forth or Lisp dialect.

5. Further reading

Date: 2025-05-14