flat assembler
Message board for the users of flat assembler.

Index > Main > what is xor

Author
Thread Post new topic Reply to topic
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
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.
Post 02 Jul 2009, 01:27
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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)
Post 02 Jul 2009, 01:34
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
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
    
Post 02 Jul 2009, 01:36
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
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.
Post 02 Jul 2009, 02:26
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
xor ax,ax would be like mov ax,0
Post 02 Jul 2009, 02:33
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:25; edited 1 time in total
Post 02 Jul 2009, 02:43
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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 Razz
Post 02 Jul 2009, 02:48
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3045
Location: vpcmipstrm
bitRAKE
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.
Post 02 Jul 2009, 02:54
View user's profile Send private message Visit poster's website Reply with quote
arigity



Joined: 22 Dec 2008
Posts: 45
arigity
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 Wink
Post 02 Jul 2009, 03:11
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
thanks for all of the information guys
Post 02 Jul 2009, 04:51
View user's profile Send private message Reply with quote
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo
Every bitwise operation modifies the flags, am I wrong?

xor
or
and
not
Post 02 Jul 2009, 06:20
View user's profile Send private message Reply with quote
manfred



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

_________________
Sorry for my English...
Post 02 Jul 2009, 15:32
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
That's make it easy to remember.
Post 02 Jul 2009, 15:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.