FIX: Incorrect Code Generated in Function That Uses _asm

Last reviewed: September 18, 1997
Article ID: Q114070
1.00 WINDOWS kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with: Microsoft Visual C++ for Windows, version 1.0

SYMPTOMS

Executing a program built from the sample code shown below after compiling with the optimizing compiler causes the program to hang, crash, or generate a General Protection Fault.

CAUSE

The code generated for the return statements in the Test() function contains incorrect JMP instructions.

RESOLUTION

To work around the problem, use the fast compiler instead of the optimizing compiler. Use of the fast compiler can be forced by compiling with the /f switch.

STATUS

Microsoft has confirmed this to be a problem with C/C++ for MS-DOS version 8.0. This problem was corrected with C/C++ for MS-DOS version 8.0c, include with Visual C++ for Windows, version 1.5.

MORE INFORMATION

The incorrect code can be seen by either generating a code listing file with the /Fc compiler option or by running the executable built from the sample code in the CodeView debugger. The code generated for the two return statements in the Test() function specify the wrong displacement for the JMP instructions.

Sample Code

/* Compile options needed: /f-
* * This sample code must also be compiled as a .CPP file.
*/

double Test(const double x, double& dt);

double dub;

void main(void)
{
    Test(0.0, dub);
}

double Test(const double x, double& dt) {

    if(x == 0.0)
        return dt = 1.0;

    double y;

    _asm
    {
        fld x
        fld st(0)
        frndint
        fxch
        fsub st(0),st(1)
        f2xm1
        fld1
        faddp st(1),st(0)
        fscale
        fst st(1)
        fld1
        fdiv st(0),st(1)
        fadd st(2),st(0)
        fsubp st(1),st(0)
        fdivrp st(1),st(0)
        fst y
        fmul st(0),st(0)
        fld1
        fsubrp st(1),st(0)
        les bx,DWORD PTR dt
        fstp QWORD PTR es:[bx]
        fwait
    }

    return y;
}


Additional reference words: 1.00 8.00 inline assembly
KBCategory: kbtool kbfixlist kbbuglist
KBSubcategory: CodeGen
Keywords : CodeGen kb16bitonly kbbuglist kbfixlist kbtool
Version : 1.00
Platform : WINDOWS
Solution Type : kbfix


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: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.