A few days ago, I ran into an online post where someone pointed out the book “Learn to Program with Assembly” and asked if anyone had ever learned assembly language as a first programming language. I had to smile because, if you are a certain age, your first language may well have been assembly, even if it was assembly for machines that never existed.
I’m no stranger to assembly languages, but I’m not sure I know a modern and defensible answer to this question. You can find plenty of tutorials, of course (including some from me). There are plenty of cases where a few lines of embedded assembly can make a big difference in a program. Debugging a bad compiler can also require assembly chops. So it seems that at least some people still need to learn assembly. That leaves the question of when to learn it and, as a corollary, who needs to learn it.
My traditional answer would be that everyone should learn it as soon as possible. But that could be because that’s how I did it years ago. I’m not convinced that’s the right answer for everyone today. However, I’ll make my case.
The Case for Early
The only problem is that modern assembly language is difficult. CPU instruction sets are strange, and there are issues with CPUs that do out-of-order execution. Then there is relocatable code and other details that are easy to trip on and not very useful to know much about.
So there are two ways to go. First, pick an older CPU. Something like the Z80, the 1802, or the 6502 isn’t that hard to learn, and there are a ton of resources available. Don’t have any hardware like that? Who cares? Use an emulator. You can probably even find some that run in the browser and have excellent debugging capabilities not available in the real hardware. I’ve programmed on dozens of CPUs, and they are all pretty similar. Given the oddness of the 1802, I might not recommend it even though I love it myself. It is, on the other hand, very simple to learn. The PDP-8 or PDP-11 are other good candidates, although some of how minicomputers do things are rarely seen today.
Or, pick a machine that doesn’t exist. Most of these were made for learning, so that’s a plus, and many of them also have modern emulators. If you were to pick one, I’d suggest Mix. The books from Knuth are classic and use Mix. They influenced everyone, so you’ll see echoes of Knuth’s ideas in every computer system you ever touch. (That isn’t a quantum computer, at least.)
Just don’t go too far back. Programming the EDSAC, TUTAC, or the 4004 is probably not representative of modern computing at all. Honestly, none of these CPUs are. But they can help set the stage for tackling more advanced processors if needed. Like the old adage: You have to crawl before you walk, and walk before you run.
The Case for Late
You could easily argue the other side, too. Maybe assembly language makes more sense once you understand why you need pointers to make linked lists and why conditional jumping is a thing. If you’ve been programming for a while, some ideas like hex numbers and addresses might already be familiar.
Probably the wrong time to learn it, though, is when you have an intractable bug, and you suspect the compiler is optimizing your code incorrectly. Or at the midnight hour before a deadline when you need to shave that extra little bit from your code.
What Do You Think?
This is, after all, “Ask Hackaday,” so tell us what you think in the comments. Make your case for why no one needs to learn assembly. Or tell us your opinion about the best processor to learn. Learn in the browser? We don’t suggest WebAssembly, but maybe you disagree. What are the best online resources and books? What’s your favorite story about that time that knowing assembly saved the day?
(Digital rain effect from [Rezmason]’s generator.)