1

Possible Duplicate:
Do programming language compilers first translate to assembly or directly to machine code?

For example:

gcc -c myprogram.c

The command above will produce myprogram.o, which is an object file. I want to know internally, does GCC have to go through the assembler step? E.g:

myprogram.c -> myprogram.asm -> myprogram.o
Community
  • 1
  • 1

3 Answers3

1

As far as I know, yes. The Assembly code generated by gcc is used to write the object file.

Ocracoke
  • 1,718
  • 3
  • 24
  • 38
0

It's standard for compilers to convert to assembly where you mention. As to "do they have to?" -- one can write a compiler that does not, however it's neither typical nor likely to occur these days.

mah
  • 39,056
  • 9
  • 76
  • 93
  • 1
    You have to write a machine level representation of the code you are compiling, be it for a virtual machine (so it is not called assembly) or for a hardware processor target (a DSP, an Intel processor, an ARM processor etc.). Unless, how could you execute it? – Vincenzo Pii Jan 06 '12 at 12:29
0

When you call gcc you are actually generating assembly code for your target architecture as an internal step of the compiler.

Try using the -S option to see the assembly code that the compiler generates.

The executable object file is than produced by the linker, which will be called internally as part of the command you issued.

Vincenzo Pii
  • 18,961
  • 8
  • 39
  • 49