闲着蛋疼看下a++的过程
赋值过程
int a = 1;
int b = a++;
x86 反汇编:
int a = 1;
00D06428 C7 45 F8 01 00 00 00 mov dword ptr [a],1
int b = a++;
00D0642F 8B 45 F8 mov eax,dword ptr [a]
00D06432 89 45 EC mov dword ptr [b],eax 先赋值
00D06435 8B 4D F8 mov ecx,dword ptr [a]
00D06438 83 C1 01 add ecx,1
00D0643B 89 4D F8 mov dword ptr [a],ecx 在修改
传递过程
int a = 1;
printf("%d\n", a++);
x86反汇编:
int a = 1;
003E6428 C7 45 F8 01 00 00 00 mov dword ptr [a],1
printf("%d\n", a++);
003E642F 8B 45 F8 mov eax,dword ptr [a]
003E6432 89 85 30 FF FF FF mov dword ptr [ebp-0D0h],eax 存了旧值
003E6438 8B 4D F8 mov ecx,dword ptr [a]
003E643B 83 C1 01 add ecx,1
003E643E 89 4D F8 mov dword ptr [a],ecx a已被改变
003E6441 8B 95 30 FF FF FF mov edx,dword ptr [ebp-0D0h] 取了旧值
003E6447 52 push edx
003E6448 68 30 8C 44 00 push offset string "%d\n" (0448C30h)
003E644D E8 DE 9D FF FF call _printf (03E0230h) 调用函数
003E6452 83 C4 08 add esp,8
保存旧值,修改值,传递旧值