Reverse Engineering Stack Exchange is a question and answer site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following line in an assembler code:


So, then I've searched a little bit and found out that XOR represents a "swap algorithm". You can read it here:

But when I look in register window of ollydbg, then I have the following

 EAX = 00000068
 EBX = 0000003B

Now, after the line the register window says

EAX = 000000053
EBX = 0000003B

But from that what I have read in wikipedia article I would expect the following

EAX = 0000003B
EBX = 00000053

At the end, i can say that a normal XOR operation is performed because:

0111011   =>EAX=0000003B 
1101000   =>EBX=00000068
1010011   =>EAX=00000053

So my question would be why the swap algorithm is not performed. Or in other words: When can I expect the swap algorithm?

share|improve this question
up vote 12 down vote accepted

As the first answer states, XOR is a bitewise XOR, not an XOR swap.

To do the Xor swap that you referenced from wikipedia it takes 3 instructions :

xor eax, ebx
xor ebx, eax
xor eax, ebx

Since you asked about the purpose of XOR I thought I would include some other concepts for you to read up on, so you might have an idea of what to expect from XORs

You can use XOR to clear a register:

xor eax,eax

Calculate absolute value:

xor eax,edx
sub eax,edx

XORs can be used for Crypto:

XORs are used in the CRC checksum algorithm:

XORs can be used to calculate Gray codes:

This is just the tip of the iceberg. The instruction can be used in a large number of situations.

share|improve this answer

The XOR mnemonic does not represent an XOR swap; it represents a bitwise XOR.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.