ちょっとお遊びでコンパイラの動きを調べます。
小手調べに...
/////////////////////////////////////////////
#include
main(){
int i;
i=0;
++i;
printf("i=%d",i);
}
/////////////////////////////////////////////
cc -S test.c
/////////////////////////////////////////////
.file "test.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "i=%d"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
subl $24,%esp
movl $0,-4(%ebp)
incl -4(%ebp)
addl $-8,%esp
movl -4(%ebp),%eax
pushl %eax
pushl $.LC0
call printf
addl $16,%esp
.L2:
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 2.95.3 20010315 (release)"
/////////////////////////////////////////////
どの行がどれに対応するか分かりますか?
変数の領域がどこに確保されるかとか、
printfの関数呼び出しとパラメーターの渡し方に注目です。
スタックの使い方を理解しておきましょう。