【发布时间】:2013-03-03 00:38:00
【问题描述】:
我正在学习汇编语言,有一个关于调用约定和堆栈清理的问题。
由于我使用的是 OSX,因此我需要对系统调用使用 BSD 调用约定,如下所示。
SECTION .text
push StringLen ; Push string length
push MyString ; Push the string
push 0x1 ; Push the file descriptor (stdout)
mov eax, 4 ; Push the system call (sys_write)
int 0x80 ; Call kernel dispatcher
add esp, 0x10 ; Clean up stack 16 bytes for 4DWORDS
mov eax, 1
mov ebx, 0
int 0x80 ; System exit
我的问题是,add esp, 0x10 是否被认为是清理堆栈的好习惯?我已经尝试过,清理后它会显示这些值仍在堆栈上,但在推送另一个值时会被覆盖,例如
add esp, 0x10 ; Clean up stack 16 bytes for 4DWORDS
push 0x1A ; New push overwrites the previous stack values
我确信这在小程序中并没有太大的不同,但在大程序中,如果它永远不会被覆盖,它不会浪费空间吗?
【问题讨论】:
标签: assembly stack calling-convention