flat assembler
Message board for the users of flat assembler.

 Index > Main > what is xor
Author
GhostXoPCorp

Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 02 Jul 2009, 01:27
i have never used xor before, and had just found it in a vesa tutorial, and i read up on what it does but i dont understand, whhat does it do?

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
02 Jul 2009, 01:27
LocoDelAssembly

Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Jul 2009, 01:34
It performs the eXclusive OR operation.
http://en.wikipedia.org/wiki/Exclusive_or

Not however that many times you'll see that XOR contains two register operands that are the same. For instance, in situations like "XOR eax, eax", "MOV eax, 0" would be the same except for a minor difference (the former alters the flags while the latter doesn't)
02 Jul 2009, 01:34
windwakr

Joined: 30 Jun 2004
Posts: 827
windwakr 02 Jul 2009, 01:36
if the the second bit is one flips the first bit.
By second bit I mean the second operand of xor, not the second bit of the number you're using.

So for example, 10011011 xor 10101101 would be 00110110

Code:
```INPUT
A       B       OUTPUT
0       0       0
0  1       1
1  0       1
1  1       0
```
02 Jul 2009, 01:36
GhostXoPCorp

Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 02 Jul 2009, 02:26
so xor is just like mov ax,0 without modifying flags?

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
02 Jul 2009, 02:26
windwakr

Joined: 30 Jun 2004
Posts: 827
windwakr 02 Jul 2009, 02:33
xor ax,ax would be like mov ax,0
02 Jul 2009, 02:33
Yardman

Joined: 12 Apr 2005
Posts: 244
Location: US
Yardman 02 Jul 2009, 02:43
[ Post removed by author. ]

Last edited by Yardman on 04 Apr 2012, 03:25; edited 1 time in total
02 Jul 2009, 02:43
LocoDelAssembly

Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Jul 2009, 02:48
And it is XOR which modifies the flags, so avoid things like this:
Code:
```cmp ax, VALUE
xor ax, ax
je IT_IS_EQUAL ; This jump will always be taken    ```

In such cases you will need mov
Code:
```cmp ax, VALUE
mov ax, 0
je IT_IS_EQUAL ; Will jump only if AX was equal to VALUE before setting it to zero    ```

In general you can use XOR safely, only rarely situations like above make it a bad choice.

tom tobias must be rolling in the floor laughing at me right now
02 Jul 2009, 02:48
bitRAKE

Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 02 Jul 2009, 02:54
XOR does modify flags. If we think in terms of the effect on the bits: XOR uses the source to select which bits to reverse in the destination (i.e. conditional NOT). We see this used in raster graphics algorithms. For example, how to reverse bits 4-7 of a byte? Answer: XOR AL,\$F0.
02 Jul 2009, 02:54
arigity

Joined: 22 Dec 2008
Posts: 45
arigity 02 Jul 2009, 03:11
Quote:
XOR
Syntax: XOR dest,src

The XOR instruction connects two values using logical exclusive OR (remember OR uses
inclusive OR).

This instruction clears the O-Flag and the C-Flag and can set the Z-Flag.
To understand XOR better, consider those two binary values:

1001010110
0101001101

If you OR them, the result is 1100011011

When two bits on top of each other are equal, the resulting bit is 0. Else the resulting
bit is 1. You can use calc.exe to calculate XOR.
The most often seen use of XOR is “XOR, EAX, EAX”. This will set EAX to 0, because when
you XOR a value with itself, the result is always 0. I hope you understand why, else
write down a value on paper and try
02 Jul 2009, 03:11
GhostXoPCorp

Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 02 Jul 2009, 04:51
thanks for all of the information guys
02 Jul 2009, 04:51
eskizo

Joined: 22 Nov 2005
Posts: 59
eskizo 02 Jul 2009, 06:20
Every bitwise operation modifies the flags, am I wrong?

xor
or
and
not
02 Jul 2009, 06:20
manfred

Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred 02 Jul 2009, 15:32
Yes, all bitwise operations modify the flags.

_________________
Sorry for my English...
02 Jul 2009, 15:32
Borsuc

Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 02 Jul 2009, 15:44
That's make it easy to remember.
02 Jul 2009, 15:44
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum