Hacker News new | ask | show | jobs
by throwawaymaths 1162 days ago
This is silly. Assembly is an abstraction too. Do you think the CPU actually runs the code you give it? Of course not. There's microcode, register aliasing, speculative execution, etc.

Even assembly itself has symbols and labels, which are themselves abstractions.

3 comments

Did you really not understand the point the GP was trying to make or is this an attempt to be clever?

Of course assembly is an abstraction, but it is the lowest level programming language that ordinary mortals can still write code in, which was the point the GP was making.

Exactly nobody writes applications in microcode. Register aliasing and speculative execution have under normal circumstances no effect other than some performance which if the CPU just did as it was told by the assembly code (or actually, the machine code, the binary representation of the possibly optimized assembly) would still work exactly as advertised. You can also switch those off if they're features of the assembler, and if the CPU does them then you're going to have to live with it.

If you really wanted to make the point that Assembly is an abstraction then macros would have probably been a better thing to mention.

If you’re trying to understand the behaviour of the computer then all of the layers of abstraction matter, right down to the logic gates. Spectre and Meltdown proved that software developers can’t just “trust the CPU to do the right thing.”

Besides the issue of security, performance is also a thing. If you’re trying to squeeze every last cycle out of your program then you need to understand CPU cache hierarchies at the very least. That’s at a level far below assembly language, digging down into the physical layout of the machine.

I'm well aware of all of those levels. But they are not germane to the discussion about programming in general. They are important if you are doing some really specialist work (low latency, extreme performance, operating system design). But that wasn't the context at all.
Child, assemler mnemonic representations of opcodes are not hiding anything.

You could make the same, useless, argument about the raw binary. If you looked at an executable you are still actually only looking at a transcoded representation in ascii in an editor. The cpu doesn't actually know what 0A is, those are glyphs for numbers and letters in a human language.

Assembler mnemonics are not materially different, and even macros don't change this because the macros are macros, built out of other visible assembler not hidden magic.

You are not conducting useful argument or communication with this silliness.

> assemler mnemonic representations of opcodes are not hiding anything

They do hide things. There are often multiple ways to encode a line of assembly into machine code. For example on x86, JMP can take an 8-, 16-, or 32-bit displacement, and the assembler will usually select the shortest encodable variant. Some instructions have a shorter variant for certain registers, like ADD $1, %eax. You add useless REX prefixes.

The difference is that a CPU does way less magic under the hood than an optimizing compiler for a high level language, and there's no such thing as UB in assembly (outside some exotic cases like 'illegal' instructions on the 6502 which behave unpredictably)
Meltdown/Spectre pulled back the curtain and revealed just how much magic is going on with modern CPUs.
But it only really manifests as timing.
This.

The cpu magic doesn't do things you didn't ask for, or can't figure out how to ask for through a bunch of indirection.

All the cpu magic means is that you don't know how it did exactly what you expected. It still produced exactly and only the expected output from the given input.

High level language magic means it does things you didn't expect, and that you can have a hard time figuring out how to get it to do something you want if that doesn't happen to be one of the things the language designers predicted and decided for you that you should ever need to do.

Assembly is about as much abstraction as rot13 is encryption.