6502 is a Good Starting Point for Beginning Assembly Programming
Why I believe 6502 instruction set is a good first assembly language
Deciding where to start is one of the hardest things about learning assembly programming. Unlike high-level languages, assembly is tightly connected to the hardware and deciding which CPU to use is an important first step.
Here, I will explain why I believe 6502 is a good platform to start learning assembly.
To be clear, I am not saying 6502 assembly itself is a particularly useful skill nowadays, nor that it is particularly pleasant for writing real-life applications. In fact, I do not believe you should spend too much time with 6502 unless you are interested in retro programming as such.
My arguments for starting with 6502 are in a nutshell:
6502 is simple; you can quickly learn assembly programming basic concepts with it;
6502 is real; there are plenty devices, emulators, books to help you learn.
Simplicity
To learn basic assembly programming concept, having a simple system is more important than having a powerful one.
6502 contains only 6 registers: one accumulator, two index registers, a status register, a stack register and a program counter which is the only 16-bit register on 6502. Modern x86-x64 CPUs have so many registers that counting them is almost a research project. Small number of registers is constraining for real-life applications but is helpful for understanding what a register is and how it works.
The original 6502 instruction set contains only 56 instructions. Again, counting x86-x64 instructions is a non-trivial task and even modern RISC instructions sets like ARM are far from being small and simple. Yet, with 6502 we can quickly learn about major instruction types, including loading/storing, logical and arithmetic, as well as branching. All of them are present in the modern CPUs in some form.
Reality
6502 was introduced in mid-1970 by MOS technology, as a cheap simplified version of Motorola’s 6800 CPU which was previously developed by the same team. The processor quickly became extremely popular and was used in some well-known microcomputers, like Apple II, Commodore VIC 20, Commodore 64 and BBC micro. It is easy to find emulators for all these machines, and even modern re-creations of some of them. Furthermore, successors of 6502 are still being produced at the time of this writing, and there are brand new machines that run it, like Neo6502 by Olimex.
There is a plenty of learning material available for free on the internet: books, videos, tutorials. Most of these resources can be found and accessed via 6502.org site.
With all that said, if you want to spend only half an hour learning 6502, the place to visit is Easy 6502 ebook by Nick Morgan. The web page contains not only text and images, but a 6502 assembler and simulator written in JavaScript, so you can actually write some simple 6502 assembly code on the spot!
Another fascinating resource I encourage you to check out is Visual6502.org. Not so much as a tool for learning assembly programming, but an illustration of the simplicity of 6502.
Alternatives
Of course, not everyone will agree that 6502 is a good choice for starting assembly programming. Some other opinions I have heard include:
Various imaginary CPUs created for teaching purposes; admittedly, some of them have very clean and “perfect” instruction set - in fact I was taught one in high school. However, even the most popular of them lack the wealth of resources for learning and the community of 6502
other “retro” CPUs like Z80, 6809 or 68000. They are all good choices, and in my opinion all three mentioned above are better for serious programming than 6502. But if we are talking about learning basic concepts, the simplicity of 6502 wins. As much as I like Z80 which powered my first computer, it has many more registers than 6502 (and even an “alternate” set of registers) and is not as easy to get started with.
modern RISC architectures such as ARM, MIPS or RISC-V. At some point, a serious assembly programmer should definitely learn some of them. However, they are not ideal to start with: the “S” in RISC stands for “simple”, but the simplicity is more about internal implementation of the chips than the instruction set. Modern microprocessors are almost exclusively programmed with high-level languages and the direct usage of assembly instruction is not high on the list of priorities for CPU designers nowadays. To illustrate this point, loading a 64-bit constant to a register on ARM64 can take 4 instructions with bit shifting. Loading a constant to a register with 6502 is trivial in comparison.
x86-x64. This is arguably the most popular instruction set on modern desktop and server computers, although ARM is catching up. In some respects, it is easier to code than with ARM, given the wealth of instructions that are not constrained by being 32-bit in size and can have variable number of operands; or at least that’s my impression after starting with Z80 which is compatible with x86 predecessor Intel 8080. However, it is still really complex for beginners and four decades of history does not make it any simpler.