_AddPS 函数使堆栈不平衡,并且旨在成为 StdCAll。我没有更多信息,这只是我的第二段汇编程序代码(我的第一段是模拟 cdecl 函数调用的测试 .exe)。
.386
.MODEL FLAT, STDCALL
option casemap :none ; case sensitive
.CODE
_LibMain proc instance:dword, reason:dword, unused:dword
mov EAX, 1 ;
ret
_LibMain endp
_AddPS proc a:dword, b:dword
push ebp ;
mov ebp, esp ; // ebp << esp
push EAX ;
push EBX ;
mov EAX, [ebp+8] ;
mov EBX, [ebp+4] ;
add EAX, EBX ;
pop EBX ;
pop EAX ;
mov esp, ebp ;
pop ebp ;
RET 8
_AddPS endp
END _LibMain
使用 MASM 和以下命令行编译:
c:\Asm\Test.asm /coff /Gz /FeC:\Asm\Test.dll /FoC:\Asm\Test.obj /link /SUBSYSTEM:WINDOWS /link /DLL
编辑:以下代码有效,但我不清楚原因:
_Test proc a:dword, b:dword
push ebp ; Store the stack frame.
push EAX ; Store EAX. Probably not needed.
mov EAX, a ; Move a into EAX.
add EAX, b ; Add b to EAX.
add esp, 4 ; Move past the stored EAX without popping.
pop ebp ; pop the stack frame.
RET 8 // dword is 4 bytes in .386. We return past the parameters.
_Test endp // Marks where to stop compiling the function.