所以我想寫一些x86來爲結構分配內存。我的C代碼看起來像這樣...在x86程序集中的結構分配
struc *uno = malloc(sizeof(struc));
uno->first = 0;
uno->second = 0;
uno->third = 0;
//And the struct
struct struc {
int first;
int second;
int *third;
}
而且拆機的模樣......
pushl %ebp
movl %esp, %ebp
subl $40, %esp
movl $12, (%esp)
call malloc
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl $0, (%eax)
movl -12(%ebp), %eax
movl $0, 4(%eax)
movl -12(%ebp), %eax
movl $0, 8(%eax)
movl $0, %eax
所以,我有幾個問題...
1)的大小結構是16,但爲什麼組件只顯示它分配12?
2)什麼是對於
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
的意義不只是把EAX的內容到EBP的地址 - 12。然後第二個語句是多餘的?
3)爲什麼當沒有其他本地變量或參數要推入堆棧時,esp會減少40?我會認爲它只需要減少16。
任何幫助表示讚賞,以及任何我可能錯過了,你認爲有關。我很新裝配。謝謝。
是什麼讓你覺得尺寸是16?你背後的理由是什麼? – 2014-09-05 20:05:09