flat assembler
Message board for the users of flat assembler.

Index > Main > difference between call, invoke and cinvoke?

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 18 May 2018, 22:30
Hello,
everything is in the title, I'd like to know the difference between call, invoke and cinvoke. When should I use them? Can I only use one instead of the three?
This would probably make my compiler's job easier, it wouldn't need to deduce which feature to use...
Thank you Wink

_________________
The best way to predict the future is to invent it.
Post 18 May 2018, 22:30
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 816
Location: Russian Federation, Sochi
ProMiNick 18 May 2018, 23:42
call is more flexible, because invoke & cinvoke are abstraction macros around of it.
In case of call you can make with call arguments things unacessible in other cases: such as early pushing parameters, or reusing some of parameters left in stack from previous call, and one more - invoke & cinvoke - indirect call, call itself can be direct & indirect.
Post 18 May 2018, 23:42
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20489
Location: In your JS exploiting you and your system
revolution 19 May 2018, 00:45
  • call is a native CPU instruction in x86 Intel syntax
  • invoke is a macro that uses pascal calling convention and does an indirect call (i.e. it uses "call [...]")
  • stdcall is a macro that uses pascal calling convention and does a direct call (i.e. it uses "call ...")
  • cinvoke is a macro that uses C-call convention and and does an indirect call (i.e. it uses "call [...]")
  • ccall is a macro that uses C-call convention and and does a direct call (i.e. it uses "call ...")
  • Use call if you need just the native CPU instruction
  • Use invoke to call all Windows APIs (except wsprintf) and all DLL functions that use pascal convention
  • Use stdcall to call functions you have defined with the proc macro
  • Use cinvoke to call the Windows wsprintf API and all DLL functions that use C-call convention (e.g. MSVCRT)
  • Use ccall to call functions you have statically linked that use the C-call convention and functions you have defined with "proc <func> c ..."
Post 19 May 2018, 00:45
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 19 May 2018, 09:36
Thanks, I understand much better Smile However, how could I have my program deduce which instruction to use?
Because between printf and foo, only the name changes...
Post 19 May 2018, 09:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20489
Location: In your JS exploiting you and your system
revolution 19 May 2018, 10:07
The only instruction there is call. All the others are macros.

Normally an HLL compiler will only generate native instructions, so probably you will only want to use call and implement the calling convention using native push/mov/pop/add etc.
Post 19 May 2018, 10:07
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 19 May 2018, 10:45
Okay, thanks a lot Wink I will use call in this cas.
Post 19 May 2018, 10:45
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.