Assembler Developer

Moderators: None (Apply to moderate this forum)
Number of threads: 819
Number of posts: 1580

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
force specific calling convention on C Posted by guyenph on 27 Dec 2009 at 8:18 PM
Hi guys, I am developing bootloader and met with a need to force C compiler to output the calling function in a specific way.

Due to program requirement, I am passing function parameter to function called ProcName function from code segment like following:
I am also declaring all functions far.

jmp skipData
param1 db 00h, 001h

skipData:
push cs
push offset word ptr cs:param1 ; pushed seg:ofs address of param1
push cs
push offset word ptr cs:retAddr ; pushed return address.
dw eah
dw ProcName
dw CS_SEG ; far jump to CS_SEG:ProcName

retAddr:

ProcName PROC FAR

Now the problem is I declare ProcName in C file and calling ProcName function from C like following way:

extern void far ProcName(char far *);
.....
ProcName("12345");

Problem is it is not working because, C compiler compiles it as follows:
push ds
push offset word ptr ds:paramInC

because string '12345' is created in data segment. But upon program entry I am using ds for something else not for DATA segment.

Finally the question is is there way to force C compiler to create 12345 string in code segment and pass CS and OFFSET CS:12345 to ProcName. Thanks!




Report
Re: force specific calling convention on C Posted by shaolin007 on 1 Mar 2010 at 1:51 PM
By default, unless you specify the convention, the compiler will probably default to __cdecl?

extern void far ProcName(char far *);

is probably defaulting to

extern void __cdecl far ProcName(char far *);


I think you might be wanting to do this if your compiler supports it.

Naked function calls

http://msdn.microsoft.com/en-us/library/5ekezyy2%28VS.71%29.aspx



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.