r/programming • • May 01 '18

C Is Not a Low-level Language - ACM Queue

https://queue.acm.org/detail.cfm?id=3212479
152 Upvotes

303 comments sorted by

View all comments

Show parent comments

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.

24

u/[deleted] May 01 '18

Assembly is still a high level language. The only real language is writing the op codes by hand with toggle switches. /s

13

u/monocasa May 01 '18

There was a program to do that job, an “optimizing assembler”, but Mel refused to use it.

“You never know where it's going to put things”, he explained, “so you'd have to use separate constants”.

http://www.catb.org/jargon/html/story-of-mel.html

→ More replies (1)

17

u/Chippiewall May 01 '18

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.

5

u/ThirdEncounter May 01 '18

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.

7

u/Garestinian May 01 '18

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?

3

u/MINIMAN10001 May 01 '18

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.

1

u/pdp10 May 01 '18

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.

4

u/FenrirW0lf May 01 '18

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

1

u/[deleted] May 02 '18

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.

6

u/MINIMAN10001 May 01 '18

If we want to get this stupidly nitpicky x86 assembly isn't low level because x86 is a virtual machine

3

u/[deleted] May 02 '18

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.

3

u/MINIMAN10001 May 02 '18

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.

11

u/Vhin May 01 '18

This makes the term "low level languages" useless. We already have a perfectly satisfactory term to refer to assembly languages. Namely, assembly languages.

4

u/[deleted] May 01 '18

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.

2

u/I_am_the_inchworm May 01 '18

Those books are outdated.

Even assembly can be argued not to be low level anymore.

2

u/[deleted] May 02 '18

Even assembly can be argued not to be low level anymore.

Any language that assembles opcode on a one to one basis is low level, regardless of what any trendy book says.

3

u/I_am_the_inchworm May 02 '18

It doesn't do that anymore due to abstractions at the hardware level. That's the point.

1

u/ThirdEncounter May 01 '18

What's considered low level, then, if not assembly? Micro-code?

→ More replies (1)

2

u/TinynDP May 01 '18

only assembly is.

If there is only one possible "low level language" then the term is meaningless.

2

u/ThirdEncounter May 01 '18

That's just incorrect. "If there can only be one Pope, then the term in meaningless."

→ More replies (2)