<b>1.3.2 編譯</b>
接下來gcc對hello.i進行編譯,指令如下:
$gcc –s hello.i
–o hello.s
編譯後産生的彙編檔案hello.s内容如下:
.file "hello.c"
.section .rodata
.lc0:
.string "hello
world!"
.text
.globl main
.type main,
@function
main:
pushl %ebp
movl %esp,
%ebp
andl $-16,
%esp
subl $16,
movl $.lc0,
%eax
movl %eax,
(%esp)
call printf
movl $0,
leave
ret
.size main,
.-main
.ident "gcc:
(ubuntu/linaro 4.4.4-14ubuntu5) 4.4.5"
.section .note.gnu-stack,"",@progbits
gcc生成的彙編代碼的文法是at&t格式,與intel格式的彙編有所不同(若要生成intel格式的彙編代碼,使用編譯選項“-masm=intel”即可)。比如立即數用“$”字首,寄存器用“%”字首,記憶體尋址使用小括号等。差別最大的是,at&t彙編指令的源操作數在前,目标操作數在後,這與intel彙編文法正好相反。本書會在後續章節中較長的描述這兩種彙編文法格式的差別。
不過我們仍能從中發現進階語言代碼中傳遞過來的資訊,比如字元串“hello world!”、主函數名稱main、函數調用call printf等。