- 论坛徽章:
- 39
|
经过VC调试查看反汇编我得出的结论是(只适用VC)
1.++i right to left
i++ left to right
+ right to left
2.vc中先计算 right to left,再计算 left to right
vc中,先计算++i,后计算+
看vc源代码:
#include <stdio.h>
void main()
{
int j3=0,j4=0;
j3 =(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++);
++j4;++j4;++j4;++j4;++j4;++j4;
j4=j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4;
j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;
printf("j3 = %d\n",j3);
printf("j4 = %d\n",j4);
}//j3,j4的结果都是120
对比j3,j4,汇编完全一样
j3 =(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++)+(j3++)+(++j3)+(j3++);
004114D0 mov eax,dword ptr [j3]
004114D3 add eax,1
004114D6 mov dword ptr [j3],eax
004114D9 mov ecx,dword ptr [j3]
004114DC add ecx,1
004114DF mov dword ptr [j3],ecx
004114E2 mov edx,dword ptr [j3]
004114E5 add edx,1
004114E8 mov dword ptr [j3],edx
004114EB mov eax,dword ptr [j3]
004114EE add eax,1
004114F1 mov dword ptr [j3],eax
004114F4 mov ecx,dword ptr [j3]
004114F7 add ecx,1
004114FA mov dword ptr [j3],ecx
004114FD mov edx,dword ptr [j3]
00411500 add edx,1
00411503 mov dword ptr [j3],edx
00411506 mov eax,dword ptr [j3]
00411509 add eax,dword ptr [j3]
0041150C add eax,dword ptr [j3]
0041150F add eax,dword ptr [j3]
00411512 add eax,dword ptr [j3]
00411515 add eax,dword ptr [j3]
00411518 add eax,dword ptr [j3]
0041151B add eax,dword ptr [j3]
0041151E add eax,dword ptr [j3]
00411521 add eax,dword ptr [j3]
00411524 add eax,dword ptr [j3]
00411527 add eax,dword ptr [j3]
0041152A add eax,dword ptr [j3]
0041152D add eax,dword ptr [j3]
00411530 add eax,dword ptr [j3]
00411533 add eax,dword ptr [j3]
00411536 add eax,dword ptr [j3]
00411539 add eax,dword ptr [j3]
0041153C mov dword ptr [j3],eax
0041153F mov ecx,dword ptr [j3]
00411542 add ecx,1
00411545 mov dword ptr [j3],ecx
00411548 mov edx,dword ptr [j3]
0041154B add edx,1
0041154E mov dword ptr [j3],edx
00411551 mov eax,dword ptr [j3]
00411554 add eax,1
00411557 mov dword ptr [j3],eax
0041155A mov ecx,dword ptr [j3]
0041155D add ecx,1
00411560 mov dword ptr [j3],ecx
00411563 mov edx,dword ptr [j3]
00411566 add edx,1
00411569 mov dword ptr [j3],edx
0041156C mov eax,dword ptr [j3]
0041156F add eax,1
00411572 mov dword ptr [j3],eax
00411575 mov ecx,dword ptr [j3]
00411578 add ecx,1
0041157B mov dword ptr [j3],ecx
0041157E mov edx,dword ptr [j3]
00411581 add edx,1
00411584 mov dword ptr [j3],edx
00411587 mov eax,dword ptr [j3]
0041158A add eax,1
0041158D mov dword ptr [j3],eax
00411590 mov ecx,dword ptr [j3]
00411593 add ecx,1
00411596 mov dword ptr [j3],ecx
00411599 mov edx,dword ptr [j3]
0041159C add edx,1
0041159F mov dword ptr [j3],edx
004115A2 mov eax,dword ptr [j3]
004115A5 add eax,1
004115A8 mov dword ptr [j3],eax
==================================================================================================
++j4;++j4;++j4;++j4;++j4;++j4;
004115AB mov eax,dword ptr [j4]
004115AE add eax,1
004115B1 mov dword ptr [j4],eax
004115B4 mov eax,dword ptr [j4]
004115B7 add eax,1
004115BA mov dword ptr [j4],eax
004115BD mov eax,dword ptr [j4]
004115C0 add eax,1
004115C3 mov dword ptr [j4],eax
004115C6 mov eax,dword ptr [j4]
004115C9 add eax,1
004115CC mov dword ptr [j4],eax
004115CF mov eax,dword ptr [j4]
004115D2 add eax,1
004115D5 mov dword ptr [j4],eax
004115D8 mov eax,dword ptr [j4]
004115DB add eax,1
004115DE mov dword ptr [j4],eax
j4=j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4+j4;
004115E1 mov eax,dword ptr [j4]
004115E4 add eax,dword ptr [j4]
004115E7 add eax,dword ptr [j4]
004115EA add eax,dword ptr [j4]
004115ED add eax,dword ptr [j4]
004115F0 add eax,dword ptr [j4]
004115F3 add eax,dword ptr [j4]
004115F6 add eax,dword ptr [j4]
004115F9 add eax,dword ptr [j4]
004115FC add eax,dword ptr [j4]
004115FF add eax,dword ptr [j4]
00411602 add eax,dword ptr [j4]
00411605 add eax,dword ptr [j4]
00411608 add eax,dword ptr [j4]
0041160B add eax,dword ptr [j4]
0041160E add eax,dword ptr [j4]
00411611 add eax,dword ptr [j4]
00411614 add eax,dword ptr [j4]
00411617 mov dword ptr [j4],eax
j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;j4++;
0041161A mov eax,dword ptr [j4]
0041161D add eax,1
00411620 mov dword ptr [j4],eax
00411623 mov eax,dword ptr [j4]
00411626 add eax,1
00411629 mov dword ptr [j4],eax
0041162C mov eax,dword ptr [j4]
0041162F add eax,1
00411632 mov dword ptr [j4],eax
00411635 mov eax,dword ptr [j4]
00411638 add eax,1
0041163B mov dword ptr [j4],eax
0041163E mov eax,dword ptr [j4]
00411641 add eax,1
00411644 mov dword ptr [j4],eax
00411647 mov eax,dword ptr [j4]
0041164A add eax,1
0041164D mov dword ptr [j4],eax
00411650 mov eax,dword ptr [j4]
00411653 add eax,1
00411656 mov dword ptr [j4],eax
00411659 mov eax,dword ptr [j4]
0041165C add eax,1
0041165F mov dword ptr [j4],eax
00411662 mov eax,dword ptr [j4]
00411665 add eax,1
00411668 mov dword ptr [j4],eax
0041166B mov eax,dword ptr [j4]
0041166E add eax,1
00411671 mov dword ptr [j4],eax
00411674 mov eax,dword ptr [j4]
00411677 add eax,1
0041167A mov dword ptr [j4],eax
0041167D mov eax,dword ptr [j4]
00411680 add eax,1
00411683 mov dword ptr [j4],eax
[ 本帖最后由 rover12421 于 2010-1-6 13:30 编辑 ] |
|