flat assembler
Message board for the users of flat assembler.

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

Author
Thread Post new topic Reply to topic
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_
Hi!
Well, I know how to use them, but for what are they useful? Thank you!
Post 15 Nov 2004, 17:27
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
You will learn soon, that you can't live without them Wink
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 
    

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

_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 15 Nov 2004, 19:07
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Kristian_



Joined: 13 Nov 2004
Posts: 38
Kristian_
Thank you very much!
Assembly is so interesting!!!
Post 15 Nov 2004, 19:15
View user's profile Send private message Reply with quote
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.
more info here:
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,
and you should add it to your faq."

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
Post 15 Nov 2004, 19:16
View user's profile Send private message Visit poster's website Reply with quote
veach1



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

Powered by rwasa.