ASM中的新框架

时间:2014-12-17 16:24:02

标签: assembly nasm

理论上,当我执行一个电话时:

堆栈

Local variables
EBP
RET ADDRESS
Args
...

嗯,案例是,为什么当我执行“pop esi”时,我获得了RET ADDRESS而不是EBP?

# NASM
BITS 32

section .text
global _start

_start:
call function
mov eax,0x41414141



function:
# esi get the address of "mov eax,0x41414141"
# but theorically, we should obtain the EBP value, no?
pop esi

# Exit
xor eax,eax
xor ebx,ebx
mov al,0x01
int 0x80

1 个答案:

答案 0 :(得分:1)

您在那里显示的功能是“裸”,即它没有设置堆栈帧。

如果您需要,可以在汇编程序中手动执行此操作。通常它看起来像:

function:
push ebp
mov ebp, esp
...

然后你必须在返回之前手动拆掉它,通常是

mov esp, ebp
pop ebp
ret n

(或者我可以使用leave指令)

如果你有这个,那么你的原理图就是正确的,尽管它与我个人在英特尔平台上的思考方式完全颠倒了。在这个平台上,堆栈在内存中向下增长。