i've seen the use of xor in assembly programs, but i don't know what it does or why it matters. Helppc said it was an Exclusive Bitwise OR, but I don't even know what an OR is :dazzled:
please give code examples and explanation :U
Along the lines of electronics, a gate operates by on and off states (0=off or 1=on). The inputs to the gate(A,B) are on the left and the output (C) is on the right.Following along in the part of the 'AND' example below, reading from the 'Truth Table', the inputs A and B are required to be 'on' in order for C to be on (1). It could be read as the following:
IF A=0 AND B=0 then C=0
IF A=0 AND B=1 then C=0
IF A=1 AND B=0 then C=0
IF A=1 AND B=1 then C=1
So The "Truth Table" for XOR Reads something like this
IF A=0 XOR B=0 then C=0
IF A=0 XOR B=1 then C=1
IF A=1 XOR B=0 then C=1
IF A=1 XOR B=1 then C=1
From the above table.....If both the inputs(A,B) are same then the output will be ZERO "0" or OFF
"To result in TRUE, XOR requires that ONLY ONE of its two operands to be TRUE."So, when you XOR two bits when both are valued 1, the result will ALWAYS be 0
XOR is used in some encryption technology such as XOR encryption and for XOR swap. XOR allows you to swap the contents of two variables without using a third variable
An example:
lets say you have A=1 and B=0
XOR A,B ==>>now A=1 and B=0
XOR B,A ==>>now A=1 and B=1
XOR B,A ==>>now A=0 and B=1
Hope it gives you a better picture.so enjoy
Have a look at Art of Assembly at:
http://webster.cs.ucr.edu/AoA/Windows/index.html
You can study it on-line or download the entire tutorial in either HTML or PDF format. You will find in it the answer to most of your basic questions related to opcodes and the assembly language.
Raymond
Quote from: raymond on November 19, 2005, 05:54:10 PM
Have a look at Art of Assembly
The Best Choice available on net.and an another option:
http://win.asmcommunity.net/x86book/
The bitwise operations for AND, OR, XOR, NOT.
Easy to remember rules and the truth tables.
For AND if both are 1 then 1 else 0 ( AND all 1 then 1)
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
For OR if both are 0 then 0 else 1 ( OR all 0 then 0)
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
For XOR if both are the same then 0 else 1 ( XOR different 1, same 0)
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
For NOT the opposite value ( NOT opposite)
NOT 0 = 1
NOT 1 = 0
Most common use is to zero a register
xor eax,eax ; since eax == eax, each pair of bits is the same, so each resulting bit is 0
Another is to encode (hide) a value, which can be later decoded (recovered) by a second xor operation.
u use xor to clear a reg
for example
mov eax,0fffa1h
then u put
xor eax,eax
the reg eax get cleared
it the same as mov eax,0 === xor eax,eax
then why do i see things like:
mov eax,230
mov ecx,123
xor eax,ecx
because you dont need to put in actual binary/hexidecimal representations, any number form will do (tho it wont make sense in decimal).
mov eax,230 ;11100110
mov ecx,123 ;01111011
xor eax,ecx ;10011101
One example is when certain patterns are set. You want to know if a certain pattern is there. 1010 xor 1010 will always be zero. So you can xor them and jz (jump on zero). I haven't done any asm programming in a while but, in the past, I probably could give a million examples.
A common use of xor is to flip bits (make them opposite.)
So, for "xor reg,num" - for each bit in num that is set (1) it will flip the bit in the same place in reg, bits that are 0 in num will not change those bits in reg.
Usually this is used to change the status of flags (not necessarily the eflags 'register' but program status flags.)
This is why xor-ing a number with itself will turn it into zero - since it changes all the bits set to 1 into 0, and leaves all the bits that are already 0, causing all bits to become 0 => zero.