Next: , Previous: The preprocessor, Up: How the compiler works


12.3 The compiler

The next stage of the process is the actual compilation of preprocessed source code to assembly language, for a specific processor. The command-line option -S instructs gcc to convert the preprocessed C source code to assembly language without creating an object file:

     $ gcc -Wall -S hello.i

The resulting assembly language is stored in the file hello.s. Here is what the Hello World assembly language for an Intel x86 (i686) processor looks like:

     $ cat hello.s
         .file  "hello.c"
         .section  .rodata
     .LC0:
         .string  "Hello, world!\n"
         .text
     .globl main
         .type  main, @function
     main:
         pushl  %ebp
         movl  %esp, %ebp
         subl  $8, %esp
         andl  $-16, %esp
         movl  $0, %eax
         subl  %eax, %esp
         movl  $.LC0, (%esp)
         call  printf
         movl  $0, %eax
         leave
         ret
         .size  main, .-main
         .ident  "GCC: (GNU) 3.3.1"

Note that the assembly language contains a call to the external function printf.