Ask Hackaday: Learn Assembly First, Last, Or Never?

Ask Hackaday: Learn Assembly First, Last, Or Never?

Source Node: 2170599

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.

Of course, that was a long time ago. It is more likely, these days, if you are over 40, you might have learned BASIC first. Go younger, and you start skewing towards Java, Javascript, or even C. It got me thinking, though: should people learn assembly, and if so, when?

<img data-attachment-id="603872" data-permalink="https://hackaday.com/2023/07/14/ask-hackaday-learn-assembly-first-last-or-never/pexels-jeremy-waterhouse-3665444/" data-orig-file="https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg" data-orig-size="6000,4000" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="pexels-jeremy-waterhouse-3665444" data-image-description="

PD from Pexels

” data-image-caption=”

Assembly language is a text representation of the machine code your CPU executes

” data-medium-file=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?w=400″ data-large-file=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?w=800″ decoding=”async” loading=”lazy” class=”size-thumbnail wp-image-603872″ src=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never.jpg” alt width=”250″ height=”167″ srcset=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg 6000w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?resize=250,167 250w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?resize=400,267 400w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?resize=800,533 800w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?resize=1536,1024 1536w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-2.jpg?resize=2048,1365 2048w” sizes=”(max-width: 250px) 100vw, 250px”>

Assembly language is a text representation of the machine code your CPU executes

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

If you are satisfied writing code to validate zipcodes in Javascript, you probably don’t need to learn assembly. But if you want to really be a top programmer, you are going to have to confront it sooner or later. Learning it early has some benefits. If you understand what’s really going on at the CPU level, a pointer in C doesn’t seem like a tough concept. Being able to look at the output from a compiler and understand what it means is often illuminating when you are trying to learn something new.

However…

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.

<img data-attachment-id="603878" data-permalink="https://hackaday.com/2023/07/14/ask-hackaday-learn-assembly-first-last-or-never/a88/" data-orig-file="https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg" data-orig-size="2037,1040" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="a88" data-image-description="

PD by Al Williams

” data-image-caption=”

Even if you can’t afford an Altair, you can get a replica. Or just stick with software emulation

” data-medium-file=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg?w=400″ data-large-file=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg?w=800″ decoding=”async” loading=”lazy” class=”size-thumbnail wp-image-603878″ src=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-1.jpg” alt width=”250″ height=”128″ srcset=”https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg 2037w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg?resize=250,128 250w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg?resize=400,204 400w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg?resize=800,408 800w, https://platoaistream.net/wp-content/uploads/2023/07/ask-hackaday-learn-assembly-first-last-or-never-7.jpg?resize=1536,784 1536w” sizes=”(max-width: 250px) 100vw, 250px”>

Even if you can’t afford an Altair, you can get a replica. Or just stick with software emulation

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.)

Time Stamp:

More from Hack A Day