6502
The 6502 CPU is an 8-bit processor designed in the mid 70s. It was used in various home computers and consoles at the time, amongst them the Apple II.
The core (or a variation of it) is still in use in some microcontrollers. Estimates are that more than 6 billion units have been built. With the cost having been lowered to just $25, it has been one of the most influential microprocessors ever designed, and it accelerated the trend of making computers affordable.
What is so great about the 6502?
The 6502 was the first affordable microprocessor. Developed in 1976, it was sold at a fraction of the price of the Intel 8080, which helped make "home" computers such as the Apple II both possible and affordable.
Despite its simple design, the 6502 had astonishing performance, and a 1MHz version had similar performance to a 4 MHz Z80. And all of that was achieved with just roughly 3200 transistors.
Programming
The 6502 is a real 8-bit machine, with very few registers.
Registers
- PC—16 bit Program counter
- S—8 bit stack pointer. Stack is always located in the first page, so from 0x100 to 0x1FF
- ACC—8 bit accumulator
- X—8 bit index register
- Y–8 bit index register
- Flags-8 bit Flag register
Sweet 16
Some programs used Sweet 16, a pseudo processor originally implemented by Steve Wozniak (https://en.wikipedia.org/wiki/Steve_Wozniak). Sweet 16 was a pseudo 16-bit processor, with 16 16-bit registers. It required 32 bytes in the zero page of the 6502 to hold the values of these registers, and it needed fewer instructions than the 6502 for most programs.
Typical programs written in Sweet 16 needed about half the size and 5 to 10 times less time to create as pure 6502 assembly code. The Sweet-16 executer was implemented in the ROM of the original Apple II. The 6502 assembler and Sweet 16 could be mixed easily: Sweet-16 code was inlined and preceded by a function call to the executer, which was located at a known address (0xF689 or in Apple speech $F689), and it could be easily started by a subroutine call.
Despite its simplicity, Sweet 16 achieved amazing code density, which is still hard to beat today. For more information on Sweet 16, see http://www.6502.org/source/interpreters/sweet16.htm
More information on the web
An excellent article is available at https://en.wikipedia.org/wiki/MOS_Technology_6502. For anyone interested in the hardware design of a CPU, the Javascript simulator might be interesting http://www.visual6502.org/JSSim/index.html.
Another site to look at is Monster 6502. Here there is a complete, functioning transistor-scale replica of the classic MOS 6502 microprocessor; see https://monster6502.com/. The principle designer was Chuck Peddle (https://en.wikipedia.org/wiki/Chuck_Peddle), and the story of the team behind the chip that launched a revolution is here: https://www.team6502.org.