送交者: wasguru 于 2005-6-30, 23:40:03:
回答: Well, nothing is really wrong 由 wasguru 于 2005-6-30, 23:35:15:
Because you specified that register ecx will hold the input value (num>>4), under -O2 the compiler assumes that ecx still holds that value after the asm statement. Also note that (num>>4) is a common subexpression, so the initial value of i is "optimized" to "ecx<< 4", which is zero!
Under -O3 optimization the whole function test() is expanded into inline code, then the argument num becomes a constant 35, and the expression "(num>>4)<< 4" becomes a constant expression. The compiler will preevaluate it into a constant value 32.