[fpc-devel] Strange assembler from 2.7.1

Martin lazarus at mfriebe.de
Thu Sep 6 23:27:29 CEST 2012


On 06/09/2012 22:18, Jonas Maebe wrote:
> On 06 Sep 2012, at 23:00, Martin wrote:
>
>> Stopping in the disassemble view (using asm single stepping) the point in classes had the below asm:
>>
>> CLASSES_POINT$LONGINT$LONGINT$$TPOINT
>> 0010BAF0 83ec0c                   sub    $0xc,%esp
>> 0010BAF3 890424                   mov    %eax,(%esp)
>> 0010BAF6 89542404                 mov    %edx,0x4(%esp)
>> 0010BAFA 8b0424                   mov    (%esp),%eax
>> 0010BAFD 8b542404                 mov    0x4(%esp),%edx
>> 0010BB01 83c40c                   add    $0xc,%esp
>> 0010BB04 c3                       ret
>>
>> I don't have the exact copy of the asm for the case where the function was compiled in a unit outside the RTL, but it used eax,ecx,edx. And eax would be the pointer to the record (result:TPoint). Above the result is at -12(esp)
>>
>> For now, my question is: What settings could get fpc to generate the above code?
> It's the default setting on Darwin/i386 and iPhoneSim/i386, because that's how its ABI prescribes that small records should be returned. Apparently there's a check for cdecl/cppdecl/mwpascal missing in the parameter manager for that platform, although until now nobody noticed.
>
> All those custom calling conventions on i386 are a real pain, especially on platforms where they have absolutely no use or right of existence other than the fact that everyone and their uncle insists on writing inline assembler code in when programming in FPC/Delphi/TP.
>

Ok.

Then my next question.

As indicated, compiling a copy and paste of this code, using the same 
compiler, it produced asm using eax as pointer to the result.

Is that possible or allowed? If so how?

And if so then how would
   type TPointProc =  function(AX, AY: Integer): TPoint;
work?

If dereferenced any were in code
   SomePointProc(1,1);
how would it know which calling convention (if there are 2 to choose from)





More information about the fpc-devel mailing list