にコンパイルCでのプットとprintfの違いは、これはputs()
を使用して、私のCプログラムでは何:アセンブリ言語
#include <stdio.h>
int main(void){
puts("testing");
}
にgcc -S -o sample.s sample.c
を使用した後のアセンブリにそれをコンパイルし、これは私が得たものである:
.file "sample.c"
.section .rodata
.LC0:
.string "testing"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $.LC0, (%esp)
call puts
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.4.5 20110214 (Red Hat 4.4.5-6)"
.section .note.GNU-stack,"",@progbits
は、私が代わりにプットのprintf()
を使用していたのと同じ方法、この時間を行なったし、これは私が得たものである:
.file "sample.c"
.section .rodata
.LC0:
.string "testing"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $.LC0, %eax //this is the difference
movl %eax, (%esp)
call printf
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.4.5 20110214 (Red Hat 4.4.5-6)"
.section .note.GNU-stack,"",@progbits
ここ
printf()
機能mov $.LC0
は直接(%esp)
からputs()
機能mov %.LC0
ながらmov %eax
(%esp)
に、%eax
に、私は理解していないものです。 私はなぜそれが分からないのですか?
'printf'は可変引数関数であり、それらは異なった引数の固定数を持つ関数から呼び出されますので、それはおそらくです。 – Barmar
興味深いことに、os xにclangを使用すると、両方のプログラムが同じアセンブリにコンパイルされます。 – Leandros
GCCはlinux上で位置依存コードをコンパイルする理由は何ですか? – Leandros