### a++和++a的问题

a++是语句结束后在后加，
++a是先加后计算再语句结束。

1 int k=2;
int val=0;
val=(k++)+(k++);

8: int k=2;
00401028 mov dword ptr [ebp-4],2//// k的地址是dword ptr [ebp-4]
9: int val=0;
0040102F mov dword ptr [ebp-8],0//val的地址是dword ptr [ebp-8]
10: val=(k++)+(k++);
00401036 mov eax,dword ptr [ebp-4]// 把2放入eax中
00401039 add eax,dword ptr [ebp-4]// 把2+2=4放入eax中
0040103C mov dword ptr [ebp-8],eax//把eax中的4移回val中
0040103F mov ecx,dword ptr [ebp-4]
00401042 add ecx,1//
00401045 mov dword ptr [ebp-4],ecx//k地址中的值加1,k=3

00401048 mov edx,dword ptr [ebp-4]
0040104B add edx,1// 寄存器中的值加1,k=4
0040104E mov dword ptr [ebp-4],edx//移回k地址

2. int k=2;
int val=0;
k=(k++)+(k++);

:
8: int k=2;
00401028 mov dword ptr [ebp-4],2//同上
9: int val=0;
0040102F mov dword ptr [ebp-8],0
10: k=(k++)+(k++);
00401036 mov eax,dword ptr [ebp-4]
00401039 add eax,dword ptr [ebp-4] //同上
0040103C mov dword ptr [ebp-4],eax//同上，不同的是计算结果存入k地址k=4
0040103F mov ecx,dword ptr [ebp-4]
00401042 add ecx,1//寄存器中的值加1,
00401045 mov dword ptr [ebp-4],ecx//k=5
00401048 mov edx,dword ptr [ebp-4]
0040104B add edx,1//寄存器中的值加1
0040104E mov dword ptr [ebp-4],edx//k=6

3 int k=2;
int val=0;
val=(++k)+(++k);

8: int k=2;
00401028 mov dword ptr [ebp-4],2// k的地址是dword ptr [ebp-4]
9: int val=0;
0040102F mov dword ptr [ebp-8],0//val的地址是dword ptr [ebp-8]
10: val=(++k)+(++k);//k先加
00401036 mov eax,dword ptr [ebp-4]
00401039 add eax,1//寄存器中的值加1

0040103C mov dword ptr [ebp-4],eax//k=3
0040103F mov ecx,dword ptr [ebp-4]
00401042 add ecx,1//对k地址中的值加1,k=4
00401045 mov dword ptr [ebp-4],ecx
00401048 mov edx,dword ptr [ebp-4]
0040104B add edx,dword ptr [ebp-4]//k+k=8
0040104E mov dword ptr [ebp-8],edx//值移入val地址中val=8

4. int k=2;
int val=0;
k=(++k)+(++k);

8: int k=2;
00401028 mov dword ptr [ebp-4],2
9: int val=0;
0040102F mov dword ptr [ebp-8],0
10: k=(++k)+(++k);
00401036 mov eax,dword ptr [ebp-4]
00401039 add eax,1
0040103C mov dword ptr [ebp-4],eax
0040103F mov ecx,dword ptr [ebp-4]
00401042 add ecx,1
00401045 mov dword ptr [ebp-4],ecx
00401048 mov edx,dword ptr [ebp-4]
0040104B add edx,dword ptr [ebp-4]///以上同3例
0040104E mov dword ptr [ebp-4],edx// 值移入k地址k=8

5. int k=2;
int val=0;
val=(++k)+(k++);

8: int k=2;
00401028 mov dword ptr [ebp-4],2
9: int val=0;
0040102F mov dword ptr [ebp-8],0
10: val=(++k)+(k++);
00401036 mov eax,dword ptr [ebp-4]
00401039 add eax,1
0040103C mov dword ptr [ebp-4],eax//k=k+1=3
0040103F mov ecx,dword ptr [ebp-4]
00401042 add ecx,dword ptr [ebp-4]//k+k=6
00401045 mov dword ptr [ebp-8],ecx//val=6
00401048 mov edx,dword ptr [ebp-4]
0040104B add edx,1//k=k+1=4
0040104E mov dword ptr [ebp-4],edx

6. int k=2;
int val=0;
k=(++k)+(k++);

8: int k=2;
00401028 mov dword ptr [ebp-4],2
9: int val=0;
0040102F mov dword ptr [ebp-8],0
10: k=(++k)+(k++);
00401036 mov eax,dword ptr [ebp-4]
00401039 add eax,1//k+1
0040103C mov dword ptr [ebp-4],eax//k=3
0040103F mov ecx,dword ptr [ebp-4]
00401042 add ecx,dword ptr [ebp-4]//k+k=6
00401045 mov dword ptr [ebp-4],ecx//k=6
00401048 mov edx,dword ptr [ebp-4]
0040104B add edx,1
0040104E mov dword ptr [ebp-4],edx//k=k+1=7

1．
int k=2;
int val=0;
val=(k++)+(k++)+(++k);

331: int k=2;
00407488 mov dword ptr [ebp-14h],2
332: int val=0;
0040748F mov dword ptr [ebp-18h],0
333: val=(k++)+(k++)+(++k);
00407496 mov eax,dword ptr [ebp-14h]
00407499 add eax,dword ptr [ebp-14h]//以上同双操做数中间数存在eax中eax=4,k=2
0040749C mov ecx,dword ptr [ebp-14h]
0040749F add ecx,1
004074A2 mov dword ptr [ebp-14h],ecx//k=3
004074A5 add eax,dword ptr [ebp-14h]//eax+k=
004074A8 mov dword ptr [ebp-18h],eax//赋值给val=eax+k=7
004074AB mov edx,dword ptr [ebp-14h]
004074AE add edx,1
004074B1 mov dword ptr [ebp-14h],edx
004074B4 mov eax,dword ptr [ebp-14h]
004074B7 add eax,1
004074BA mov dword ptr [ebp-14h],eax

2．
int k=2;
int val=0;
k=(k++)+(k++)+(++k);

331: int k=2;
00407488 mov dword ptr [ebp-14h],2
332: int val=0;
0040748F mov dword ptr [ebp-18h],0
333: k=(k++)+(k++)+(++k);
00407496 mov eax,dword ptr [ebp-14h]
00407499 add eax,dword ptr [ebp-14h]
0040749C mov ecx,dword ptr [ebp-14h]
0040749F add ecx,1
004074A2 mov dword ptr [ebp-14h],ecx
004074A5 add eax,dword ptr [ebp-14h]
004074A8 mov dword ptr [ebp-14h],eax//赋值给k=eax+k=7
004074AB mov edx,dword ptr [ebp-14h]
004074AE add edx,1
004074B1 mov dword ptr [ebp-14h],edx//k=k+1=8
004074B4 mov eax,dword ptr [ebp-14h]
004074B7 add eax,1
004074BA mov dword ptr [ebp-14h],eax//k=k+1=9

1.
int k=2;
int val =0;
val=(++k)+(++k)+(k++)+(++k) +(++k) +(++k) +(++k) +(k++)+(k++)+(k++);
val=4 + 4 +4 +5 +6 +7 +8 +8 +8 +8= 62

2.
int k=2;
int val =0;
k=(++k)+(++k)+(k++)+(++k) +(++k) +(++k) +(++k) +(k++)+(k++)+(k++);
4个k++
k=4 + 4+ 4 +5 +6 + 7 + 8 +8 +8 +8 在加 4=66

"a--,--a"与++a,a++相同.

0 0