6.3 Using Emulator Libraries

If you do not have a math coprocessor or an 80486 processor, you can do most floating-point operations by writing assembly-language procedures and accessing the emulator from a high-level language. All Microsoft high-level languages come with the emulator library.

However, you cannot use a Microsoft emulator library with stand-alone assembler programs, since the library depends on the high-level-language start-up code.

Summary: With emulator libraries, you can use most floating-point instructions.

To use the emulator, first write the procedure using coprocessor instructions. Then assemble it using the /FPi option of your compiler. Finally, link it with your high-level-language modules. In MASM 6.0 you can enter options in the Programmer's WorkBench (PWB) environment, or you can use the OPTION EMULATOR in your source code.

In emulation mode, the assembler generates instructions for the linker that the Microsoft emulator can use. The form of the OPTION directive in the example below tells the assembler to use emulation mode. This option (introduced in Section 1.3.2) can be defined only once in a module.

OPTION EMULATOR

Emulator libraries do not allow for all of the coprocessor instructions. The following floating-point instructions are not emulated:

FCOSFDECSTPFINCSTPFPREM1FRSTORFRSTOR16FRSTOR32FSAVEFSAVE16FSAVE32FSETPMFSINFSINCOSFUCOMFUCOMPFUCOMPPFXTRACT

The set of emulated instructions is different under OS/2 2.x. If you use a coprocessor instruction that is not emulated, your program generates a run-time error when it tries to execute the unemulated instruction.

See Chapter 20, “Mixed-Language Programming,” for information about writing assembly-language procedures for high-level languages.