马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 avatar10010 于 2014-10-13 23:26 编辑
int a=1,b=2,t;
a^=b^=a^=b; //方式一
t=a; //方式二
a=b;
b=t; int a = 1, b = 2,t;
001F356E mov dword ptr [a],1
001F3575 mov dword ptr [b],2
a ^= b ^= a ^= b;
001F357C mov eax,dword ptr [a]
001F357F xor eax,dword ptr [b]
001F3582 mov dword ptr [a],eax
001F3585 mov ecx,dword ptr [b]
001F3588 xor ecx,dword ptr [a]
001F358B mov dword ptr [b],ecx
001F358E mov edx,dword ptr [a]
001F3591 xor edx,dword ptr [b]
001F3594 mov dword ptr [a],edx
t= a;
001F3597 mov eax,dword ptr [a]
001F359A mov dword ptr [t],eax
a = b;
001F359D mov eax,dword ptr [b]
001F35A0 mov dword ptr [a],eax
b = t;
001F35A3 mov eax,dword ptr [t]
001F35A6 mov dword ptr [b],eax
显然方式二效率更高
|