Ground floor: GNU’s C Compiler

Im starting another mini-series I call “Ground Floor”. It’s a mini-series that will go over all of the interesting subject/concepts I will learn in low level programming. Enjoy!


GNU FOR LIFE!!!! MOO SAYS THE COW!!!! but thats not a cow…so it doesn’t say moo :((((

Programming is cool…you may have just got started learning Javascript and think that your code speaks directly to your computers cpu, just like if you where talking to someone in a different language, on the other hand lot’s of stuff happens behind the scene in order for a Javascript file or Python script to execute flawlessly(unless you have errors). This is the world of Compiling! Compiling is a process which takes your humanly readable code(humanly readable language) and “compiles” it into code that your machine can understand and execute.

gcc bestProgrammEver.c

What happens when you enter the command above? What steps does your computer take to turn a

int main(void)
{
puts("Hello World!");
return(0);
}

into

01001001 01100110 00100000 01111001 01101111 01110101 00100000 01100100 01100101 01100011 01101111 01100100 01100101 01100100 00100000 01110100 01101000 01101001 01110011 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01110100 01101000 01100001 01110100 00100000 01101101 01100101 01100001 01101110 01110011 00100000 01111001 01101111 01110101 00100000 01101100 01101001 01101011 01100101 00100000 01101101 01111001 00100000 01100001 01110010 01110100 01101001 01100011 01101100 01100101 00101100 00100000 01100100 01101111 01101110 00100111 01110100 00100000 01100110 01101111 01110010 01100111 01100101 01110100 00100000 01110100 01101111 00100000 01101100 01100101 01100001 01110110 01100101 00100000 01100001 00100000 01100011 01101100 01100001 01110000 00101110 00101110 00101110 01110100 01100001 01101100 01101011 01101001 01101110 01100111 00100000 01100001 01100010 01101111 01110101 01110100 00100000 01100011 01101100 01100001 01110000 01110000 01101001 01101110 01100111 00101110 00101110 00101110 01100100 01101001 01100100 00100000 01111001 01101111 01110101 00100000 01100011 01101000 01100101 01100011 01101011 00100000 01101111 01110101 01110100 00100000 01110100 01101000 01100001 01110100 00100000 01110010 01101001 01100011 01101011 00100000 01100001 01101110 01100100 00100000 01101101 01101111 01110010 01110100 01111001 00100000 01100101 01110000 01101001 01110011 01101111 01100100 01100101 00111111 00100000 01110011 00110000 00110011 01100101 00110000 00110111 00101100 00100000 01110111 01101111 01110111 00100000 01110111 01101000 01100001 01110100 00100000 01100001 00100000 01110011 01101000 01101111 01110111 00101100 00100000 01110100 01101000 01100001 01110100 00100000 01110111 01100001 01110011 00100000 01100001 00100000 01110010 01100101 01100001 01101100 00100000 01100111 01101111 01101111 01100100 00100000 01101111 01101110 01100101 00101100 00100000 01100001 00100000 01110010 01100101 01100001 01101100 00100000 01110010 01101001 01101110 01100111 01100101 01110010 00101110

Above is binary code, its the output of a compiler, its what you computer can understand, you can’t read code in binary thats why you compile the humanly readable one to the machine code.

Your C code takes a few loops thru the compiler thru 4 main steps. First, GCC sends your code to the pre processor, the pre-processor gets your file ready assembly. All of your #INCLUDE tags and expansions get processed so that when they go to assembly its all in one package, after that it goes to assembly. The assembly is when the code gets converted into, assembly is a language, its one of the lowest level language that works with symbols, everything gets replaced with symbols that match with the assembly’s language format. Think of the assembly language as a VERY LONG instruction page, like an Ikea manual but with every single move(ex. move screwdriver 91 degrees to the right for 2.05 seconds), it instructs and breaks down the code into symbols that will help link the code. Linking is the final part of a compiler, it links all of the libraries with your code. That stdio.h file is a library! at this stage it gets link the library to the file so that its has all the dependencies it needs to run in a single machine code file. Think of it as grabbing everything you need before going on a trip, but only what you essentially need, not all the extras that you wont use.


Well that was one hell of a trip, after all of that you get a nice executable file out the other end. It’s amazing what happens behind the scenes that we take for granted when writing code form our high level languages looking down from our ivory towers… but when it comes down to it, without a good compiler to keep our code ticking, our tower would come crashing down spectacularly…Hope this was a good and short read, if you liked it…clap, if you didn’t…leave some constructive criticism and I would be happy to read it.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.