Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Re: Function ca...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 8 Topic 3722 of 3900
Post > Topic >>

Re: Function calling convention for large return values ?

by "Skybuck Flying" <BloodyShame@[EMAIL PROTECTED] > May 2, 2008 at 07:23 AM

Delphi definetly does something special:

Project1.dpr.95: vLarge := ExamineLargeReturnValue;
004091A5 8BC4             mov eax,esp
004091A7 E880FFFFFF       call ExamineLargeReturnValue
Project1.dpr.96: for vIndex := 0 to 31 do
004091AC BE20000000       mov esi,$00000020
004091B1 8BDC             mov ebx,esp
Project1.dpr.98: writeln( vLarge.mByte[vIndex] );
004091B3 0FB613           movzx edx,[ebx]
004091B6 8BC7             mov eax,edi
004091B8 E87BA5FFFF       call @[EMAIL PROTECTED]
 E8AEA5FFFF       call @[EMAIL PROTECTED]
 E8159CFFFF       call @[EMAIL PROTECTED]
 functions it seems to be efficient, this is misleading though.

I am pretty sure for properties it does something different and
inefficient 
yet again ;)

At least last time I used a property for a large type it was hellish slow
;)

Or maybe the assignments caused it, someday I will investigate but not
today 
:P*

// *** Begin of Code  ***

program Project1;

{$APPTYPE CONSOLE}

{

Test Delphi's calling convention

version 0.01 created on 2 may 2008 by Skybuck Flying.

According to Wikipedia:

Evaluating arguments from left to right,
it p***** three arguments via EAX, EDX, ECX.
Remaining arguments are pushed onto the stack, also left to right.
It's the default calling convention of Borland Delphi.

What it doesn't say is how arguments are returned...

Well for now assume eax... but what if the arguments are bigger than a 
longword ;)

What happens when bytes are in the parameters will 4 bytes on the stack
be used or just 1 ?

Let's find out ! ;)

}


uses
 SysUtils;

function ExamineLongwordParameters
(
 Para1 : longword;
 Para2 : longword;
 Para3 : longword;
 Para4 : longword;
 Para5 : longword;
 Para6 : longword;
 Para7 : longword;
 Para8 : longword
) : boolean;
begin
 writeln( IntToHex(Para1,4) );
 writeln( Para2 );
 writeln( Para3 );
 writeln( Para4 );
 writeln( Para5 );
 writeln( Para6 );
 writeln( Para7 );
 writeln( Para8 );

 result := true;
end;

type
 Tlarge = packed record
  mByte : packed array[0..31] of byte;
 end;


function ExamineLargeReturnValue : Tlarge;
var
 vIndex : integer;
begin
 for vIndex := 0 to 31 do
 begin
  result.mByte[vIndex] := vIndex;
 end;
end;

procedure Main;
var
 vIndex : integer;
 vLarge : Tlarge;
begin
 writeln('program started');

 if ExamineLongwordParameters
 (
  $AABBCCAA, // eax
  $AABBCCBB, // edx
  $AABBCCCC, // ecx
  $AABBCCDD, // stack
  $AABBCCEE, // stack
  $AABBCCFF, // stack
  $AABBCC00, // stack
  $AABBCC11  // stack
 ) then
 begin
  writeln('true');
 end;

 vLarge := ExamineLargeReturnValue;
 for vIndex := 0 to 31 do
 begin
  writeln( vLarge.mByte[vIndex] );
 end;

 writeln('program finished');
end;

begin
 try
  Main;
 except
  on E:Exception do
   Writeln(E.Classname, ': ', E.Message);
 end;
 readln;
end.

// *** End of Code  ***

Bye,
  Skybuck.
 




 8 Posts in Topic:
Function calling convention for large return values ?
"Skybuck Flying"  2008-05-02 07:13:19 
Re: Function calling convention for large return values ?
"Skybuck Flying"  2008-05-02 07:23:35 
Re: Function calling convention for large return values ?
"Skybuck Flying"  2008-05-02 07:30:33 
Re: Function calling convention for large return values ?
"Skybuck Flying"  2008-05-02 07:42:51 
Re: Function calling convention for large return values ?
"Skybuck Flying"  2008-05-02 09:36:22 
Re: Function calling convention for large return values ?
Ivan Levashew <octagra  2008-05-04 04:25:06 
Re: Function calling convention for large return values ?
Terence <tbwright@[EMA  2008-05-03 16:01:07 
Re: Function calling convention for large return values ?
Terence <tbwright@[EMA  2008-05-03 18:42:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 22:28:58 CDT 2008.