int a = 5;
00064EB8 mov dword ptr [a],5
// a++ = 6;
++a = 6;
00064EBF mov eax,dword ptr [a] // 先把a的值赋给eax
00064EC2 add eax,1 // eax的值为6
00064EC5 mov dword ptr [a],eax // 把eax中的6赋给a
00064EC8 mov dword ptr [a],6 // 再把6赋给a
printf("a is %d \n", a);
00064ECF mov eax,dword ptr [a]
int a = 5;
00C64EB8 mov dword ptr [a],5
// a++ = 6;
++a = 7;
00C64EBF mov eax,dword ptr [a]
00C64EC2 add eax,1
00C64EC5 mov dword ptr [a],eax
00C64EC8 mov dword ptr [a],7
int a = 5;
007E4EB8 mov dword ptr [a],5
++a = 7;
007E4EBF mov eax,dword ptr [a]
007E4EC2 add eax,1
007E4EC5 mov dword ptr [a],eax
007E4EC8 mov dword ptr [a],7
a++;
007E4ECF mov eax,dword ptr [a]
007E4ED2 add eax,1
007E4ED5 mov dword ptr [a],eax
- 利用一个变量观察
- ++a + 1 先加1再进行运算
int a = 5;
00D7176E mov dword ptr [a],5
int b = ++a + 1;
00D71775 mov eax,dword ptr [a]
00D71778 add eax,1
00D7177B mov dword ptr [a],eax
00D7177E mov ecx,dword ptr [a]
00D71781 add ecx,1
00D71784 mov dword ptr [b],ecx
int c = a++ + 1;
00D71787 mov eax,dword ptr [a]
00D7178A add eax,1
00D7178D mov dword ptr [c],eax
00D71790 mov ecx,dword ptr [a]
00D71793 add ecx,1
00D71796 mov dword ptr [a],ecx
int a = 5;
mov dword ptr [a],5
int b = ++a + 2;
// a自加1
mov eax,dword ptr [a] // eax = a = 5
add eax,1 // eax = eax + 1 = 6
mov dword ptr [a],eax // a = eax = 6
// 将a的值6赋给ecx
mov ecx,dword ptr [a] // ecx = a = 6
add ecx,2 // ecx = 8
mov dword ptr [b],ecx // b = ecx = 8
// a = 6
int c = a++ + 2;
mov eax,dword ptr [a] // eax = a = 6
add eax,2 // eax = 8
mov dword ptr [c],eax // c = eax = 8
mov ecx,dword ptr [a]
add ecx,1
mov dword ptr [a],ecx // a = ecx = 7
- 结果
- ++a先把值给寄存器,再返回 a 本身
- a++会产生歧义