I'm getting into assembly and I keep running into xor, for example:
xor ax, ax
Does it just clear the register's value?
The XOR function returns a logical Exclusive Or of all arguments.
the XOR (and many other arithmetic/logic operations) will set the zero flag of the status register if the result of the operation is zero.
xor ax, ax would do the same as mov ax, 0 , but with additional capability of setting the flag to zero and clearing carry according to the logic of xor. And xor consumes less clocks than mov does in some old architectures. mov eax,eax would take up 5 bytes in byte code where xor eax,eax would consume 2 bytes.
This means that any value XOR'd with itself gives zero.
A XOR B
in english would be translated as "are A and B not equal". So xor ax, ax
will set ax
to zero since ax is always equal to itself.
A B | A XOR B 0 0 | 0 1 0 | 1 0 1 | 1 1 1 | 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With