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.

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

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

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.

Once again, thank you for the resources. Appreciations.

maybe there was a way i could too

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

Raymond

My favourite on this line is: "no job is impossible when you make someone else do it" :D

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

Donkey

Hm, not present here - XP SP2.

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.

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.

I think NASM has floating-point emulation code, by the way - so you might want to take a look at that.

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.