我在从内联汇编调用 C++ 函数时遇到问题。我需要将所需的参数压入堆栈,但出了点问题。例如,如果我 push 3
,那么一切正常,但是如果我尝试(从函数)或[ebp+8]
(相同的东西)推送变量的值,则1
无论实际值如何,它都会被调用函数错误地接收。
int i;
DWORD nietgebruikt(DWORD x)
{
// x is always 1
x += 40;
return x;
}
_declspec(naked) void asmfunc(DWORD x)
{
_asm
{
push x; // or [ebp+8]
call nietgebruikt
pop x // or [ebp+8]
add i, eax
ret
}
}
int _tmain(int argc, _TCHAR* argv[])
{
i = 1;
asmfunc(3);
cout << i << endl;
system("pause");
return 0;
}