Patches of Floating-Point Instructions at Run Time Normal

Last reviewed: July 17, 1997
Article ID: Q42762
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                      | WINDOWS
kbprg kbfasttip

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

In the above Microsoft C versions, memory overwrites occur in the library routine i8_input. While debugging the program under CodeView with the assembler listing, you may notice that after executing into the code, the first 2 bytes of each instruction beginning with a hex CD are overwritten. The C statement that generated the assembler code with the problem in it was an fscanf() function call.

Below is an listing example of what is occurring:

   Before
   ------

   7E1F:4266 CD35C0       INT 35 ; FLD     ST(0)
   7E1F:4269 CD35E1       INT 35 ; FABS
   7E1F:426C CD372E7425   INT 37 ; FLD     TByte Ptr [__chbuf+5C (2574)]

   After
   -----

   7E1F:4266 90           NOP
   7E1F:4267 D9C0         FLD      ST(0)
   7E1F:4269 90           NOP
   7E1F:426A D9E1         FABS
   7E1F:426C 90           NOP
   7E1F:426D DB2E7425     FLD      TByte Ptr [__chbuf+5C (2574)]

CAUSE

This behavior is normal. The Microsoft C floating-point package works by generating the INT instructions shown above. When these instructions are executed, the routine they call replaces the INT instructions with either the library calls to the emulator library or the actual 80x87 floating- point instructions, depending on whether or not a coprocessor is installed.

When the instructions are executed again, there is no overhead for determining whether on not a coprocessor is installed; the proper instructions have been patched into place already. This patching occurs even if the -FPi87 option has been selected.

You can force in-line 8087 instructions to be put into your code. For more information about this technique, query on the following words in the Microsoft Knowledge Base:

   in-line 8087 instructions

This code modification occurs only under MS-DOS. Under Windows NT and OS/2, coprocessor instructions (such as in the second listing) are always generated. If a coprocessor is not present, Windows NT will emulate one.

NOTE: Such code modification is impossible under OS/2 because there is no way to dynamically change a code segment under OS/2, although it is possible to cause a data segment to be executed.


Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
patch
KBCategory: kbprg kbfasttip
KBSubcategory: CRTIss
Keywords : CRTIss kb16bitonly kbfasttip kbprg
Version : 5.10 6.00 6.00a 6.00ax 7.00 | 1.
Platform : MS-DOS WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.