我正在学习汇编语言,并且对调用约定和堆栈清理有疑问。
由于我使用的是 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
我确信这在小程序中并没有太大的区别,但是在一个大程序中,如果它永远不会被覆盖,它不会浪费空间吗?