RSP如何降低?

时间:2011-03-28 15:11:10

标签: assembly gdb

通过调试,我发现在func中调用main时,RSP8减少0x7fffffffe9600x7fffffffe958:< / p>

(gdb) disas func
Dump of assembler code for function func:
0x0000000000400448 <func+0>:    push   %rbp
0x0000000000400449 <func+1>:    mov    %rsp,%rbp
0x000000000040044c <func+4>:    mov    $0x1,%eax
0x0000000000400451 <func+9>:    leaveq 
0x0000000000400452 <func+10>:   retq   
End of assembler dump.
(gdb) disas main
Dump of assembler code for function main:
0x0000000000400453 <main+0>:    push   %rbp
0x0000000000400454 <main+1>:    mov    %rsp,%rbp
0x0000000000400457 <main+4>:    callq  0x400448 <func>
0x000000000040045c <main+9>:    mov    $0x6,%eax
0x0000000000400461 <main+14>:   leaveq 
0x0000000000400462 <main+15>:   retq   

为什么calla func会使rsp减少8

更新

(gdb) x/4x 0x7fffffffe960
0x7fffffffe960: 0x00000000  0x00000000  0xf401d994  0x00000034

1 个答案:

答案 0 :(得分:1)

这是因为返回地址的大小也是64位(例如0x0000000000400457)。当您调用func时,该值将被放入堆栈,堆栈指针将减少该数量。