flat assembler
Message board for the users of flat assembler.

Index > Main > Which is better

Author
Thread Post new topic Reply to topic
Razneb



Joined: 10 Feb 2005
Posts: 12
Razneb 10 Feb 2005, 03:48
Is it better to manually push the values then call a function.

Or is it better to use the invoke or stdcall macro and let it push and call the function automatically.

Which one is better to use. Resource, and speed-wise.

Razneb-
Post 10 Feb 2005, 03:48
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 10 Feb 2005, 04:17
Actually it is approximately the same.
When using macroses "stdcall" and "invoke" we have more "compact" source code that is generally more readable. But sometimes using separate push instructions gives us more flexibility and better code.
For example, let say we save some register in the stack in order to preserve it for future call of API function:
Code:
invoke  GetDlgItem, [.hwnd], 100
push  eax   ; preserve eax for the second call of API

invoke SomeAPI, eax

pop eax
invoke OtherAPI, eax
    


The last two rows will generate following pretty bad code:
Code:
pop   eax
push  eax
call  [OtherAPI]
    


In similar cases (especially when there are more arguments to the functions) I am using:
Code:
invoke  OtherFunction, arg1, arg2  ;, agument is in the stack    


Note that good comments are simply mandatory in such using. The main requirement for optimal using of "invoke" type macroses is good understanding what actually happens behind the macro...

Regards
Post 10 Feb 2005, 04:17
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Razneb



Joined: 10 Feb 2005
Posts: 12
Razneb 10 Feb 2005, 04:27
So, lets say I am using 'CreateFont'. It would be a complete waste of line space if I manually pushed the 14 arguments?

Thanks for your reply.

Razneb-
Post 10 Feb 2005, 04:27
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 10 Feb 2005, 12:44
yes, a waste of line space since there's no runtime advantage. Of course one could argue that if you manually push arguments you can add a comment on what each argument is, but... that's overkill, IMHO.
Post 10 Feb 2005, 12:44
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Feb 2005, 13:24
i prefer manual pushing if arguments need comments. And no one is such fool to remember meaning of 14 arguments, so it improves readability of code. Of course not with well known APIs.
Post 10 Feb 2005, 13:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 11 Feb 2005, 06:06
I use manual pushing and call instead of invoke, mostly because I have a bad habit of using hex instead of constant names so i have to shorthand comment them.
Post 11 Feb 2005, 06:06
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.