flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > An executable with mixed calling convention

Author
Thread Post new topic Reply to topic
Pinczakko



Joined: 02 May 2004
Posts: 34
Location: Takabonerate National Park, Indonesia
Pinczakko 01 Mar 2012, 20:45
Hi guys, I'm not a compiler or assembler developer so pardon me if this sounds silly Confused .

I found this rather weird C-compiled executable at work, but it seems to use mixed calling convention within the generated x86 (16-bit [maybe big-real]) code. What I observed is the calling convention mixed between stdcall and fastcall. I suspect it's generated by Watcom 16-bit compiler (Open Watcom??). Not so sure about it.

Anyone have experience on this? or probably have been working on things like this before.

Well, I didn't have a computer during the DOS 4GW era, so I don't have lots of experience with 16-bit big-real mode or even the "standard" 16-bit mode.

_________________
Human knowledge belongs to the world
Post 01 Mar 2012, 20:45
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 01 Mar 2012, 21:11
Hm, what is the problem with the mixed calling convention? I use it all the time, because of different reasons.
Post 01 Mar 2012, 21:11
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Pinczakko



Joined: 02 May 2004
Posts: 34
Location: Takabonerate National Park, Indonesia
Pinczakko 01 Mar 2012, 21:49
Actually, not a problem. But, I want to know whether 16-bit compiler(s) could emit code with different calling conventions? I have very little exposure to 16 compilers like Watcom C/C++ or Open Watcom.

_________________
Human knowledge belongs to the world
Post 01 Mar 2012, 21:49
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 01 Mar 2012, 22:01
I don't know about C/C++. The code written by me on 16 bit computers was in Turbo Pascal and TASM assembler.
IIRC, both supports different calling conventions.
Post 01 Mar 2012, 22:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Mar 2012, 22:41
Pinczakko wrote:
Actually, not a problem. But, I want to know whether 16-bit compiler(s) could emit code with different calling conventions? I have very little exposure to 16 compilers like Watcom C/C++ or Open Watcom.
Same here, but I can think of a few reasons:
1. The programmer(s) explicitly specified the calling convention for each function (or some of them and the rest established by the compiler by default)
2. The stdcall (not cdelc??) functions are not marked static and therefore the compiler's optimization engine felt free to change the calling convention to an optimal one for the functions that could result beneficial (sure it was exactly fascall and not really a free register-based convention?)
3. Besides using the same logic as in to 2., also some non-static functions were internally duplicated by the compiler to be able to change the convention (this is an available option in cases where the callee and caller are in the same source file)

If the compiler was capable of doing 3 or 2, then in the disassembly you may be missing some functions because they end up inlined even if the programmer(s) didn't specify inline explicitly.
Post 01 Mar 2012, 22:41
View user's profile Send private message Reply with quote
Pinczakko



Joined: 02 May 2004
Posts: 34
Location: Takabonerate National Park, Indonesia
Pinczakko 03 Mar 2012, 18:06
hi,

about 1: Perhaps some of the code I observed are mixed assembly+C. The thing is bx register is sometimes used to pass parameters while in most cases, the parameters are passed via stack. Or is it possible that these "outlier" functions are coded to use __fastcall??

about 2: I can say I'm 90% sure it's stdcall calling convention because mostly the callee cleans-up the stack.

about 3: I see. I have never used such feature so I didn't know it previously. Well, thanks for pointing out Smile.

_________________
Human knowledge belongs to the world
Post 03 Mar 2012, 18:06
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 676
Location: Mar del Plata
Enko 05 Mar 2012, 13:35
Borland C++ Compiler used __fastcall for the VCL(visual component library). Because of the VCL was writen in Delphi Pascal.

So this way, VCL function like TButton1::Clik was __fastcall while the procedure you writen where cdecl. And then, if you called some winapi function, it would be defined as extern stdcall.
Post 05 Mar 2012, 13:35
View user's profile Send private message Reply with quote
Pinczakko



Joined: 02 May 2004
Posts: 34
Location: Takabonerate National Park, Indonesia
Pinczakko 05 Mar 2012, 15:07
Thanks Enko. That's insightful Smile

_________________
Human knowledge belongs to the world
Post 05 Mar 2012, 15:07
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
MarcoV



Joined: 28 Apr 2019
Posts: 7
MarcoV 01 May 2022, 13:27
(I'm necroing here, but I came here by chance via google).

Some 16-bit compilers like Topspeed's 3.x line (having a C/C++, Pascal and Modula2 compiler) could handle custom calling conventions. So you could specify per function if first parameter should go into ax, second into bx, third on the stack and fourth in dx etc.

That is mainly made to optimize (e.g. with an interface to the out port instruction as prime example) or 3rd party libraries with atypical calling conventions.
Post 01 May 2022, 13:27
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2572
Furs 01 May 2022, 16:58
Sounds cool, I wish GCC had something like that builtin without requiring some plugin extension.
Post 01 May 2022, 16:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20460
Location: In your JS exploiting you and your system
revolution 01 May 2022, 22:25
Furs wrote:
Sounds cool, I wish GCC had something like that builtin without requiring some plugin extension.
The GCC devs will complain that it isn't portable.

What is AX on ARM/MIPS?
Post 01 May 2022, 22:25
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2572
Furs 02 May 2022, 12:29
They could just ignore it on another platform; it already has inline asm and that won't even compile in such case. I know what you mean but yeah they're just dumb.
Post 02 May 2022, 12:29
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.