设 i = 5
mov
eax,dword ptr [i]
eax = 5
add
eax,1
// ++i
eax = 6
mov
dword ptr [i],eax
i = 6
mov
ecx,dword ptr [i]
ecx = 6
sub
ecx,1
// --i
ecx = 5
mov
dword ptr [i],ecx
i = 5
mov
edx,dword ptr [i]
edx = 5
imul
edx,dword ptr [i] // i*i
edx = 25
mov
eax,dword ptr [i]
eax = 5
imul
eax,dword ptr [i] // i*i
eax = 25
add
eax,edx
// i + i
eax = 50
mov
dword ptr [i],eax
i = 50
mov
ecx,dword ptr [i]
ecx = 50
sub
ecx,1
// i--
ecx = 49
mov
dword ptr [i],ecx
i = 49
mov
edx,dword ptr [i]
edx = 49
add
edx,1
// i++
edx = 50
mov
dword ptr [i],edx
i = 50
上面是那句代码在调试时的反汇编后的代码,可以看出顺序如下:
先计算两个前置运算( ++i ,
--i),这之后,i的值不变;
然后计算乘法运算
i*i
然后计算加法运算
i*i + i*i
最后计算后置运算符( i-- , i++ ),这样 i的值还是没变