FIX: Optimization Removes SS Override from Inline Assembly

Last reviewed: September 18, 1997
Article ID: Q115536
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

If optimizations are used, the version 8.0 C/C++ compiler may remove the use of the stack segment register (SS) override in a pointer reference in an inline assembly block.

RESOLUTION

To get around this problem, do one of the following:

  • Disable optimization using the /Od compiler switch.

    -or-

  • Use the fast compiler option, /f.

    -or-

  • Disable optimization during the function where the problem occurs, using #pragma optimize before and after the function.

    -or-

  • In the case of the sample code (in the "MORE INFORMATION" section, below), remove the line of code before the assembly block to allow the compiler to also generate correct code.

STATUS

Microsoft has confirmed this to be a problem with the C/C++ compiler version 8.0. The problem was corrected in C/C++, version 8.0c, included with Visual C++ for Windows, version 1.5.

MORE INFORMATION

The sample code below can be used to reproduce the problem. Use the /Fc compiler option to generate a source/assembly listing of the code.

Sample Code

/* Compile options needed: /c /Ox (or any optimization)
*/
      unsigned char tbl[256];

      static void Bug(unsigned char _far *Font, unsigned char c)
      {
         unsigned char _far *font_data = Font + c*33;

         __asm
         {
            push ds
            mov al, byte ptr ss:[bx]
            mov bl, es:[di]
         }
      }

      main()
      {
         Bug((unsigned char _far *)0, 0);
      }


Additional reference words: 8.00 1.00
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.