Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2018, 01:34
gigaman gigaman is offline
Friend
 
Join Date: Jun 2002
Posts: 87
Rept. Given: 0
Rept. Rcvd 3 Times in 2 Posts
Thanks Given: 0
Thanks Rcvd at 14 Times in 11 Posts
gigaman Reputation: 4
Does one call or jump really matter?
I mean, if you said you couldn't easily access local variables or structures, I'd agree... but "excessive call", it sounds like you are trying to optimize something. In that case inline assembler is hardly any good - it's a blackbox for the compiler (at least for the Microsoft's) so it has to dump the values from registers into local variables and after the inline assembly load them back. In other words, a piece of inline assembly heavily breaks the optimization of the surrounding C code - so it's usually not worth it, it does more damage than one call would (so it's better to write the whole CPU intensive piece of code in assembler as a separate function).
Reply With Quote
The Following User Says Thank You to gigaman For This Useful Post:
tonyweb (06-20-2018)
  #2  
Old 06-20-2018, 05:38
chants chants is offline
VIP
 
Join Date: Jul 2016
Posts: 826
Rept. Given: 47
Rept. Rcvd 50 Times in 31 Posts
Thanks Given: 737
Thanks Rcvd at 1,140 Times in 529 Posts
chants Reputation: 51
It matters because its very convenient to program like this. By having to call/return or jump/jump or what have you (also don't forget all the stack setup and cleanup), it forces calling conventions and requires the parameters to be dealt with and such. Yes the MS implementation is not as clever as in GCC/GAS where you can really customize details of the behavior. I agree for optimization its a lame point as you would better be off with pure asm or optimized C rather than a mix and match without sophisticated inline-ing support.

Further its easier to write portable 64/32 bit code without calling conventions and clever use of macros, as the calling conventions are so different you have to use different assembly instructions (registers vs stack).

A C function can modify itself in memory also using clever tricks with inline assembler which has its obfuscation or other uses.

But I suppose this discussion is easily already documented:
Quote:
https://msdn.microsoft.com/en-us/library/80ccffx3.aspx
Quote:
Advantages of Inline Assembly
Because the inline assembler doesn't require separate assembly and link steps, it is more convenient than a separate assembler. Inline assembly code can use any C variable or function name that is in scope, so it is easy to integrate it with your program's C code. Because the assembly code can be mixed inline with C or C++ statements, it can do tasks that are cumbersome or impossible in C or C++.
The uses of inline assembly include:
Writing functions in assembly language.
Spot-optimizing speed-critical sections of code.
Making direct hardware access for device drivers.
Writing prolog and epilog code for "naked" calls.
So optimization is on the list after all
Reply With Quote
The Following User Says Thank You to chants For This Useful Post:
tonyweb (06-20-2018)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inline patche hp3 Source Code 3 06-04-2021 14:48
X64 inline asm Fyyre x64 OS 48 08-10-2014 16:50
Inline Patching MaRKuS-DJM General Discussion 1 01-24-2004 23:03


All times are GMT +8. The time now is 05:19.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )