<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, Calling Convention for External Assembly Code</title>
    <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Thu, 11 Jun 2026 12:40:40 GMT</lastBuildDate>
    <pubDate>Thu, 11 Jun 2026 12:40:40 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, Calling Convention for External Assembly Code</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, Calling Convention for External Assembly Code</title>
      <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code</link>
    </image>
    <item>
      <title>Calling Conventions</title>
      <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code?ref=Feed:MaplePrimes:Calling Convention for External Assembly Code:Comments#answer80640</link>
      <itunes:summary>The manual entry is really meant for users developing external calling code in higher level languages.  On Windows, shared libraries do use different calling conventions.  Therefore we specify which convention (stdcall) must be used for external calling.  In UNIX it is very unlikely that a shared library would not use the default calling convention.  Therefore Maple expects the default C calling convention be used when executing functions via external calling.

Your assembly functions on UNIX should use whatever the standard calling convention is for the platform you are developing on.

You might consider using inline assembly in a C library so that the compiler and linker can take care of the calling conventions.  You can always edit the generated assembly.

Darin

--
Kernel Developer
Maplesoft</itunes:summary>
      <description>The manual entry is really meant for users developing external calling code in higher level languages.  On Windows, shared libraries do use different calling conventions.  Therefore we specify which convention (stdcall) must be used for external calling.  In UNIX it is very unlikely that a shared library would not use the default calling convention.  Therefore Maple expects the default C calling convention be used when executing functions via external calling.

Your assembly functions on UNIX should use whatever the standard calling convention is for the platform you are developing on.

You might consider using inline assembly in a C library so that the compiler and linker can take care of the calling conventions.  You can always edit the generated assembly.

Darin

--
Kernel Developer
Maplesoft</description>
      <guid>80640</guid>
      <pubDate>Wed, 31 Aug 2005 23:58:00 Z</pubDate>
      <itunes:author>dohashi</itunes:author>
      <author>dohashi</author>
    </item>
    <item>
      <title>ret</title>
      <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code?ref=Feed:MaplePrimes:Calling Convention for External Assembly Code:Comments#answer80639</link>
      <itunes:summary>In masm, exit from a procedure with 'ret' cleans the (invisible in the procedure part of the) stack (such as local variables, for example), pushs and pops still have to be balanced in the procedure. Some people don't like that, because it adds a few clocks, and use 'retn' instead - but then they should take care of cleaning stack themselves. It can be done as a part of optimization process, if desirable.  </itunes:summary>
      <description>In masm, exit from a procedure with 'ret' cleans the (invisible in the procedure part of the) stack (such as local variables, for example), pushs and pops still have to be balanced in the procedure. Some people don't like that, because it adds a few clocks, and use 'retn' instead - but then they should take care of cleaning stack themselves. It can be done as a part of optimization process, if desirable.  </description>
      <guid>80639</guid>
      <pubDate>Thu, 01 Sep 2005 01:25:17 Z</pubDate>
      <itunes:author>alec</itunes:author>
      <author>alec</author>
    </item>
    <item>
      <title>multiple emails and question about return address</title>
      <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code?ref=Feed:MaplePrimes:Calling Convention for External Assembly Code:Comments#comment86844</link>
      <itunes:summary>Thanks Alec.  Did you, by the way, edit you response a few times after originally posting it?  I received about three email notifications, at 15:36, 15:39, and 15:41.  I'm just wondering what caused that, or whether it is a bug in the system.

Do you (or anyone) happen to know where the return address is placed on the stack in relation to the arguments?  This could be system-dependent.  It seems to me that if the caller is expected to clean the stack (which I think is the case for Linux), then the return address needs to be pushed on the stack after all the arguments have been.  On the other hand, if the callee is supposed to be doing the cleaning, it is easier if the return address is first pushed onto the stack, followed by the arguments.</itunes:summary>
      <description>Thanks Alec.  Did you, by the way, edit you response a few times after originally posting it?  I received about three email notifications, at 15:36, 15:39, and 15:41.  I'm just wondering what caused that, or whether it is a bug in the system.

Do you (or anyone) happen to know where the return address is placed on the stack in relation to the arguments?  This could be system-dependent.  It seems to me that if the caller is expected to clean the stack (which I think is the case for Linux), then the return address needs to be pushed on the stack after all the arguments have been.  On the other hand, if the callee is supposed to be doing the cleaning, it is easier if the return address is first pushed onto the stack, followed by the arguments.</description>
      <guid>86844</guid>
      <pubDate>Thu, 01 Sep 2005 02:06:35 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>Return address</title>
      <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code?ref=Feed:MaplePrimes:Calling Convention for External Assembly Code:Comments#comment90250</link>
      <itunes:summary>AFAIK, the standard positioning of the return address is between parameters and local variables, as in &lt;a href="http://pandonia.canberra.edu.au/OS/l14_1.html"&gt;this picture&lt;/a&gt;.

You could try to test a couple of simple procedures. First - with no arguments at all - just move something to the accumulator and see if it returns in Maple. Then - with 1 argument (and return something like that argument + 1). That should clarify some things. The worst thing that could happen - Maple's kernel shuts down, and it is not such a big deal. By the way, the object files in the zip files with my assembly examples, are in the COFF format, so they can be used directly in Linux for creating so files. If you used nasm instead of gas, masm source code also could be used practically without changes (or with a very slight ones). That's what I would do. 

Yes, I edited the post couple times - adding some comments in parentheses. 

</itunes:summary>
      <description>AFAIK, the standard positioning of the return address is between parameters and local variables, as in &lt;a href="http://pandonia.canberra.edu.au/OS/l14_1.html"&gt;this picture&lt;/a&gt;.

You could try to test a couple of simple procedures. First - with no arguments at all - just move something to the accumulator and see if it returns in Maple. Then - with 1 argument (and return something like that argument + 1). That should clarify some things. The worst thing that could happen - Maple's kernel shuts down, and it is not such a big deal. By the way, the object files in the zip files with my assembly examples, are in the COFF format, so they can be used directly in Linux for creating so files. If you used nasm instead of gas, masm source code also could be used practically without changes (or with a very slight ones). That's what I would do. 

Yes, I edited the post couple times - adding some comments in parentheses. 

</description>
      <guid>90250</guid>
      <pubDate>Thu, 01 Sep 2005 02:21:08 Z</pubDate>
      <itunes:author>Alec Mihailovs</itunes:author>
      <author>Alec Mihailovs</author>
    </item>
    <item>
      <title>assembly is for linux</title>
      <link>http://www.mapleprimes.com/questions/43651-Calling-Convention-For-External-Assembly-Code?ref=Feed:MaplePrimes:Calling Convention for External Assembly Code:Comments#comment86845</link>
      <itunes:summary>I'm writing for Linux.  So if I'm right (questionable) about the standard Linux/UNIX calling convention, then I don't need to pop the arguments off the stack, that will be handled by the code generated by &lt;b&gt;define_external&lt;/b&gt;.  

I was trying to stay away from inline-assembly; this is more a learning project and that seemed one more detail.</itunes:summary>
      <description>I'm writing for Linux.  So if I'm right (questionable) about the standard Linux/UNIX calling convention, then I don't need to pop the arguments off the stack, that will be handled by the code generated by &lt;b&gt;define_external&lt;/b&gt;.  

I was trying to stay away from inline-assembly; this is more a learning project and that seemed one more detail.</description>
      <guid>86845</guid>
      <pubDate>Thu, 01 Sep 2005 00:22:20 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
  </channel>
</rss>