Compiling C programming
-
In previous tutorial we got a quick idea about C language. Today we are going to learn what is compiling programs and why it is needed.
As the first step let’s see what’s a computer program and how they handle the computer to do our needs. You know that computers only works with binary. Take this example. If we want to print “hello ” to the screen we can write a program as this.
#include <studio.h> int main(){ printf("hello\n"); return 0; }
But computer can’t understand this language. This is the time Compiler comes to play. Compiler will transform C code into mashing instructions. Mashing code is a set of simple instructions.
CPU can process simple instructions like move eax, esp / pop ebp/ push esp etc quickly.
If there is a instruction as move eax 0x00
CPU will move zero into eax register. Also if we say push esp CPU will take the value from ebp and push that on to top of the stack.
But even instructions like move eax 0x00 are not actual mashing language. It’s something called Assembly language. So how CPU understand assembly ?.
There is a unique number for every assembly command. We call these hex numbers as Op-codes or operational codes.If opcode for move something into eax is 5f , opcode for move eax ,0x00 is 5f 00.After converting these hex values to binary it will be something like ‘0000011000100100000011‘ Now CPU can understand what it says and quickly do that instruction. If we take long story shortly what happens hear is transform our C instructions into CPU readable mashing language. That’s the job done by compiler.Now we have a clear idea about compiler and next see how we can compile C programs.
Compiling on a Linux mashingIf you are compiling a program on a Unix/Linux system, no additional software is needed. There is a awesome compiler called GCC for this.
You can easily open a shell and type
GCC -o [executable_name] [program_name.c]
GCC does rest for you.
Now you can run it by entering ./program_name.
If you don’t specify a name for executable file the default name will be a.out .
Compiling on a windows mashing.In sometimes you may need to write C codes in windows environment. For a example if you are learning win32 exploit development then you want to write your own vulnerable codes for practice. So let’s see how you can compile in windows. For this purpose you can use a compiler like dev c++. Dev compiler is a nice tool for compile and debug programs .
Now we can run the exe file.
Also you want a editor for write codes. You can use sublime , nano gedit or what ever you like. Personally I love sublime for coding.OK guys it’s all for this tutorial. Thank you for reading.Don’t forget to share it.(sharing is caring 🙂 . )
C you again on next posts.
If you loved my tutorial. Share it o -
patta mchan
-
@Malith Thanks ayiya :-)
-
Niyama wadak