XOR - eXclusive OR
Syntax: xor dst, src
Description:
XOR truth table:
A | B | Result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Examples:
xor rax, 42
-
C pseudo code would be value = value ^ 42;
xor rcx, rbx
Add the contents of RBX into RCX
C pseudo code would be:
int valB = 50;
int valC = 20;
valC = valC ^ valB;
Hint:
XOR is the easiest way to clear a register as anything xor'd with itself is 0.
mov rax, 0
gives the same result as
xor rax, rax
However, the actual machine code is more compact with XOR:
48B80000000000000000 mov rax, 0
4831C0 xor rax, rax
Clearing a register can even be further simplified by only clearing its 32-bit part.
31C0 xor eax, eax