flat assembler
Message board for the users of flat assembler.

Index > Main > XOR EAX,EAX

Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Author
Thread Post new topic Reply to topic
Kain



Joined: 26 Oct 2003
Posts: 108
Kain
tom tobias wrote:

Kain wrote:

it will eventually become natural

Yes, doing things improperly can indeed become "natural", history is full of illustrations. Very appropriate comment, "Kain".


I meant understanding would become natural. Anybody who doesn't understand boolean operations has no business in assembly. Assembly hides the big picture most of the time as it's focused on only a few pixels at a time. It is important to have a small comment header in each section to inform the reader what it does.

_________________
:sevag.k
Post 17 Dec 2006, 20:03
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
That is indeed true. that's how i layout my programs.
Post 17 Dec 2006, 20:05
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
tom tobias wrote:
As my dad used to ask me, "Is your arm broken"?
The question then is this, Would a "tutorial" (whether in depth, or superficial, and whether authored by Tomasz, or someone (i.e. anyone!) else of lesser talent) yield a satisfactory answer to the original question posed by the author of this thread, i.e. why is it desirable to employ a Boolean (or arithmetic) operator to clear or test a register, rather than the intuitive instructions, MOV reg, zero; CMP reg, zero?


Dude what the hell are you talking about? Tomasz posted an explanation of the XOR instruction from a different "angle" and I suggested with his in-depth knowledge he should contribute the assembly tutorial beginners so desperately want as he is better suited then most.

Why would we use XOR, well as the ten thousand people have said before me, the instruction is smaller, the instruction is faster, and we code in assembly for a reason. I don't know why YOU code in assembly, but most of us code for size/speed/control, so when there is a public and common optimization we generally implement it Wink

Reading your posts frustrates me greatly.

_________________
redghost.ca
Post 17 Dec 2006, 22:00
View user's profile Send private message AIM Address MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
i'd like to see him come up with a few simple games and comment every section of his tricks so we have something to learn off of. I only ever remember one trick from anything i've learned to use in assembly and that is using add if i want to multiply anything by 2 other than the eax register. It'd be interesting to see some more "sneaky tricks" like that.
Post 17 Dec 2006, 22:13
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
kohlrak: look at "aam" instruction
Post 17 Dec 2006, 22:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
vid wrote:
kohlrak: look at "aam" instruction


I'm not talking about packed numbers... I'll show you what i mean below.

Code:
push eax ;to save the "important stuff" from eax
mul ebx, 2
mov ebx, eax
pop eax    


can become the following, but more quickly.

Code:
add ebx, ebx    
Post 17 Dec 2006, 22:36
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
neither am i. again, do some research. It is often used as a very cruel trick to multiple numbers
Post 17 Dec 2006, 23:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
kohlrak wrote:
vid wrote:
kohlrak: look at "aam" instruction


I'm not talking about packed numbers... I'll show you what i mean below.

Code:
push eax ;to save the "important stuff" from eax
mul ebx, 2
mov ebx, eax
pop eax    


can become the following, but more quickly.

Code:
add ebx, ebx    


Code:
shl eax, 1
    


eax is now multiplied by 2 Cool

_________________
redghost.ca
Post 17 Dec 2006, 23:47
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
vid: AAM does the division, it's AAD that does multiplication. Wink
Post 17 Dec 2006, 23:53
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
RedGhost wrote:
kohlrak wrote:
vid wrote:
kohlrak: look at "aam" instruction


I'm not talking about packed numbers... I'll show you what i mean below.

Code:
push eax ;to save the "important stuff" from eax
mul ebx, 2
mov ebx, eax
pop eax    


can become the following, but more quickly.

Code:
add ebx, ebx    


Code:
shl eax, 1
    


eax is now multiplied by 2 Cool


That's probably the fastest one yet. XD I'm experimenting with that one a little more...

I still can't figure out how AAD or AAM does either... XD I guess it's my lack of understanding of packed numbers...
Post 17 Dec 2006, 23:55
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
BTW, "mul ebx, 2" doesn't exists, though, exists "imul ebx, 2" which is encoded as "imul ebx, ebx, 2" and leaves EAX untouched.
Post 17 Dec 2006, 23:56
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
kohlrak wrote:
I still can't figure out how AAD or AAM does either... XD I guess it's my lack of understanding of packed numbers...

