在编译源文件时指定"-S",输出汇编代码到.s文件
gcc -S hello.c
使用GNU汇编器as来编译源代码hello.s
as -o hello.o hello.s
[root@localhost kernel]# gcc -S hello.c [root@localhost kernel]# ls hello.c hello.s [root@localhost kernel]# cat hello.s .file "hello.c" .section .rodata .LC0: .string "haha" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 andl $-16, %esp subl $16, %esp movl $.LC0, %eax movl %eax, (%esp) call printf movl $0, %eax leave .cfi_restore 5 .cfi_def_cfa 4, 4 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (GNU) 4.6.3 20120306 (Red Hat 4.6.3-2)" .section .note.GNU-stack,"",@progbits [root@localhost kernel]# [root@localhost kernel]# [root@localhost kernel]# [root@localhost kernel]# cat hello.c #include <stdio.h> #include <stdlib.h> int main(){ printf("haha"); return 0; } [root@localhost kernel]#