Take the 2-minute tour ×
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. It's 100% free, no registration required.

I have the following line in an assembler code:

 XOR EAX, EBX

So, then I've searched a little bit and found out that XOR represents a "swap algorithm". You can read it here: http://en.wikipedia.org/wiki/XOR_swap_algorithm

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

2 Answers 2

up vote 11 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:

cdq
xor eax,edx
sub eax,edx

XORs can be used for Crypto: http://en.wikipedia.org/wiki/XOR_swap_algorithm

XORs are used in the CRC checksum algorithm: http://en.wikipedia.org/wiki/Cyclic_redundancy_check

XORs can be used to calculate Gray codes: http://www.morkalork.com/mork/article/74/How_to_understand_and_use_Gray_code.htm#.U6RhN_ldXvI

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

 
discard

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.