For example, when I compile a C application is the outputted file read as binary or does the OS then interpret the compilation? Is the "machine language" pure binary?
EDIT: Yes, everything on a computer is pure binary. Im asking if the processer directly interprets the file outputted by the compiler or does the OS process it first?
A compiled program usually contains a header followed by the actualy CPU instructions (what you might call "binary") + various other data.
When you try to tell the OS to load your program the header will be read by the OS, and it is used to check that the executable file is really an executable file meant for this OS and this architecture. I.e. so that you don't accidentally run a Linux program on Windows or similar.
The header also contains various other bits of information on where the actual CPU instructions are located in the exeutable file, where data segments (text, strings, graphics) are located and so forth.
Once the OS is happy that the executable file is what it's supposed to be, then the OS will load the different segments from the executable file into memory and instruct the CPU to start running the "binary" code segment. This code is "pure" in a sense that it is straight CPU assembly code.
However the operating system can sill interrupt the CPU (for example to switch to another program, or just kill the program from memory and so forth). So there are a lot of things going on around this running program, and the OS kind of "manages" it and makes sure it behaves like a nice boy, but the code itself when it is running is executing pure CPU instructions as fast as possible..without the OS having to interpret the code in between.
Also note that the running program may call the OS in various ways while it is running. For example to request the OS to open a window on the display, open a network connection, allocate memory, and so forth. All that actually is happening is that the CPU just jumps to executing code at a different location (i.e. it jumps from running the code in the executable, to running some piece of code in the OS, and then jumps back).
That's it in a nutshell. There are many other ways to run programs though. There are virtual machines, interpreted languages (like Java or Ruby for example), and so forth. And they all run programs in different ways from the traditional "pure binary" languages like C/C++, but hopefully this helped you understand how it works a bit better.
I think what you're really asking is, do compiled programs run on bare metal (do they execute independent of the OS). The very short answer is, no. Although the program itself does execute native CPU instructions, the OS is capable of confining it and controlling its behavior. Furthermore, during the loading phase, certain external (dll) symbols need to be resolved. Finally most programs rely on various operating system abstractions (memory access, for example -- writing your own swap functionality is exceedingly difficult and pointless). In this sense, no binaries are not autonomous bare-metal machine code.
However they are pure binary. Everything on a computer is.
EDIT
Another way to interpret your question is: are compiled programs actually native CPU instructions. The answer is yes (aside from loading the binary, which the OS has to help with). Compilers output assembly language in which each line corresponds with exactly one CPU instruction. This is still text. The assembly is compiled by an assembler into actual binary.
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