我是一個學習裝配的新人。我寫了一個C文件:我有關於堆棧幀結構的問題嗎?
#include <stdlib.h>
int max(int c)
{
int d;
d = c + 1;
return d;
}
int main(void)
{
int a = 0;
int b;
b = max(a);
return 0;
}
和我使用gcc -S as01.c
並創建一個彙編文件。
.file "as01.c"
.text
.globl max
.type max, @function
max:
pushl %ebp
movl %esp, %ebp
subl $32, %esp
movl $0, -4(%ebp)
movl $1, -24(%ebp)
movl $2, -20(%ebp)
movl $3, -16(%ebp)
movl $4, -12(%ebp)
movl $6, -8(%ebp)
movl 8(%ebp), %eax
addl $1, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
.size max, .-max
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $20, %esp
movl $0, -4(%ebp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call max
movl %eax, -8(%ebp)
"as01.s" 38L, 638C
I」相混淆,怎麼一回事,因爲在movl %eax, -4(%ebp) movl -4(%ebp), %eax
MAX(), 我知道,%eax中用於返回任何函數的值。 我認爲%eax是臨時註冊商店c + 1
。 這是對的? 感謝您的回答。
你的平臺是什麼?當提出關於程序集的問題時,我想你最好讓我們知道你的操作系統和編譯器。你在使用64位平臺嗎? – 2011-04-11 12:31:55
當使用'gcc -S'來查看彙編輸出時,強烈建議使用'-Os'。 Unoptimised彙編程序是非常詳細和充滿無用的垃圾。相反,優化的彙編器更易於閱讀。 – 2011-04-11 12:46:46