flat assembler
Message board for the users of flat assembler.

 Index > Main > Why do I need to use XOR, AND, OR?
Author
Kristian_

Joined: 13 Nov 2004
Posts: 38
Kristian_
Hi!
Well, I know how to use them, but for what are they useful? Thank you!
15 Nov 2004, 17:27

Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
You will learn soon, that you can't live without them
Code:
```;AND:
;Let's say you have useful data in lower part of eax
and eax,0FFFFh
;Now the upper part does not bother you
;OR:
;You have something in lower eax and upper ebx
or  eax,ebx
;Now you have all you need in eax
;XOR:
;This is not meant this way but mostly it is used to zero out regs
xor eax,eax
;Now eax=0 according to XOR rules

;#Ok, now one real world application
;#You have a user input a string which
;#is in decimal of course. This takes up
;#much space and we can pack it to
;#50% exactly (4 to 2 bytes).
mov eax,[UserInput] ;Let's pretend we have 32353739h
;Which is "2579" as a string
and eax,0F0F0F0Fh   ;Now we only have 02050709h
mov ebx,eax         ;ebx=eax
shl ebx,4           ;ebx is 20507090h
or  ebx,eax         ;ebx is 22557799h now (EAX OR EBX)
ror ebx,4           ;ebx is 92255779h
mov eax,ebx         ;eax=ebx
shr eax,8           ;eax is 00922557h
mov al,bl           ;eax changed to 00922579
and eax,0FFFFh      ;eax is 00002579 <=BCD result
```

I'll give you a buch of others when you grow older and wiser
like an MMX solution for the same problem.

_________________
My updated idol http://www.agner.org/optimize/
15 Nov 2004, 19:07
Kristian_

Joined: 13 Nov 2004
Posts: 38
Kristian_
Thank you very much!
Assembly is so interesting!!!
15 Nov 2004, 19:15
Matrix

Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
they are logical operations of the Arithmetical&Logical Unit of your Processor,
Code:
```xor al,bl ; this will exclusive or bits in al, with appropriate bits in bl, then place the result in al
```

you can get idea on data recovery using XOR
X XOR B = A
A XOR X = B

so

like ABCDEFXYZ (like in raid - 3 letters represent one disk)
where
X=A xor D
Y=B xor E
Z=C xor F
now XYZ on 3rd disk is data recovery information, now if 1 disk loses all data, you can recover it.
http://www.thecodeproject.com/csharp/raidfile.asp

so use it when you need it

btw.: i also recommend you reading the basics before asking something, this board is not large enough to contain every basic questions like what is byte? or similar.

you should also take a look @
Flat Assembler Frequently Asked Questions (FAQ) (main)

its linked to other FAQs as well, and they should contain a large amount of links to tutorials. if you find tutorials explaining your problem well you can recommend them @ faq page like:

"i found this great tutorial about xxxx @ http://xxxx.com/whatisit.htm,

this way it others have the same question, they will find it easily without searching in the FAQ

Last edited by Matrix on 17 Nov 2004, 04:40; edited 2 times in total
15 Nov 2004, 19:16
veach1

Joined: 16 Jul 2004
Posts: 165
veach1
XOR can be used instead of XCHG
Code:
```xor ax, bx
xor bx, ax
xor ax, bx
```
16 Nov 2004, 07:37
 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