compiler
a compiler translates source code into machine level code
- preprocessor: inlcudes and macros are expanded
- compiler: generates assembly code
- compiler: generates binary object code
- linker: links object code with std. libr functions (e.g. printf) and creates executable
example:
- just show assembly from c source file:[code]gcc -O2 -S code.c[/code]
- compile and assemble to create object file:
[code]gcc -O2 -c code.c[/code] - to disassemble an object file again:[code]objdump -d code.o[/code]
- actually creating an executable (linking object files and one needs to have a main file):
[code]gcc -O2 -o prog code.o main.c[/code]
I used these example files:
[code language="cpp" collapse="true" title="code.c"]
int accum = 0;
int sum(int x, int y) 4{
int t = x + y;
accum += t;
return t;
}
[/code]
[code language="cpp" collapse="true" title="main.c"]
int main(){
return sum(1,3);
}
[/code]