I read in a thread here that you can save a few bytes in your program when you do the following:
lets say your api is like that--->invoke api,0,0,hbutton
just an example,
you could save two bytes by doing it that way:
push eax
push eax
push hbutton
call api
1) Why is that ?
2) Do i have to pop eax first or empty it somehow ?
3) Does pop eax mean i empty the stack or i copy its content into a pointer ?
Thanks, Olli
Push 0 generates a 2 byte inst - 6A00.
Push eax generates a 1 byte inst - 50.
However, you must be sure that eax contains 0 before you push it, using something like xor eax,eax, which generates 2 bytes - 33C0.
So in this case, unless you are SURE that eax contained 0, and could eliminate the xor, it works out to the same thing! If you were pushing more than 2 0s on the stack, you could save 1 byte for each additional one. But then you run into readability issues, and more importantly, you lose the ability of having INVOKE check that you are passing the correct number of parameters.
Doesn't seem worth it to me. :)
.......if you push, you save some register........and if you pop, you recall that register:
push EAX ;saves EAX by putting it on the stack
push EBX ;saves EBX by putting it on the stack
xxx xxx, xxx ;do whatever you need to
pop EBX ;gets the old value that you saved
pop EAX ;gets the old value that you saved
........you usually do this when you go in and out of calls. And remember, the first thing you push is the last thing you pop....you must do it in reverse order:
invoke API ;make some needed call
invoke Second API, EAX ;call which needs EAX from above
API PROC ;API's process
push EAX ;save EAX cause Second API needs it
... ;whatever API does
pop EAX ;get EAX back for Second API
ret ;return
API endp ;end API's process
Hope that helped,
*unknown*