Skip to content

Instantly share code, notes, and snippets.

@weirddan455
Created April 26, 2022 16:54
Show Gist options
  • Save weirddan455/78641c4dad06d691c959bf9a6f81ecc6 to your computer and use it in GitHub Desktop.
Save weirddan455/78641c4dad06d691c959bf9a6f81ecc6 to your computer and use it in GitHub Desktop.
void swap_xor(int *x, int *y)
{
*x = *x ^ *y;
*y = *x ^ *y;
*x = *x ^ *y;
}
void swap_normal(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
/* Dissasembly
0000000000001170 <swap_xor>:
1170: 8b 07 mov eax,DWORD PTR [rdi]
1172: 33 06 xor eax,DWORD PTR [rsi]
1174: 89 07 mov DWORD PTR [rdi],eax
1176: 33 06 xor eax,DWORD PTR [rsi]
1178: 89 06 mov DWORD PTR [rsi],eax
117a: 31 07 xor DWORD PTR [rdi],eax
117c: c3 ret
117d: 0f 1f 00 nop DWORD PTR [rax]
0000000000001180 <swap_normal>:
1180: 8b 07 mov eax,DWORD PTR [rdi]
1182: 8b 16 mov edx,DWORD PTR [rsi]
1184: 89 17 mov DWORD PTR [rdi],edx
1186: 89 06 mov DWORD PTR [rsi],eax
1188: c3 ret
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment