What is the difference between invoke and pushes & call?, i've heard some like Xtreme that claim pushes are better and izcelions in his tuts that invoke is just a type check test against a prototype i think thats the right answer.. but ??

i would appreciatte any help  ;)
Posted on 2005-07-09 00:47:45 by Punky

Just see what both do and you will have answered the question. In almost all instances invoke does automatic conversion to push/call syntax and its as efficient as doing the same by hand but there are occasions when you want to do domething different that manually coding a function call has an advantage.

Just try simple code like this to start with.

  invoke MessageBox,hWnd,lpMsg,lpTitle,MB_OK

  push MB_OK
  push lpTitle
  push lpMsg
  push hWnd
  call MessageBox

If you have masm32, disassemble the generated code and you will see that they are close enough to identical. Its when you need to do things like load a variable part way through pushing arguments or using a different register for a LOCAL address that you can do more than invoke allows.
Posted on 2005-07-09 02:10:26 by hutch--
invoke does basic typechecking, and also allows you to use "addr foo" to push the address of a local variable (this translates to "lea eax, / push eax"). Invoke is usually more handy, and allows less lines of source code.
Posted on 2005-07-09 08:15:49 by f0dder
And it can fix the stack for you if you are calling cdecl functions. Therefore, I don't usually see a reason for you to not use it.
Posted on 2005-07-09 08:39:59 by roticv
thanks ya all? ?:)

but then, like Xtreme said, pushes are better than invokes cuz in the example code we can use, said:

push OFFSET myString
call PrintString

and with the invoke is translated to:

lea eax,myString
push eax
call PrintString

which is slower ... so ?
Posted on 2005-07-09 23:50:06 by Punky
You can use "offset" instead of "addr" in invokes btw. So your example is not valid. Offset does not work for local variables and you would still end up doing the maual lea + push eax.

I only do manual pushes when I push the parameters of a function onto the stack earlier on and then calling a function with lesser parameters to save some bytes.

If you ask me, doing your own pushes just causes more problem (because of lack of type checking) and also you end up typing more code. I don't see the validity of Xtreme's (whoever that is) arguments.
Posted on 2005-07-09 23:56:44 by roticv
addr only uses the lea/push combination if the argument is a local variable - for globals, it returns the offset, so extreme's argument is invalid.

And, well, if you worry about call overhead for a function, your program design is invalid too :) - you shouldn't split extremely small pieces of code out to functions, especially not if they're time-critical. Then macros would be a better choice.
Posted on 2005-07-10 01:06:40 by f0dder
o i see, now all is clear to me , thank you guys :)

And yes roctiv, Xtreme http://www.asmcommunity.net/board/index.php?action=profile;u=338 in one of his owner draw menues examples said he was about to convert all the invokes in a future version to pushes/call to improve performance (i think) that's why this post.
Posted on 2005-07-10 03:35:35 by Punky
improve performance? O_o - sounds weird.
Posted on 2005-07-10 03:52:04 by f0dder

I add my comments to both f0dder and Victor here that there is NO peformance gain by doing so. Most assembler programmers grew up with manual function calls so its not like its a big deal but the only gain you have by doing so is if you are doing something different in the way you produce the arguments for the function call. As far as loading the address of a LOCAL variable, it still needs to be referenced and you will need to use LEA to do this.
Posted on 2005-07-10 04:13:01 by hutch--
There's one possible advantage of using manual pushes - that you can add a comment for each value you push. But that can be done with invoke too (you can split the single invoke line into multiple lines), and in most cases, documenting arguments is overkill and bad coding style anyway :)
Posted on 2005-07-10 04:17:42 by f0dder
t hink i'll stick to invokes  :lol:
Posted on 2005-07-12 14:33:55 by Punky