How long do you think it took to modify a 2,200-line C program that runs on Windows H to have it run on Linux? Just one hour. The main changes were switching some string routines such as strcpy_s to strncpy, altering paths for includes and changing the high-speed timing code. It might take between a week and a month or longer to do that in assembly. And moving that C code from, say, Ubuntu on x86 to Raspberry Pi on ARM would take almost no time at all. In assembler, it would take a complete rewrite; more months of work.
Having tried to put you off modern assembly, let’s try some old-fashioned assembler from 40 years ago. With roughly 60 instructions, the 6502 CPU is simpler than modern CPUs, which can have several hundred.
What is a 6502?
Pretend it’s 1983 and you have bought a brand new Commodore 64 and assembler cartridge that will ‘compile’ 6502 assembler into machine code. In this article, we are learning some 6502 assembly language, writing a short program in it and then running it on a web emulator.
The 6502 has just three registers: A (known as the accumulator), X and Y. Each register is 8-bit, so can hold a number between 0 and 255. It’s easier to deal with values and addresses in base 16 – hexadecimal – so a byte holds a value