For any system architecture in history, the only low level language has been, and is, assembly language. Assembly language is merely the one-to-one direct association to machine language for any CPU. If you want to call C a "mixed" level language, fine. That is merely semantics. But C is not a low level language - only assembly is.
Ehh.. these days even assembly wouldn't constitute a low level language. The machine code that's generated still doesn't run precisely as described. Modern CPUs perform so many optimisations at runtime in terms of instruction re-ordering, register remapping, skipping no-op instructions that even assembly doesn't fit as an accurate description of what the hardware will do.
The thing is, as a programmer you have no control over how those CPU tasks are done - except, of course, if there is a bug that leads to Spectre and others. So, what does it matter if assembler does not account for such tasks?
That's like saying that you're not a true expert car driver because you can't access the steering hydraulic pump with your bare hands to control it.
But I think that's precisely the point of the article - modern "fast" processors are so complex that even plain old assembly isn't low level in the truest sense. So a question is - could we do with simpler (dumber) processors, and assembly that is closer to how processors work today (multithreading, vectorisation, cache), but is not supportive of C?
Well the reason why we've reached this point is because it irritatingly went down the rabbit hole of saying "Well X isn't low level because Y"
Truth is the answer is no, C as a language is close enough to the code ran on the hardware and does not try to abstract away a large amount it does qualify as low level.
In theory, you can load microcode into most types of hardware to control lower-level behavior, and even make your own instructions. In practice, the hardware vendors don't allow end-users or even OEMs to do that any more.
Which is ultimately the point of the article tbh. Things have been written in C for decades, so processors expose an interface similar to the kind that C compilers have historically targeted despite operating completely differently under the hood these days.
Maybe that point would have been better made if the author had titled it as "Assembly Is Not a Low-Level Language".
these days even assembly wouldn't constitute a low level language.
Actually, yes, it is. The Assembler doesn't actually run the code. It just puts the bytes together in the correct order - hence the name "assembler". What the CPU chip does with the code has nothing to do with the assembler. Look, there has to be a low level language. You can't go from nothing right to high level in one shot. It doesn't work that way. That low level is assembler.
If we want to get this stupidly nitpicky x86 assembly isn't low level because x86 is a virtual machine
The Intel 80x86 CPU's are not virtual machines. They do have a 8086 virtual mode, but that is not a virtual machine. Assembly language is still low level since direct opcodes are being assembled.
The article isn't about virtual mode. It's about the fact that the opcodes you give the processor no longer execute the instructions that they used to execute because it is now a virtual machine.
CMP and JMPcc and now executed on the CPU as a single instruction on the processor.
xor eax, eax doesn't clear eax just marks it as unused freeing it up to the pool of 168 registers.
mov eax, ebx doesn't move eax to ebx it renames ebx register to eax
I'll quote this one
But because the processor is massively out-of-order, I can continue executing instructions in the future that don't depend upon this memory read. This includes other memory reads. Inside the CPU, the results always appear as if the processor executed everything in-order, but outside the CPU, things happen in strange order.
This means any attempt to get smooth, predictable execution out of the processor is very difficult. That means "side-channel" attacks on x86 leaking software crypto secrets may always be with us.
The upshot is this: Intel's x86 is a high-level language. Coding everything up according to Agner Fog's instruction timings still won't produce the predictable, constant-time code you are looking for.
This makes the term "low level languages" useless. We already have a perfectly satisfactory term to refer to assembly languages. Namely, assembly languages.
This makes the term "low level languages" useless. We already have a perfectly satisfactory term to refer to assembly languages. Namely, assembly languages.
I didn't make the names up. I am just reporting what I have read in countless references and books over the decades.
15
u/[deleted] May 01 '18
For any system architecture in history, the only low level language has been, and is, assembly language. Assembly language is merely the one-to-one direct association to machine language for any CPU. If you want to call C a "mixed" level language, fine. That is merely semantics. But C is not a low level language - only assembly is.