[fpc-devel] asm to Object Pascal

Graeme Geldenhuys graemeg.lists at gmail.com
Fri Apr 18 10:07:00 CEST 2008


Hi,

I'm porting a reporting engine from Delphi to Free Pascal. I want to get 
it as cross-platform as possible even though my deployment environment 
is only x86 systems.

There is a function implemented in Assembly language, but I would prefer 
a Object Pascal implementation. From the name I gather it's a math Power 
function, but not 100% sure how to convert it to Pascal. My ASM knoledge 
is non-existent. ;)


Could anybody help port this to Object Pascal, or does RTL or FCL have 
an equivalent function?


function Ipwr(const Base: Double; const Exponent: integer): Double;
begin
   asm
           mov     ecx, eax
           cdq
           fld1                      { Result := 1 }
           xor     eax, edx
           sub     eax, edx          { eax := Abs(Exponent) }
           jz      @@3
           fld     Base
           jmp     @@2
   @@1:    fmul    ST, ST            { X := Base * Base }
   @@2:    shr     eax,1
           jnc     @@1
           fmul    ST(1),ST          { Result := Result * X }
           jnz     @@1
           fstp    st                { pop X from FPU stack }
           cmp     ecx, 0
           jge     @@3
           fld1
           fdivrp                    { Result := 1 / Result }
   @@3:
           fwait
   end;
end;



Regards,
   - Graeme -


_______________________________________________________
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/





More information about the fpc-devel mailing list