<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等。