首先,不清楚引用最终怎么实现的,另外不清楚汇编与c语言混用时怎么返回数值,所以这个问题很难呀。试验一:#include <iostream> using namespace std; void myswap(int& a,int& b) { cout<<(long)(&a)<<","<<(long)(&b)<<endl;_asm { mov eax,a mov ebx,b xor ebx,eax xor eax,ebx xor ebx,eax mov a,eax mov b,ebx } cout<<(long)(&a)<<","<<(long)(&b)<<endl;} int main() { int a=5,b=10;cout<<(long)(&a)<<","<<(long)(&b)<<endl; myswap(a,b); cout<<(long)(&a)<<","<<(long)(&b)<<endl;printf("a=%d,b=%d\n" ,a,b); } 看一下这个运行结果估计应该有所启发吧!在程序返回时,地址又还原了!我推测引用实现时,只是把各自指向的值交换,而地址不变,程序中的asm恰恰把它们的地址交换了,而返回时,地址又被还原所以造成没有交换数值。试验二:#include <iostream> using namespace std; void myswap(int* a,int* b) { // cout<<(long)(&a)<<","<<(long)(&b)<<endl; cout<<(long)(a)<<","<<(long)(b)<<endl;_asm { mov eax,a mov ebx,b xor ebx,eax xor eax,ebx xor ebx,eax mov a,eax mov b,ebx } //cout<<(long)(&a)<<","<<(long)(&b)<<endl;cout<<(long)(a)<<","<<(long)(b)<<endl;} int main() { int a=5,b=10;cout<<(long)(&a)<<","<<(long)(&b)<<endl; myswap(&a,&b); cout<<(long)(&a)<<","<<(long)(&b)<<endl;printf("a=%d,b=%d\n" ,a,b); } 试验结果与一相同,所以我认为是asm与c混合的机制造成的,为了防止汇编出错,所有地址要还原。希望能对你有点启发吧!你也运行一下我改的例子,我也关注此问题中。。。下面是反汇编的代码:--- d:\my documents\code\rub**h\asm.cpp ------------------------------------------------------------------------------------------------------------------1: #include <iostream>2:3: using namespace std;4:5: void myswap(int&a,int&b)6: {00401580 push ebp00401581 mov ebp,esp00401583 sub esp,40h00401586 push ebx00401587 push esi00401588 push edi00401589 lea edi,[ebp-40h]0040158c mov ecx,10h00401591 mov eax,0cccccccch00401596 rep stos dword ptr [edi]7: cout<<(long)(&a)<<","<<(long)(&b)<<endl;00401598 push offset @ilt+195(std::endl) (004010c8)0040159d mov eax,dword ptr [ebp+0ch]004015a0 push eax004015a1 push offset string "," (0046c01c)004015a6 mov ecx,dword ptr [ebp+8]004015a9 push ecx004015aa mov ecx,offset std::cout (004777f0)004015af call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)004015b4 push eax004015b5 call @ilt+640(std::operator<<) (00401285)004015ba add esp,8004015bd mov ecx,eax004015bf call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)004015c4 mov ecx,eax004015c6 call @ilt+475(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004011e0)8: // cout<<(long)(a)<<","<<(long)(b)<<endl;9:10: _asm {11: mov eax,a004015cb mov eax,dword ptr [ebp+8]12: mov ebx,b004015ce mov ebx,dword ptr [ebp+0ch]13: xor ebx,eax004015d1 xor ebx,eax14: xor eax,ebx004015d3 xor eax,ebx15: xor ebx,eax004015d5 xor ebx,eax16: mov a,eax004015d7 mov dword ptr [ebp+8],eax17: mov b,ebx004015da mov dword ptr [ebp+0ch],ebx18: }19: /* int c;20: c=a;21: a=b;22: b=c;*/23: cout<<(long)(&a)<<","<<(long)(&b)<<endl;004015dd push offset @ilt+195(std::endl) (004010c8)004015e2 mov edx,dword ptr [ebp+0ch]004015e5 push edx004015e6 push offset string "," (0046c01c)004015eb mov eax,dword ptr [ebp+8]004015ee push eax004015ef mov ecx,offset std::cout (004777f0)004015f4 call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)004015f9 push eax004015fa call @ilt+640(std::operator<<) (00401285)004015ff add esp,800401602 mov ecx,eax00401604 call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)00401609 mov ecx,eax0040160b call @ilt+475(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004011e0)24: //cout<<(long)(a)<<","<<(long)(b)<<endl;25: }00401610 pop edi00401611 pop esi00401612 pop ebx00401613 add esp,40h00401616 cmp ebp,esp00401618 call __chkesp (00420a50)0040161d mov esp,ebp0040161f pop ebp00401620 ret--- d:\my documents\code\rub**h\asm.cpp ------------------------------------------------------------------------------------------------------------------26:27: int main()28: {00401650 push ebp00401651 mov ebp,esp00401653 sub esp,48h00401656 push ebx00401657 push esi00401658 push edi00401659 lea edi,[ebp-48h]0040165c mov ecx,12h00401661 mov eax,0cccccccch00401666 rep stos dword ptr [edi]29: int a=5,b=10;00401668 mov dword ptr [ebp-4],50040166f mov dword ptr [ebp-8],0ah30:31: cout<<(long)(&a)<<","<<(long)(&b)<<endl;00401676 push offset @ilt+195(std::endl) (004010c8)0040167b lea eax,[ebp-8]0040167e push eax0040167f push offset string "," (0046c01c)00401684 lea ecx,[ebp-4]00401687 push ecx00401688 mov ecx,offset std::cout (004777f0)0040168d call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)00401692 push eax00401693 call @ilt+640(std::operator<<) (00401285)00401698 add esp,80040169b mov ecx,eax0040169d call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)004016a2 mov ecx,eax004016a4 call @ilt+475(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004011e0)32: myswap(a,b);004016a9 lea edx,[ebp-8]004016ac push edx ;b004016ad lea eax,[ebp-4]004016b0 push eax ;a004016b1 call @ilt+660(myswap) (00401299)004016b6 add esp,833: cout<<(long)(&a)<<","<<(long)(&b)<<endl;004016b9 push offset @ilt+195(std::endl) (004010c8)004016be lea ecx,[ebp-8]004016c1 push ecx004016c2 push offset string "," (0046c01c)004016c7 lea edx,[ebp-4]004016ca push edx004016cb mov ecx,offset std::cout (004777f0)004016d0 call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)004016d5 push eax004016d6 call @ilt+640(std::operator<<) (00401285)004016db add esp,8004016de mov ecx,eax004016e0 call @ilt+245(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004010fa)004016e5 mov ecx,eax004016e7 call @ilt+475(std::basic_ostream<char,std::char_traits<char> >::operator<<) (004011e0)34: printf("a=%d,b=%d\n" ,a,b);004016ec mov eax,dword ptr [ebp-8]004016ef push eax004016f0 mov ecx,dword ptr [ebp-4]004016f3 push ecx004016f4 push offset string "a=%d,b=%d\n" (0046c020)004016f9 call printf (00420a90)004016fe add esp,0ch35: }00401701 pop edi00401702 pop esi00401703 pop ebx00401704 add esp,48h00401707 cmp ebp,esp00401709 call __chkesp (00420a50)0040170e mov esp,ebp00401710 pop ebp00401711 ret 20210311