I noticed in Tutorial 3 in WinMain that instead of writing

mov wc.hInstance,hInstance

he writes

push hInstance
pop wc.hInstance

I assume this has something to do with the fact that wc is on the stack while hInstance is not. Anyway, so what's the rule behind this? Why is "mov wc.hInstance,hInstance" wrong?

Thanks.
Posted on 2005-04-30 23:23:47 by wildgnu
There is no opcodes that allows mov mem, mem. That's why in his example he push the data onto the stack then pop it into the variable he wanted. Of course he could have done


mov eax, hInstance
mov wc.hInstance, eax


It is a matter of choice I suppose.
Posted on 2005-05-01 02:29:18 by roticv
roticv is right.
I noticed in Tutorial 3 in WinMain that instead of writing

mov wc.hInstance,hInstance


It is "m2m" instead of "mov".
"m2m" is the macro name.

Examples of a "m2m" macro:

m2m MACRO a1, a2
            push a2
            pop a1
        ENDM

or

m2m MACRO a1, a2
            mov eax, a2
            mov a1, eax
        ENDM


So, when pre-compiling...

    m2m wc.hInstance, hInstance


will be replaced by...

    push hInstance
    pop wc.hInstance


or

    mov eax, hInstance
    mov wc.hInstance, eax


Depending on the macro used.

Hope this help.

Kecol.-
Posted on 2005-05-02 10:02:42 by Kecol
push/pop is slower and two bytes longer than moving through EAX. Not that it matters a lot, but you should keep it in mind. And you could use a WNDCLASS/EX structure initialized in .data rather than filling it at runtime (though hInstance and a few other members do have to be filled runtime).
Posted on 2005-05-02 11:35:20 by f0dder
The logic is simple for using push/pop, it does not require a register. Where speed matters 2 MOV's are faster but require the use of a register to transfer the data.  push/pop is more than fast enough for high level code like working with API code but in the middle of a processor intensive algo, the two MOV instructions are a better choice.
Posted on 2005-06-04 02:04:48 by hutch--