i have some code(inline assembly).
void NativeLoop()
{
int m;
__asm
{
PUSH ECX
PUSH EDX
MOV ECX, 100000000
NEXTLOOP:
MOV EDX, ECX
AND EDX, 0X7FFFFFFF
MOV DWORD PTR m, EDX
DEC ECX
JNZ NEXTLOOP
POP EDX
POP ECX
}
}
MS C++ Automagicaly adds these codes(marked with **) to my procedure.
Why?
how to avoid it?
**push ebp
**mov ebp,esp
**push ecx
push ecx
push edx
mov ecx,5F5E100h
NEXTLOOP:
mov edx,ecx
and edx,7FFFFFFFh
mov dword ptr m,edx
dec ecx
jnz NEXTLOOP
pop edx
pop ecx
**mov esp,ebp
**pop ebp
**ret
It is the standard function entry and exit code. It establishes and tears down the stack frame. If you don’t want it you can use __declspec(naked). Don’t forget to include the RET if you do.
However, your snippet relies on a valid stack frame, your “m” variable requires it. It is addressed at [ebp-10]. Without the preamble, the ebp register won’t be set correctly and you’ll corrupt the stack frame of the caller.