I\'m getting into assembly and I keep running into xor, for example:
xor ax, ax
Does it just clear the register\'s value?
It determines the logical eXclusive OR
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
So, TRUE only if one of the expressions is true, not both.
xor reg, reg
is often used to clear register. It can be an alternative to mov reg, 0
AFAIR, it was faster (or shorter) in some cases.
And of course, XOR itself is eXclusive OR (a.k.a.: exclusive disjunction) operation (but it's a shame to describe here such basics - use Wikipedia)
xor = exclusive or. See wikipedia's definition for Exclusive or.
If you xor a register with itself, it will zero that register.
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0
Let's take the value 41 as example (in binary):
101001
xor 101001
= 000000
If I remember correctly xor ax, ax is a one byte assembly instruction, whilst mov ax, 0 would be at least 3 and would probably take slightly longer to execute. It will certainly take longer to decode than the xor instruction.
xor register, register
is commonly used to 'zero' a register, because all bits are compared with each other:
0-bits stay zero. 1-bits become zero, because 1 XOR 1 is also 0.