FIX: Bad Code Generated for Inline Assembly Using Enumerators

Last reviewed: September 19, 1997
Article ID: Q149696
4.10 WINDOWS NT kbprg kbbuglist kbfixlist

The information in this article applies to:

  • Microsoft Visual C++, 32-bit Edition, versions 4.1

SYMPTOMS

When you use an enumerator in an inline assembly statement, incorrect code will be generated for the enumerator value. The following code fragment demonstrates the problem:

   void main()
   {
   enum { FALL=1, WINTER, SPRING, SUMMER };

   _asm {
        mov eax, WINTER  ; <--- This will incorrectly load 'eax'
                          ;      with something other than 2.
        }
   }

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 32- bit Edition version 4.2.

MORE INFORMATION

This problem will impact developers that are using the Microsoft Windows 95 Device Driver Kit (DDK) or other tools that are used to build VXD drivers with C/C++. The DDK provides C/C++ header files that use enumerators and inline assembly in this fashion.

There are no workarounds for this problem. The following are possible alternatives if the developer is at liberty to modify the source code:

   void main()
   {

   #define FALL   1
   #define WINTER 2
   #define SPRING 3
   #define SUMMER 4

   _asm {
        mov eax, WINTER
        }
   }

The drawback to the #define directive method is that it has no scope. Another method that does have scope is this:

   void main()
   {

   const int FALL   = 1,
             WINTER = 2,
             SPRING = 3,
             SUMMER = 4;

   _asm {
        mov eax, WINTER
        }
   }


Additional reference words: 4.10 10.10 4.20 10.20 vcbuglist410 vcfixlist420
KBCategory: kbprg kbbuglist kbfixlist
KBSubcategory: InLineAsmIss

Keywords : InLineAsmIss kbbuglist kbfixlist kbprg
Version : 4.10
Platform : NT 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 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.