I'm in a Computer Organization class, and we're programming stuff in assembly. However, since this is a class, I'm not getting a broader sense of anything, or any real-world use. We're using Altera's Nios II Assembly language. The professor hasn't told us anything about which assembly languages are used in current production, and what the semantics are, or how C code compiles to ALL of the assembly languages.
Following that brief intro, am I correct in assuming that there are several assembly languages that C code compiles to? If so, what does it do to reach all of those assembly languages - parse it into a generic assembly language and then translate it from there? Or is there a separate process for each different assembly language?
There is no requirement to compile C to any specific assemblies or any assembly at all, those are left to the implementor of a compiler, and not part of the language specification. Typically, every CPU manufacturer will develop a C compiler to target their specific architecture.
There are more generic compilers like GCC and Clang though, which can target many different instruction sets.
To use Clang as an example, it is based on the Low Level Virtual Machine, which is an abstract machine with an "intermediate representation" language, LLVM IR. A back-end is written for each architecture that LLVM can target for converting LLVM IR to the instruction set, and then any compiler which compiles to LLVM IR can then target the CPUs supported by LLVM.
The compiler will decide which back-end to target at runtime based on the arguments you pass to it. The compiler typically has a default back-end which is set when building the compiler itself, through the configuration (which will probably default to the architecture you're building the compiler on).
GCC probably uses a similar approach with some intermediate representation, but I'm not sure of the details. There's also a GCC back-end which can target LLVM too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With