1 minute read

a compiler translates source code into machine level code

  1. preprocessor: inlcudes and macros are expanded
  2. compiler: generates assembly code
  3. compiler: generates binary object code
  4. 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]

Categories:

Updated: