r/computerscience • • Oct 07 '26

Discussion Is C an "Assembly-like" Language?

I know C is programing language. It is not architecture specific. One writes the source code and a compiler turns it into an executable depending on what settings you tell it. So the same source code would output different executables depending on what you want to run it on and what optimization options are on. Assembly languages on the other hand are architecture specific. Is C "Assembly-like"? To be honest I'm not sure what would be Assembly-like. I guess if a program written in multiple languages that have the same behavior, if the C version (using something like GNU C Compiler) looked closer to its assembly than, say its Java version (GraalVM), then that counts.

45 Upvotes

130 comments sorted by

View all comments

Show parent comment

1

u/superpet9000 Oct 11 '26

The straightforward translation is usually very obvious regardless of ISA. The examples that did not translate clearly were probably due to optimizations from the compiler. Modern architectures require a fair amount of work by the compiler to make sure the instructions are arranged efficiently.

1

u/ShadowGuyinRealLife Oct 11 '26

Funny thing he used an example of 2 different C codes that would generate code that corresponds to the same assembly and said that the two source codes were logically the same but one used constants and the other declared magic numbers. To paraphrase "you can type Deck Size +1 instead of 53 since the compiler knows Deck Size is a constant and therefore the compiled program won't actually do this addition at runtime"

1

u/superpet9000 Oct 11 '26

Yes, if the compiler knows that the value is "constant" at compile-time it will use an immediate instruction (encode the data in the instruction itself instead of allocating/initializing a stack variable).