10.4 アセンブラ(assembler)

  2.cc1が生成するアセンブリコードの実際
 前述のプリプロセッサが生成したマクロ展開済みコード(hello.i)に基づき、cc1がアセンブリコード生成を行います。比較のために、ソースファイル(hello.c)と、生成されたアセンブリコード(hello.s)を以下に示します。
<hello.c>

 #include <stdio.h>

 int main( void ) {
      printf("Hello, World!\n");
 }
   ↓
 [プリプロセッサ:cpp]
   ↓
<hello.i>
   ↓
 [アセンブリコード生成:cc1]
   ↓
<hello.s>

        .file   "hello.c"
       .version        "01.01"
 gcc2_compiled.:
 .section        .rodata
 .LC0:
       .string "Hello, World!\n"
 .text
       .align 4
 .globl main
       .type    main,@function
 main:
       pushl %ebp
       movl %esp,%ebp
        pushl $.LC0
       call printf
        leave
       ret
 .Lfe1:
       .size    main,.Lfe1-main
       .ident  "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
 実際の手続きで、call printfで呼び出している部分がありますが、これは後述するリンカによって、標準ライブラリ(/lib/libc.a)と動的リンクされることによって、呼び出し機構が解決されます。