FIX: Bad Code Generated for 'loop' When Using OptimizationsLast reviewed: September 18, 1997Article ID: Q113677 |
1.00
WINDOWS
kbtool kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSWhen you use the loop instruction in inline assembly and are enabling optimizations, the C/C++ compiler will generate incorrect code. When the code is run it will produce random run-time errors or possibly hang the machine. This problem can be reproduced by compiling and running the sample code shown below.
RESOLUTIONTo work around the problem, do one of the following:
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed above. This problem was corrected in Visual C++ version 1.5.
Sample Code
/* Compile options needed: any /O options (excluding /Od and /Oo-) */ #include <stdio.h> #define COUNT 2 /* Uncomment this #pragma to turn off optimizations and correct the problem:#pragma optimize( "", off ) */ void main(){ __asm mov cx, COUNT mylabel: __asm { ; ; various assembly instructions ; loop mylabel ; remove the loop instruction above and uncomment ; the lines below to correct the problem ;dec cx ;jnz mylabel } printf( "Test was successful if no run-time error messages\n" ); printf( "were displayed!\n" );}
/* Uncomment this #pragma to turn optimizations back on:#pragma optimize( "", on ) */ |
Additional reference words: M6111 R6001 8.00 1.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |