flat assembler
Message board for the users of flat assembler.

flat assembler > 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
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: 3490
Location: Bulgaria
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
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: 3490
Location: Bulgaria
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: 4634
Location: Argentina
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
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: 678
Location: Mar del Plata
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
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
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-2018, Tomasz Grysztar.

Powered by rwasa.