The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ic2 on December 18, 2007, 10:11:52 AM

Title: Why Invoke Works and Push Don't
Post by: ic2 on December 18, 2007, 10:11:52 AM
I provided two example with the exact same code except in one location of each attachment where we PUSH instead of INVOKE .... Everyone may have experienced this at one time or another.  It don't happen that often, only.   For me, I just never barked about it until now, and I hope someone has the fix for this and can explain why this happen, and what coding effect causes this to happen ... 
How can I make PUSH Work in a situation like this Once and For All....


Any and all information may be helpful no matter how large or short comments may be.  I need to get to the bottom of it.  Tired of wondering about it...

Thanks in Advance



Invoke_Works Attachment Has This Code and it WORKS ! ! ! :



invoke CoCreateInstance,ADDR CLSID_ITaskbarList,NULL,CLSCTX_INPROC_SERVER,\
ADDR IID_ITaskbarList,ADDR ptb







Push_Do_Not Attachment Has This Code and it DON'T Work ! ! ! :
IT WILL CRASH ON BUTTON CLICK
And you can't say PUSH offset ptb without receiving an
"invalid operand for OFFSET"when trying to assemble





PUSH  ptb                           ;  ADDR ptb     
PUSH  offset IID_ITaskbarList       ;  GUID
PUSH  1                             ;  CLSCTX_INPROC_SERVER
PUSH  0                             ;  NULL
PUSH  offset CLSID_ITaskbarList     ;  GUID
CALL  CoCreateInstance





strange...


[attachment deleted by admin]
Title: Re: Why Invoke Works and Push Don't
Post by: hutch-- on December 18, 2007, 10:17:27 AM
Try this,



; Replace

PUSH  ptb

; with

lea eax, ptb
push eax
Title: Re: Why Invoke Works and Push Don't
Post by: ic2 on December 18, 2007, 10:26:37 AM
WoW!!!

Now I see why...

Thank you Mr.hutch
Title: Re: Why Invoke Works and Push Don't
Post by: ossama on December 18, 2007, 06:42:19 PM
but what is the diffrence between PUSH and LEA,is not it the same? because i had this problem some times in my programs and changed the PUSH OFFSET with LEA without knowing the reason.
Title: Re: Why Invoke Works and Push Don't
Post by: raymond on December 19, 2007, 03:23:47 AM
If you are using the address of LOCAL variables as parameters, that address is located within the stack and is not known at assembly time (it can be anywhere on the stack depending when the procedure is called). Therefore, its OFFSET is not known and trying to use "mov eax,offset variable" cannot work. For LOCAL variables within a procedure, only "lea eax,variable" will retrieve that address which is coded as a displacement in the stack along with the EBP register.

When using "push variable" with a LOCAL variable, you actually push the value currently located at that address within the stack (NOT its address).
Title: Re: Why Invoke Works and Push Don't
Post by: ossama on December 20, 2007, 03:25:37 PM
Quote from: ossama on December 18, 2007, 06:42:19 PM
but what is the diffrence between PUSH and LEA,is not it the same? because i had this problem some times in my programs and changed the PUSH OFFSET with LEA without knowing the reason.

sorry it is my mistake, i mean : i changed the (ADDR variable) with the (LEA variable) solved the problem.
using push offset of local variable will get error at assembly time,but using the (addr variable) will not get error at assembly time, it will get error at run time,but when i changed the (addr variable) with (lea variable) solved the problem.
i hope my explanation is clear (sorry for the english i have)
thank you