07-26-2023, 07:42 PM
In the below code, output remains same in both cases,thanks for pointing what am I missing:-
Before Swap:-
a=10 b=512
After Swap:-
a=10 b=512
Following is the code, It compiles and runs without any problem:-
#include <stdio.h>
int swap(int* x, int* y)
{
if(x != y)
{
_asm
{
mov eax,[x]; x into eax
mov ebx,[y]
mov [x],ebx;swapping now
mov [y],eax
}
}
return 0;
}
int main () {
int a=10,b=512;
printf("Before Swap:- \na=%d\t b=%d\n",a,b);
swap(&a,&b);
printf("After Swap:- \na=%d\t b=%d",a,b);//Value remains same
return 0;
}
Before Swap:-
a=10 b=512
After Swap:-
a=10 b=512
Following is the code, It compiles and runs without any problem:-
#include <stdio.h>
int swap(int* x, int* y)
{
if(x != y)
{
_asm
{
mov eax,[x]; x into eax
mov ebx,[y]
mov [x],ebx;swapping now
mov [y],eax
}
}
return 0;
}
int main () {
int a=10,b=512;
printf("Before Swap:- \na=%d\t b=%d\n",a,b);
swap(&a,&b);
printf("After Swap:- \na=%d\t b=%d",a,b);//Value remains same
return 0;
}