[fpc-pascal]Default calling convention
Marcel Martin
mm10 at ellipsa.net
Fri Jul 2 01:08:34 CEST 2004
Marco van de Voort wrote:
> Marcel Martin wrote:
> >
> > I noticed that, with FPC 1.9.4, the (default) calling convention
> > "register" depends on the fact that a routine is or is not embedded
> > in an other routine.
> >
> > With "proc(A,B,C: Longint);", if "proc" is not embedded then
> > eax = A, edx = B and ecx = C but if "proc" is embedded then edx = A,
> > ecx = B and C is on the stack.
> >
> > Is this convention definitive or temporary? I am not sure it is
> > definitive since it makes the code of assembler routines dependent
> > on their status: embedded or not.
> In general it is not wise anyway to let the assembler become to dependant
> on calling convention.
> Keep on using
> mov eax,param1
> mov ecx,param2
> etc. Clearer, and doesn't have the problem between procedure/methods/nested
> procedures.
I agree with you but it doesn't work. For instance, take this
procedure
procedure nx_fill(P: PLongword; Count: Longint; Value: Longword);
assembler;
asm
pushl %edi
movl Value,%eax
movl Count,%ecx
movl P,%edi
rep
stosl
popl %edi
end;
in the .s file, FPC 1.9.4 produces this:
.globl NXKERNEL_NX_FILL$PLONGWORD$LONGINT$LONGWORD
pushl %ebp
movl %esp,%ebp
pushl %edi
movl %ecx,%eax // eax is modified
movl %edx,%ecx
movl %eax,%edi // eax is more equal to P, access violation
rep
stosl
popl %edi
ret
With this one
procedure nx_fill(P: PLongword; Count: Longint; Value: Longword);
assembler;
asm
pushl %edi
movl %eax,%edi // edi <- P
movl %ecx,%eax // eax <- Value
movl %edx,%ecx // ecx <- Count
rep
stosl
popl %edi
end;
the produced code is correct but now this proc can no more be used as a
nested proc.
--
mm
http://www.ellipsa.net/
More information about the fpc-pascal
mailing list