Hacker News new | ask | show | jobs
by ctw 3168 days ago
Very cool. Something I really love about assembly programming is that there's no black magic between me and the hardware. I can know exactly what every bit of every instruction means by looking at the instruction set documentation, and I can look at the computer architecture documentation to know exactly how to access each device.

Also, the "API"'s you have to learn are incredibly simple compared to learning API's for every framework and protocol in high-level programming. If devices are memory-mapped, than all I'll ever need to know is load and store. I just need to look at the registers that are available for each I/O device, what their addresses are, and what the bits represent in them. From there I access them all the same way: load and store. Couldn't possibly get any easier than just moving things around between registers and memory.

Compare that to high level development like web development, where you need an understanding of HTTP on top of one of infinite different web backends, written in different languages, all using different libraries with different naming conventions and different programming paradigms, plus knowledge of HTML, CSS, possibly another smorgasbord of frameworks, plus knowledge of decent security practices, databases, operations, and the list goes on.

It's obviously apples to oranges though, and I can produce a lot more real-world value doing web development than I can doing assembly programming, at least just as one person. My point is that I really like the simplicity and straightforwardness of writing assembly, at least in the few very short times I've done it. Maybe large assembly projects have all the same challenges as high-level development or worse.

2 comments

I love low-level, assembly-level programming. The big problem is, we're largely past the era of it.

All but the most simplest embedded systems are complex enough to require some pre-developed library or abstraction layer to stand between a single tinkerer and the hardware. Otherwise it would take you an eternity just to stand up a "Hello World!" The cost of a Linux-capable SoC is low enough that you can buy one for $5 in the form of the Pi Zero. If a system complex enough to run Linux only costs $5 to sell, and probably even less to make, what incentive is there anymore to produce hardware that's simple enough to work with directly at the assembly layer?

The last holdouts are extremely power-efficient embedded systems. And even then you can do those with C.

I'm an old fart who can remember the "good ol' days" just as well, and I still program the SNES as a hobby. But really, that's all it'll ever be anymore; a hobby for legacy systems. There's no reason anymore to even skip C, when architectures have been so fine-tuned for code written with C.

You would be surprised how much it is used still in embedded dev. Picking an embedded board that can, with low level coding, just run your target software is generally far cheaper and power friendly than something more powerful. On millions of devices being produced every cent counts and on wearable devices every hour battery life counts.

For instance, in our case and the case I know best, we could use a full 32 bit ARM arch in our hardware but we do not; we retarget a very simple microcontroller with a few kilobytes of memory for this because it is far cheaper and far less power hungry. Result is that we have to use asm or C with quite a high % of asm. We decided to use only asm because it makes the audits easier too. Because of this work I got to meet many manufacturers and these components are in a lot of appliances and are often coded in asm.

I don't fully agree that we're "past" it.

It's definitely out of fashion, but when something complicated breaks, where is the "adult" you call to figure it out? :)

I do 100% agree that commercial systems / enterprise / game dev is past the low level era, but the knowledge of the area is anything but obsolete for the reason I mentioned before.

I like learning about these legacy systems precisely because we are past them. They are no longer being extended. What I learn about e.g. 6502 today will be 100% applicable 10 years from now. I don't have that confidence with modern systems.
That is what I like about it too. The systems I have in my mancave and program for fun on, are from the early 80s. They are known inside and out (literally), they all still work and in 10 years they will be exactly the same.
my intent in working on this project was (for my personal education) to start engaging with computers involving the fewest layers of abstraction possible, and the gameboy seemed like a fun way to do that.

my hope was to try to stand these up on systems that i actually use on a day-to-day basis, so it's kinda disheartening that that may be overly ambitious, but i'll write about it if i have any success :)

There absolutely is still black magic between you and the hardware and thinking otherwise can lead to trouble. Yes you can read the architecture documentation but when you get into the realm of how the branch prediction tables work, register allocation schemes, operation reordering etc, what the hardware does will be "special" while (usually) not violating what the architecture specifies. Don't even get me started with load/store semantics for multithreaded architectures (although this is standardizing more with the more recent ARM)
Sure, but the Game Boy’s pseudo‐Z80 has no branch prediction, register allocation, or instruction reordering. The assembly is almost one‐to‐one to the machine code, and the CPU basically does everything in the straightforward way you’d expect.
Even on the Gameboy things aren't quite as simple and self evident as all that, for example from another thread on this post: when the Game Boy's screen is rendering (i.e. almost all the time), the CPU doesn't have access to VRAM. [...] writes are ignored, and reads return garbage.

So one of those platonic store instructions might actually be a no-op; you can't tell by looking at it in isolation.

I was replying directly to a response which generalizes the subject of the original post.
I was hoping someone would say something along these lines. My only experience with assembly has been on very simple educational platforms: nios ii on an Altera DE0 FPGA and a MIPS subset on a custom architecture made in class. I've seen photos of the huge x86 reference manual and can see how "real-life" systems would be way more complex than the simple world of assembly I've tried myself.