Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of XOR in x86 assembly?

Tags:

assembly

xor

I'm getting into assembly and I keep running into xor, for example:

xor     ax, ax 

Does it just clear the register's value?

like image 843
Chiggins Avatar asked Jan 20 '11 16:01

Chiggins


People also ask

What does a XOR function do?

The XOR function returns a logical Exclusive Or of all arguments.

Does XOR set flags in assembly?

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.

What does XOR ax ax do?

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.

What will be the effect of performing an XOR operation on an operand with itself?

This means that any value XOR'd with itself gives zero.


1 Answers

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 
like image 70
orlp Avatar answered Sep 23 '22 00:09

orlp