我花了很多时间试图解决这个问题,我不明白,为什么它不起作用 . 问题的描述在下面的评论中:
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
.NOLIST
.NOCREF
INCLUDE \masm32\include\windows.inc
.LIST
.CODE
DllEntry PROC hInstDLL:HINSTANCE, reason:DWORD, reserved1:DWORD
mov eax, TRUE
ret
DllEntry ENDP
caesarAsm proc string: DWORD, key: DWORD, stringLength : DWORD
mov esi, 1 ; I cannot use this register, mov esi, (anything) causes Crash:
; Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention
mov eax, string
ret
caesarAsm endp
END DllEntry
我搜索了“整个”互联网,我发现问题与堆栈有关,但堆栈上的操作没有帮助我解决它 . 我正在使用Microsoft Visual Studio 2012
1 回答
我假设在此函数中不会发生错误,而是在其他地方触发 .
esi
寄存器是被调用者保存的寄存器 . 您必须确保其在函数出口处的值与入口时的值相同 . 您可以在函数中使用它,但必须保存并恢复其值 . 如:这些都有很好的记录 . 您只能在不保存的情况下使用
eax
,ecx
和edx
.旁注:您正在使用汇编程序的高级功能,您可能需要检查实际生成的代码,或者在您对结果有信心之前不要使用它们 . 顺便说一句,
masm
有一个USES
关键字,可以为您保存/恢复 .