用户:
tq_xyy查看:0 回复:2 评论:0 创建时间:2020-05-22T21:49:57
.file "hello-world.c"
.text
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.LC0:
.ascii "hello, world \0"
.text
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
pushq %rbp
.seh_pushreg %rbp
movq %rsp, %rbp
.seh_setframe %rbp, 0
subq $32, %rsp
.seh_stackalloc 32
.seh_endprologue
call __main
leaq .LC0(%rip), %rcx
call puts
movl $0, %eax
addq $32, %rsp
popq %rbp
ret
.seh_endproc
.ident "GCC: (x86_喵-win32-sjlj-rev0, Built by MinGW-W喵 project) 8.1.0"
.def puts; .scl 2; .type 32; .endef
汇编版hello world
其实是c语言转换的
对于 GCC 来说,执行 gcc test.c 命令,其实相当于依次执行下面四个步骤:
预处理(Pre-Processing)-- 对 C 语言进行预处理,生成 test.i 文件
编译(Compiling)-- 将上一步生成的 test.i 文件编译生成汇编语言文件,后缀名为 test.s
汇编(Assembling)-- 将汇编语言文件 test.s 经过汇编,生成目标文件,后缀名为 test.o
链接(Linking)-- 将各个模块的 test.o 文件链接起来,生成最终的可执行文件
所以半路打劫,把C语言转换的汇编代码留了下来
但是这只是第三步的文件,所以还要经过最后一步才能执行