Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The arguments are passed similarly in both cases. The difference is that the code generated by Borland expresses the argument locations relative to EBP register and GCC relative to ESP, but both of them refer to the same addresses.</p> <p>Borlands sets EBP to point to the start of the function's stack frame and expresses locations relative to that, while GCC doesn't set up a new stack frame but expresses locations relative to ESP, which the caller has left pointing to the end of the caller's stack frame.</p> <p>The code generated by Borland sets up a stack frame at the beginning of the function, causing EBP in the Borland code to be equal to ESP in the GCC code decreased by 4. This can be seen by looking at the first two Borland lines:</p> <pre><code>push ebp ; decrease esp by 4 mov ebp,esp ; ebp = the original esp decreased by 4 </code></pre> <p>The GCC code doesn't alter ESP and Borland code doesn't alter EBP until the end of the procedure, so the relationsip holds when the arguments are accessed.</p> <p>The calling convention seems to be <a href="https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl" rel="nofollow">cdecl</a> in both of the cases, and there's no difference in how the functions are called. You can add keyword <code>__cdecl</code> to both in order to make that clear.</p> <pre><code> void __cdecl Test_Fn(double *x, size_t n,double *AV, size_t *mA, size_t NT) </code></pre> <p>However adding inline assembly compiled with GCC to the function compiled with Borland is not straightforward, because Borland might set up a stack frame even if the function body contains only inline assembly, causing the value of ESP register to differ from the one used in the GCC code. I see three possible workarounds:</p> <ol> <li>Compile with Borland without the option <a href="http://docwiki.embarcadero.com/RADStudio/XE3/en/C%2B%2B_Compiler" rel="nofollow">"Standard stack frames"</a>. If the compiler figures out that a stack frame is not needed, this might work.</li> <li>Compile with GCC without the option <a href="http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Optimize-Options.html" rel="nofollow">-fomit-frame-pointer</a>. This should make sure that atleast the value of EBP is the same in both. The option is enabled at levels -O, -O2, -O3 and -Os.</li> <li>Manually edit the assembly produced by GCC, changing references to ESP to EBP and adding 4 to the offset.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload