Math display in Delphi
We easiest way to display mathematical equations in Delphi (this solution will also work with any Windows application). the idea is to use TEX math syntax and mimeTEX application. all we have to do now is to call mimeTEX from Delphi with consol output redirected back to our application and display returned image. to display gif images in Delphi we can use - this component by Finn Tolderlund. whole procedure (quick and dirty can look like this) [read more]
Borland inline assembler - once again
and one again about assembler, well about inline assembly language. below we can see differences between pascal and c calling conventions:

ttest test _fnc( ttest z )it will be interpreted as if it was defined as
void test_fnc( ttest *result_ptr, ttest z )so now first argument of function isnt stored under [EBP+08h], where now is placed pointer to return value. pointer is 4bytes long so first argument can be found under [EBP+0ch]. to set up return structure, we will need to use pointer stored in [EBP+08h] to get to the return structure.
if we define the same function in delphi
function test_fnc( z : ttest) : ttestdelphi compiler will treat that function as a procedure of type
procedure test_fnc( z:ttest; var result:ttest )in this case argument of our function will be pointed by EAX register, as we can see result structure of our function is treated as a second argument and EDX register points to it. so if we want to set up result value using assebler, we will just need to use EDX register.
Boland Delphi and C++ Builder inline assembler
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
1