Message board for the users of flat assembler.
> Main > Why do I need to use XOR, AND, OR?
Well, I know how to use them, but for what are they useful? Thank you!
|15 Nov 2004, 17:27||
You will learn soon, that you can't live without them
;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
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||
Thank you very much!
Assembly is so interesting!!!
|15 Nov 2004, 19:15||
they are logical operations of the Arithmetical&Logical Unit of your Processor,
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
like ABCDEFXYZ (like in raid - 3 letters represent one disk)
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:
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
|15 Nov 2004, 19:16||
XOR can be used instead of XCHG
xor ax, bx xor bx, ax xor ax, bx
|16 Nov 2004, 07:37||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.
Website powered by rwasa.