I have a function in MASM x86 without a prologue. I want to compare an argument on the stack that was passed to the function.
.MODEL flat
extern x:dword
foo proc
cmp esp+4, x
...
foo endp
I've tried DWORD PTR [esp+4],x
as well but that doesn't work either. I don't want to mess with popping from the stack or anything else because this is just a forwarding function. My question is basically why can't I make a comparison directly with an arg on the stack against a global variable? If it's impossible please tell me a different way to solve it.
x86 dooesn't support direct comparison of two memory locations. You need to move one of them into a register (preferably eax
) first and then compare using the register:
MOV EAX, x
CMP DWORD PTR [ESP + 4], EAX