我有一个从ac程序调用的简单汇编函数,我必须使用FIDIV需要内存操作数的指令().
将值移动到[esp - 2]下一条指令并将其用于下一条指令是否安全,或者以这种方式使用堆栈是否安全?
我知道有很多变通方法,而且我真的不再需要它了,所以现在只是好奇心.
使用类似的偏移量会在线程上的任何操作需要再次触摸堆栈时将数据明确地暴露给损坏.这可能发生在中断,APC,上下文切换,异常等期间.您要做的是实际上在堆栈上保留空间并保存指向它的指针.
sub esp, 4 ; Allways move it 4 byte increments. x64 may need 8 bytes
mov eax, esp ; EAX points to your 4 byte buffer
add esp, 4 ; Restore allocation.
Run Code Online (Sandbox Code Playgroud)
当然,如果您只需要几个字节,则push指令要快得多
push eax
mov eax, esp ; EAX points to a buffer properly alligned to system
Run Code Online (Sandbox Code Playgroud)