The Intel manuals describe them quite well.

AAD operation description from the "IA-32 Intel® Architecture Software Developer’s Manual", Volume 2A:
Quote:
tempAL ← AL;
tempAH ← AH;
AL ← (tempAL + (tempAH ∗ imm8)) AND FFH; (* imm8 is set to 0AH for the AAD mnemonic *)
AH ← 0


AAM operation description from the same source:
Quote:
tempAL ← AL;
AH ← tempAL / imm8; (* imm8 is set to 0AH for the AAM mnemonic *)
AL ← tempAL MOD imm8;


(note that imm8 is the parameter to instruction, if you don't specify it, assembler assumes value of 10)
Post 17 Dec 2006, 23:59
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
LocoDelAssembly wrote:
BTW, "mul ebx, 2" doesn't exists, though, exists "imul ebx, 2" which is encoded as "imul ebx, ebx, 2" and leaves EAX untouched.


I know, but i'd sooner use the lsh or add for 2, and lsh for 2, 4, 8, 16, 32, and so on. But we have our styles. lol

What's the box...?
Post 18 Dec 2006, 00:00
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
WytRaven



Joined: 08 Sep 2004
Posts: 45
Location: Canberra, Australia
WytRaven
Quote:
Had to look up a couple of words:
http://www.yiddishdictionaryonline.com/
"vay" apparently means "Gosh", or "OOPS", or "WOW"

You had to look up dictionaries to decipher this sentence? The word was 'Yay' by the way, not 'vay', and dictionary.com would have found the correct definition for you just fine.
Quote:

...
while, "gimp" apparently refers, in a derogatory sense, to someone with a disability, or infirmity.

Actually no. It would appear that dictionary.com does not extend its definitions into the realm of modern culture, I would suggest you keep digging until you find the real insult. The sentence in it's entirety was dripping with sarcasm just in case you didn't catch that.
Quote:

but, whether the comment is regarded by others as productive and/or dignified, or simply a distraction, as I suspect is the case, it appears irrelevant to the central question of this thread.

tom, you are irrelevant. The question posted by the OP was to inquire after the reason for seeing things such as xor eax,eax instead of mov eax,0. In particular the OP was wanting to know what advantage these methods had over using the basic mov eax, 0. The answer was given immediately in simple form and then expanded upon by several others. Note that the OP is now enlightened. Nowhere in the OP's post do I see a request to hear you regurgitate your optimized assembly diatribe. For the final time tom, your CODE vs PROGRAMS spiel is ludicrous in the context of assembly language.

Moderator: Can we get this thread closed? It really is going nowhere...

_________________
All your opcodes are belong to us
Post 18 Dec 2006, 11:57
View user's profile Send private message Reply with quote
YONG



Joined: 16 Mar 2005
Posts: 8000
Location: 22° 15' N | 114° 10' E
YONG
A fast program is good.

A fast program, which makes use of intuitive instructions, is even better.

A fast, well-documented program, which makes use of intuitive instructions, is the best.

Having said that, I STILL CHOOSE the XOR approach! Wink

YONG
Post 18 Dec 2006, 13:16
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
Come on, computers are logical.. There is nothing cryptic in Xor eax, eax, otherwise it wouldn't have been computers, right?

Boolean algebra: what does a number xored by itself yield?? pure logic, man! maybe not logic in english-style, however in 1s and 0s style it's logic.. and computers use 1s and 0s, not english Wink
Post 18 Dec 2006, 16:38
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I have a simple system for writing code.

Level 1 (Sent to programers who don't use the language the source is in): Heavy commenting of everything.
Level 2 (Sent to programmers of that language): Commenting anything cryptic (xor eax, eax) that might not be instantainiously obvious.
Level 3 (for when i don't release the souce): Only notes for myself, if any.

Now, if you use level 2 when redistributing your code, there isn't anything too cryptic or complicated, because anything that is complicated, you have a comment there of what it's a synonym for. Examples of code below..

Well, i won't do one for level 1 programming, you can look at my c func example in the examples post and you'll see, quickly, how detailed i am.

Example for level 2 is a real example i did for my programming teacher in C++...

Code:
bool IsPrime(int num){
        for (int check1=1; check1!=(((int)num/2)+1); check1++) //Sneaky speed saving algoritham.
                for (int check2=2; check2!=(((int)num/2)+1); check2++){
                        int var=check1*check2;
                        if (var==num)
                                return 0; }
        return 1; }
//------------------------------------------------------------------
void main(){
        for (int count=2; count!=100; count++)
                if (IsPrime(count))
                        cout << count << " is prime!\n";
        return; }    


and my level 3...

Code:
void Spaces(int a){
        a--; // A smiple fix
        while(a) {
                cout << ' ';
                a--; } // Quicker than a for loop
        return; }
//------------------------------------------------------------------
void ITri(int a){
        for(int check1=0; check1!=a; check1++){
                Spaces(a-check1);
                for (int check2=0; check2<(check1+1); check2++)
                        cout << '*';
                //proc extraout
                for (int check3=0; check3<check1; check3++)
                        cout << '*';
                cout << '\n'; }
        return; }
//------------------------------------------------------------------
void main(){
        ITri(4);
        return; }    


Note the level 3 example was edited quickly since i really don't have any decent level 3 examples on hand.
Post 18 Dec 2006, 21:47
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight
i know this topic i quite old but i wa looking through it and felt that a few newbs might be misled by it. I'm not sure how Intells documentation has it but AMD has defined special Optimizations towards using xor to clear a register. and has defined it is the perfered method of zeroing a register.
Post 16 Jul 2007, 19:39
View user's profile Send private message Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
FrozenKnight wrote:
....and has defined it is the perfered method of zeroing a register.
What nonsense. Please provide a REFERENCE.
It is absurd to employ a Boolean operator with ONLY A SINGLE OPERAND. The whole point of George Boole's research, published in the Cambridge and Dublin Mathematical Journal, volume III, (1848), pages 183-198, titled, "The Calculus of Logic", was to show systematically the relationship of different groups of two or more operands:
http://www.maths.tcd.ie/pub/HistMath/People/Boole/CalcLogic/CalcLogic.pdf
FrozenKnight wrote:
...i [I] know this topic i[s] quite old....
Of course not. You will learn what old is, soon enough!!!
George Boole wrote:

Suppose that we have the conception of any group of objects consisting of
Xs, Ys, and others, and that x, which we shall call an elective symbol, represents the mental operation of selecting from that group all the Xs which it contains, or of fixing the attention upon the Xs to the exclusion of all which are not Xs,
y the mental operation of selecting the Ys, and so on; then, 1 or the universe being the subject conception, we shall have
x 1 or x = the class X,
y 1 or y = the class Y,
xy1 or xy = the class each member of which is both X and Y,
and so on....
.... [elaborating his famous distributive and commutative laws, showing the interrelationship of the classes]
....
The truth of these laws does not at all depend upon the nature, or the
number, or the mutual relations, of the individuals included in the different
classes. There may be but one individual in a class, or there may be a thousand.
....
[examples]
....
Let x denote all steamers, or steam-vessels,
y denote all armed vessels,
z denote all vessels of the Mediterranean.
Equation (a) would then express that armed steamers consist of the armed vessels of the Mediterranean and the steam-vessels not of the Mediterranean. From this it follows|
(1) That there are no armed vessels except steamers in the Mediterranean.
(2) That all unarmed steamers are in the Mediterranean (since the steam-vessels not of the Mediterranean are armed). Hence we infer that the vessels of the Mediterranean consist of all unarmed steamers; any number of armed steamers; and any number of unarmed vessels without steam. This, expressed symbolically, is equation (15).

I cannot imagine George Boole being concerned with only one single ship floating about somewhere in the Mediterranean Sea.
Post 18 Jul 2007, 11:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
tom: as i countless time told you, XOR instruction on x86 is not same as boolean XOR. boolean XOR operates on true / false values, but instruction XOR operates on set of 32 true/false values, and modifies one of it's operands. Do not mistake these two.


Last edited by vid on 18 Jul 2007, 11:45; edited 1 time in total
Post 18 Jul 2007, 11:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next

< 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.