Does anybody here have a background in implementing software emulated floating point arithmetic just like what the Pascal programming language does? Unfortunately, debugging the Pascal generated code for the floating point related arithmetic is rather difficult so i thought maybe one of you could give me a head start.
Posted on 2006-09-27 09:27:13 by XCHG
I would guess that your reason for doing this is like climbing a mountain - because it's there!!

There are numerous ways you could implement such an emulator.  The easiest would probably be to use the same IEEE format as the usual 32-bit floats. If you have a sound understanding of that format and a good math background, you can then extract the sign, exponent and mantissa, perform whatever operation(s) is necessary with integer instructions and convert the result back to the proper format. You would then be limited to the range and precision of single precision floats.

If you need more range and/or precision, you will need to develop some good algos for 64-bit math on a 32-bit processor.

If lower range and precision is sufficient, you could go with fixed point math.

If necessary, you can get a good description of the IEEE floating point format in the FPU tutorial from:
http://www.ray.masmcode.com/fpu.html

and some ideas for fixed point math from:
http://www.ray.masmcode.com/fixmath.html

Have fun.

Raymond
Posted on 2006-09-27 21:02:58 by Raymond
Hi raymond. First off, thanks for the tutorials, they really helped. Second, the reason i was looking to implement the emulated version of floating point arithmetic was just curiosity to see how Pascal was handling it. Another motivation for doing so is to implement a library for an 8-bit microprocessor a friend of mine is working on. He asked me if there was a way we could perform such calculation without having an FPU attached and i thought if Borland has done it, maybe there was a way i could too.

Once again, thank you for the resources. Appreciations.
Posted on 2006-09-29 04:21:35 by XCHG
maybe there was a way i could too

Remember the old saying: "When there's a will, there's a way"

Raymond
Posted on 2006-09-29 10:58:46 by Raymond

My favourite on this line is: "no job is impossible when you make someone else do it"  :D
Posted on 2006-10-01 04:03:43 by Maverick
NTDLL.DLL contains the complete FPU instruction set emulator and can be called from an assembly language program, note that you must initialize the FPU emulator by calling eEmulatorInit first then prefixing the FPU instuctions with __e for example _eFADD would replace FADD. Never had occasion to use the functions but they are there to replace the FPU if it is one of the defective versions.

Donkey
Posted on 2006-10-01 13:06:05 by donkey
Hm, not present here - XP SP2.
Posted on 2006-10-01 14:58:53 by f0dder
Never use XP, just 2K for my dev box, the list of exported stubs is detailed here

http://www.koders.com/c/fid34FB386E49098BFF826BBE5F4F0F868ADC20A04F.aspx

Might take a shot at REing the functions in order to try them if I get the time and the patience to do it.
Posted on 2006-10-01 17:06:39 by donkey
I think NASM has floating-point emulation code, by the way - so you might want to take a look at that.
Posted on 2006-10-01 18:03:54 by f0dder
Starting right off on an 8-bit microprocessor as the first experience on implementing such library would be a pain in the neck i guess so I'm better off coding one at least for 8086. Thanks guys for all the links and information. I appreciate it.
Posted on 2006-10-04 00:21:12 by XCHG