我用c语言写了一个简单的程序,经典的helloworld。我想知道编译器将它翻译成汇编代码时的样子。
我使用 MinGW 和命令:
gcc -S hello.c
当我打开这个文件时,我希望它至少有点类似于直接用汇编语言编写的 hello-world 程序,即:
jmp 115
db 'Hello world!$' (db = define bytes)
-a 115
mov ah, 09 (09 for displaying strings ... ah = 'command register')
mov dx, 102 (adress of the string)
int 21
int 20
相反,它看起来像这样:
.file "hellow.c"
.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
_main:
LFB6:
.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
call ___main
movl $LC0, (%esp)
call _puts
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE6:
.def _puts;
.scl 2;
.type 32;
.endef
我对汇编语言知之甚少,但我确实认识到所谓的助记符,如 ADD、POP、PUSH、MOV、JMP、INT 等。在 c 编译器生成的代码中看不到很多这些。
我误会了什么?