1

C代码是:

int rSum(int *Start, int Count)
{
        if (Count <= 0)
        return 0;
        return *Start + rSum(Start+1, Count-1);
}

对应的汇编代码为:

.file "test98.c"
.text
.globl rSum
.type rSum, @function
rSum:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
cmpl $0, 12(%ebp)
jg .L2
movl $0, %eax
jmp .L3
.L2:
movl 8(%ebp), %eax
movl (%eax), %ebx
movl 12(%ebp), %eax
leal -1(%eax), %edx
movl 8(%ebp), %eax
addl $4, %eax
movl %edx, 4(%esp)
movl %eax, (%esp)
call rSum
leal (%ebx,%eax), %eax
.L3:
addl $20, %esp
popl %ebx
popl %ebp
ret
.size rSum, .-rSum
.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
.section .note.GNU-stack,"",@progbits

我无法理解这个指令“subl $20, %esp”,为什么是 $20?

4

1 回答 1

8

subl $20, %esp从堆栈指针中减去 20 ( esp)。这在堆栈上分配了 20 个字节的空间,可用于局部变量。

于 2012-12-07T03:06:25.757 回答