I am using Visual Studio 2017 and compiling for 32-bit.
Say I have the following code snippet. The statements which don't compile give "invalid operand" errors.
int localVar = 0;
__asm {
    mov eax,      [esp+4]         <----- compiles
    mov localVar,  esp            <----- compiles
    mov localVar, [esp]           <----- doesn't compile
    mov localVar, [esp+4]         <----- doesn't compile
}
I'm aware that the 2nd and 3rd statement aren't equivalent, but I wanted to highlight the following point...
Essentially it appears that if I'm using brackets around the second operand in this manner AND storing the results into a local variable it doesn't work. I was under the impression using brackets like that was valid syntax, as proven by the first statement which stores the result into eax.
I have speculated it might be something to do with my variable type and I have tried to change mov to movl but that doesn't work either.
Basically my ultimate goal is for this to work properly:
mov localVar, [esp+4]
How do i achieve this? The type of localVar doesn't have to be int... I just thought that should work.
 
    