<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'force specific calling convention on C' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'force specific calling convention on C' posted on the 'Assembler Developer' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:13:15 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:13:15 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>force specific calling convention on C</title>
      <link>http://www.programmersheaven.com/mb/pharabee/411270/411270/force-specific-calling-convention-on-c/</link>
      <description>Hi guys, I am developing bootloader and met with a need to force C compiler to output the calling function in a specific way.&lt;br /&gt;
    &lt;br /&gt;
Due to program requirement, I am passing function parameter to function called ProcName function from code segment like following:&lt;br /&gt;
I am also declaring all functions far.&lt;br /&gt;
    &lt;br /&gt;
    jmp skipData&lt;br /&gt;
param1 db 00h, 001h    &lt;br /&gt;
&lt;br /&gt;
skipData:&lt;br /&gt;
    push cs&lt;br /&gt;
    push offset word ptr cs:param1   ; pushed seg:ofs address of param1&lt;br /&gt;
    push cs&lt;br /&gt;
    push offset word ptr cs:retAddr  ; pushed return address.&lt;br /&gt;
    dw eah&lt;br /&gt;
    dw ProcName&lt;br /&gt;
    dw CS_SEG                        ; far jump to CS_SEG:ProcName&lt;br /&gt;
&lt;br /&gt;
retAddr:&lt;br /&gt;
&lt;br /&gt;
ProcName PROC FAR&lt;br /&gt;
&lt;br /&gt;
Now the problem is I declare ProcName in C file and calling ProcName function from C like following way:&lt;br /&gt;
&lt;br /&gt;
extern void far ProcName(char far *);&lt;br /&gt;
.....&lt;br /&gt;
ProcName("12345");&lt;br /&gt;
&lt;br /&gt;
Problem is it is not working because, C compiler compiles it as follows:&lt;br /&gt;
push ds&lt;br /&gt;
push offset word ptr ds:paramInC&lt;br /&gt;
&lt;br /&gt;
because string '12345' is created in data segment. But upon program entry I am using ds for something else not for DATA segment. &lt;br /&gt;
&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pharabee/411270/411270/force-specific-calling-convention-on-c/</guid>
      <pubDate>Sun, 27 Dec 2009 20:18:51 -0700</pubDate>
      <category>Assembler Developer</category>
    </item>
    <item>
      <title>Re: force specific calling convention on C</title>
      <link>http://www.programmersheaven.com/mb/pharabee/411270/414077/re-force-specific-calling-convention-on-c/#414077</link>
      <description>By default, unless you specify the convention, the compiler will probably default to __cdecl? &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;extern void far ProcName(char far *);
&lt;/pre&gt;&lt;br /&gt;
is probably defaulting to &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;extern void __cdecl far ProcName(char far *);
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I think you might be wanting to do this if your compiler supports it.&lt;br /&gt;
&lt;br /&gt;
Naked function calls&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/5ekezyy2%28VS.71%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/5ekezyy2%28VS.71%29.aspx&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pharabee/411270/414077/re-force-specific-calling-convention-on-c/#414077</guid>
      <pubDate>Mon, 01 Mar 2010 13:51:49 -0700</pubDate>
      <category>Assembler Developer</category>
    </item>
  </channel>
</rss>
