DevlogsDevlogs
Borland Delphi is using pascal calling convention, that means arguments are passed from left to right. this rule works also when arguments are record types. then passing (using call-by-value) record type parameters to functions, pointers to variables related with arguments are stored in EAX (for the first parameter), EDX (the second one) and ECX (for third one). using them we can read record fields in order they have been defined. as we can see Delphi uses registers rather then stack, this is because by default all routines in delphi uses register call convention. to force using stack we need to use pascal calling convention. the only differance is how parameters are passed to function.
for example lets define type
Ttest=record i, j, k : real; end;
and use it as a parameter in procedure illustrates
procedure test _fnc( t :Ttest); assembler; asm fld qword ptr [eax] // this is value of t.i fld qword ptr [eax+8h] // this is value of t.j fld qword ptr [eax+10h] // this is value of t.k ... end;
where qword ptr means pointer to 8 byte value, because size of real type is 8 bytes.
But using Borland C++ Builder everything is different. all because of different calling convention. when calling function with parameters defined as structures all structure fields are placed in EBP. precisely they are stored in ESP register, but when function is called it pushes EBP register and moves ESP to EBP.
for example lets define struct like in previous example
typedef struct __ttest
{
float i,j,k;
} test;
and function that illustrates using stack to pass data to function
void test _fnc( ttest z )
{
asm
{
fld dword ptr [ebp+8h] // z.i
fld dword ptr [ebp+0ch] // z.j
fld dword ptr [ebp+10h] // z.k
};
};
In that case [EBP] stores old value of EBP register and return adress is stored in [EBP+04h].
Using this we can easily implement complex arithmetics (more) for delphi and c++ builder using inline assembly routines. but how about VC++ compiler ?... the same as above :]
read more about delphi inline assembly http://info.borland.com/techpubs/delphi/delphi5/oplg/assemblr.html
No comments as yet. Be first to comment.