Would it be possible to create macros that could be used with real numbers the same way .IF etc are used with integers? Maybe someone has made such macros already?

With simple conditions, and using FCOMI instruction (which sets ZF, PF, and CF in the EFLAGS directly) things are fairly simple. But when conditions get complex, it would be really nice to have ".IF"-syntax for FPU, too.

Actually, I guess that even better would be if .IF etc. themselves could be enhanced so, that both real and integer variables could be used in the same conditional statement.
Posted on 2003-03-25 15:42:30 by Janne
The main potential problem with such a programming approach is the restricted use of the FPU registers. You must insure that an FPU register must be "empty" before using it, and only 8 registers are available.

Proper FPU programming must therefore keep close track of the number of registers in use at all times. Branching after testing the content of a register must often take into account if the register(s) involved in the test must be cleared or retained for further processing.

Ordinary IF statements are not designed to handle this. In theory, you could probably create a complex FPUIF macro to handle those tests (or comparisons, or whatever) but you would have to give directions on how to handle the registers.

IMHO your code would be a lot clearer if you handle each case separately, using FPU instructions for the tests followed with the IF statement on the result of the test, and cleaning up the FPU stack as necessary.

If you need guidance on performing the tests with FPU instructions, you can look at the source code of the functions provided in the FPU.lib library available in the MASM32v8 package. If you want to invoke the functions without programming the FPU yourself, the associated Help file should be studied.

(If you would like the FPU.lib package without the entire MASM32v8 package, you can get the latest version from the FPU.lib Update thread of the MASM32 forum.)

Raymond
Posted on 2003-03-25 19:30:38 by Raymond
...or you could go code in a highlevel language ;-)
Posted on 2003-03-26 02:27:01 by f0dder