如欲得到指针指向的数据,需要二次寻址才可,如下程序为交换两个指针指向数据的代码

void Exchange(int *p1,int *p2)
{
#if 1
 _asm
 {
  mov eax,p1;
  mov eax,[eax];

  mov ebx,p2;
  mov ebx,[ebx];

  mov ecx,p1;
  mov [ecx],ebx;

  mov ecx,p2;
  mov [ecx],eax;
 }
#else
 int t=*p1;
 *p1=*p2;
 *p2=t;
#endif
}

void Test5()
{
 int a=1,b=2;
 Exchange(&a,&b);
 printf("%d %d\n",a,b);
}

相关文章:

  • 2021-09-30
  • 2022-12-23
  • 2021-10-28
  • 2021-04-26
  • 2021-05-20
  • 2021-10-09
猜你喜欢
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案