Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-04

asm to Object Pascal

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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/

Reply by email

Jonas Maebe
to Graeme Geldenhuys
Graeme Geldenhuys wrote
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. ;)

Use the intpower function from the math unit:

function intpower(base : float;const exponent : Integer) : float;

Jonas

Reply by email

Joost van der Sluis
to Graeme Geldenhuys

Op vrijdag 18-04-2008 om 10:11 uur [tijdzone +0200], schreef Graeme Geldenhuys:

Show quoted text 7 lines
Jonas Maebe wrote: > > Use the intpower function from the math unit: > > function intpower(base : float;const exponent : Integer) : float; Wow, 2 minutes for a reply!! :) Thanks Jonas!

This could mean three things:

a) Jonas is genius and very fast
b) this was a very easy question which you could find out yourself pretty easily
c) Both of the above

;)

Joost.

Reply by email