Pregunta

Hello I have a question about the lea instruction and arrays, This works fine:

char *msg = new char[6];
msg = "hello";

_asm{
    push        10h
    push        0
    mov         eax, [msg]
    push        eax
    push        0
    call        MessageBox
     }

}

But why do I get an "operand size conflict" error here?

char msg2[] = "hey2";
_asm{
    push        10h
    push        0
    mov         eax, [msg2]
    push        eax
    push        0
    call        MessageBox
}  

And why does it work again with lea?

char msg2[] = "hey2";
_asm{
    push        10h
    push        0
    lea         eax, [msg2]  // <-
    push        eax
    push        0
    call        MessageBox
}  
¿Fue útil?

Solución

Here you are trying to dereference the pointer which points to size char, but you try to load an int from it.

mov         eax, [msg2]

Not sure if this is the right syntax, but you might use

mov   eax, offset msg3

here, to load the address, or use the lea instruction.

In C this would be similar to:

char msg2[10];
char *p = &msg2[0];
int x = *p;

This instruction doesn't dereference the pointer, it just takes the address of it and it can also calculate addresses with certain operators.

lea         eax, [msg2]  // <-

Is aequivalent of:

char msg2[10];
char *p = &msg2[0];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top