Adventures in Assembly #1 [How It Usually Begins]

Author profile picture

@austinAustin Pocus

Do not attempt to adjust your set. We are controlling transmission.

I have this weird habit. When I find something that piques my interest, I can dive into a rabbit hole, not coming up for air for days. Naturally, this led me to a fairly deep dive over the past few nights on x86, 6502, and Z80 assembly language, as one does. Little did I know how much detail there is -- like a fractal, the more you zoom in, the more detail you find.

It all started with x86.
I vaguely recall how all of this started. One minute I was thinking about custom programming languages and virtual machines and LLVM and that sort of thing, and all of a sudden, there I was in assembly land.
Before I knew it, I was knee-deep in Intel documentation on the x86 series, then x86-64 / x64 assembly.
But, I wanted to simplify.
Of course, rather than doing what any sane human would do, closing the page and walking away to do something useful, I dug in and thought, “80s era processors were way simpler, let’s explore those!”
Simpler, I thought. 😂 How naive, how utterly ignorant I was.
Of course, the main difference between processors of that era and modern processors is that 80s processors were designed for humans to use. x86, x64, these are built for machines to write and use. 80s machines, had no such luxury.
Often, if you wanted any speed whatsoever, you had to touch bare metal, which means assembly language. C was sort of a newer thing at the time, too.
You didn’t have the privilege of “write once, run anywhere” like you did in the 90s, with Java. You had nowhere near the ubiquitous platform of the web. No, you were writing for one machine. Your machine.
And it was your machine. You control the memory. You can set any pixel on the screen to any color supported by your system. You control the vertical, you control the horizontal. Do not adjust your set.
Or do! It’s yours.
Why the obsession with these old processors though? What are they good for? Well, the biggest draw for me is that the NES was controlled by a 6502 variant, the Game Boy controlled by a sort of hybrid between the Z80 and 8080. These chips could be used to make games. In fact, some of them were made with that use case as a high priority.
I started by exploring “Easy 6502” by Skilldrick again, one of my favorite webpages of all time. Seriously, there’s a legible, playable, assembly language snake game at the end! I familiarized myself once again with concepts that are completely foreign to most web programmers: things like registers, status flags, “two’s complement” representation of negative numbers, how to use the carry bit for fun and profit, and much, much more.
As I dug into the instruction set, addressing modes (ways to access memory, basically), ways to branch...it became clear that this wasn’t going to be the nice little evening distraction I thought it would be.
Yet I continued.
Beyond the 6502 snake game, I thought, “the Z80 was used in the Game Boy [note: I was wrong], I’ll explore that chip!” This led to even more of a rabbit hole...I started reading a book on the Z80 and quickly started asking myself things like, what is memory, anyway?
I stopped short of going beyond the lowest level language and into the microcircuitry employed in actual computers. Even I’m not that crazy. But I did continue reading about assembly langauges. I’ll continue to do so tonight.
And next week, dear reader, I hope to introduce you to even more of the weird, the esoteric, and hopefully, some of the downright practical (like how page tables work!). Until then, I return to the world of Javascript, blissfully unaware of registers, memory, or anything even remotely resembling hex literals...

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!