flat assembler
Message board for the users of flat assembler.

Index > Main > "mov eax,0" or "xor eax,eax"

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
You're wrong, guys. Just step through SHR EAX,32dec in your favorite debugger and see what will happend: nothing.
Post 12 Dec 2005, 09:57
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
MazeGen: what if he is using 8086?
Post 12 Dec 2005, 10:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
Laughing

There is no explicit immediate in shift and rotate instructions on 8086 Wink
Post 12 Dec 2005, 11:57
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
BTW, I just copied the disassembly from my favourite debugger (Olly) and the results are there as you can see.
There is a catch if you do SHL(R)D reg32,reg32,imm8. This instruction takes the modulus of 32 so 33 takes one bit from another register and ie 111 takes 15 bits from the other register.
Post 12 Dec 2005, 12:03
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
well, on 286 then...
Post 12 Dec 2005, 12:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
According to his suggestion, shr reg,32, I assume he is trying to clear 32-bit register, which is not present on 286...

[lang id="cz"]
Nevím, jestli chápu, na co se vlastně ptáš... šlo mi jenom o to, aby si taky někdo někdy ověřil to, co píše.
[/lang]
Post 12 Dec 2005, 13:36
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
[lang id="sk"]Jasne, chapem, len som rypal...[/lang]
Post 12 Dec 2005, 14:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
Is something clear - did someone write something and is not responsible for it.... hmm.. my Czech and Slovakian is "a bit" rusty Very Happy
Post 12 Dec 2005, 17:08
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
you used some translator or what? We were just clearing what i said to mazegen, because his english isn't the greatest one, so he can happen to misunderstand me somtimes. But he understood well.
Post 12 Dec 2005, 17:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
Hehe, I wondered about vid's lunar politics in his lastest posts and he confessed he just narked me Wink
Post 12 Dec 2005, 17:37
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
when i first started assembler i was always told to use xor r, r because it was fast(er)(est) and from the results and tests i'll just stick with xor

_________________
redghost.ca
Post 12 Dec 2005, 19:40
View user's profile Send private message AIM Address MSN Messenger Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Me too Wink Xoring is something natural for me now, just like using "or" for testing if some register is zeroed. In Fresh source, John Found was always using "test" for that purpose. I just wonder, if there's any speed difference between "or" and "test"?
Post 12 Dec 2005, 20:47
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
Hi Decard: Speed difference?
Let's consider the REAL speed difference. You mentioned FRESH, and John's former code. So, let's stick to that problem. MULTIPLE people working on ONE project.
In that setting, does it make ANY difference whether OR is slower, or faster than TEST?
No, absolutely none. (No one on this forum will reject FRESH because it executes too slowly.)
BUT, if a group of people are trying to work jointly on a project, the single most important factor SLOWING down the project, is the SPEED of comprehension of what the other programmers are trying to accomplish.
The speed of execution is the LEAST of our concerns about FRESH. It is not TOO SLOW. It is nonexistant.
Good programming practice requires RESTRICTING use of Boolean operators to Boolean logical situations. You wrote, well, now I am accustomed to using xor to clear a register. Sure, we all are able to learn some CODE. Even I, dumb as I am, can COMPREHEND that xor eax, eax, MEANS set eax to zero.
BUT, why should it be necessary to reflect, to pause, to think, to imagine, when reading John's, or anyone else's code? Shouldn't our ability to REVISE other's efforts, such as you are now doing with FRESH, be as trouble free as possible? Shouldn't it be just as EASY to read what John had written, as possible, so that you can use your time to its best advantage, use your creativity to improve and ADD FUNCTIONALITY, rather than replace TEST with OR, because OR is 1 nanosecond faster than TEST (assuming that is the case?)
In my opinion, NO ONE ON THIS FORUM will REJECT FRESH, because of its slowness in execution.
Yes, you have now learned that one can use OR (the wrong instruction), instead of TEST (the correct instruction). Sure, we can all learn to do things the WRONG way. What I hope you will come to appreciate is this simple fact:
A great many mistakes from past scholars, and authors, have been introduced into the current practice of contemporary assembly language programmers, as DOGMA. AS STANDARD PRACTICE.
Nonsense. John was correct. Stick to TEST, don't misuse the Boolean operators, NO MATTER HOW "FAST" they may execute.
Just because everyone else does it the WRONG way, doesn't make that behaviour correct.
I believe I have thus properly elaborated precisely what Mazegen wrote:
Nevím, jestli chápu, na co se vlastně ptáš... šlo mi jenom o to, aby si taky někdo někdy ověřil to, co píše.
Razz
Post 13 Dec 2005, 09:52
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
I wasn't asking about Fresh, of course I know it won't make any difference even if I replaced all TESTs with "CMP REG,0", I just asked which is better in general. Smile
Post 13 Dec 2005, 11:02
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
As for me, when I was learning assembly, the "XOR REG,REG" and "OR REG,REG" were so widely used, and I never saw any "MOV REG,0" nor "CMP REG,0" - and thus I have learned the XOR and OR used this way to be a kind of common language constructs. Though "MOV REG,0" is really more readable for someone who knows just basics of the assembly language, for those who learned like me, the "XOR REG,REG" is a kind of language construction like "INC REG" instead of "ADD REG,1". When I look at this instruction I don't see the XOR logical operation, I see the "zero this register, please" command.
Post 13 Dec 2005, 11:28
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Absolutely agree with you, Tomasz!
Post 13 Dec 2005, 12:13
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Tom, maybe this became Standard Practice because is agreed by a majority of programmers. Don't pretend that it's stubborness, simply we don't share your point.
i.e. when I want eax to be cleared, in my mind I didn't think on storing a zero to it. In my mind I have "clear eax". So why to store and create an immediate value simply to clear it?

Readability depends on how well documented are your data structures and functions (well crafted names help a lot) but a single opcode couldn't affect it, moreover if it's the Standard Practice.

XOR is a mnemonic of an opcode instructing the processor to do a certain task. A task that an assembly programmer must know and use as it fits. You will always have more tasks than opcodes, so there will be more than one situation when the mnemonic does not correspond exactly with the task you want to accomplish.
Post 13 Dec 2005, 13:14
View user's profile Send private message Yahoo Messenger Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
MazeGen wrote:

[lang id="cz"]
Nevím, jestli chápu, na co se vlastně ptáš... šlo mi jenom o to, aby si taky někdo někdy ověřil to, co píše.
[/lang]

Madis731 wrote:
Is something clear - did someone write something and is not responsible for it.... hmm.. my Czech and Slovakian is "a bit" rusty Very Happy

tom tobias wrote:

I believe I have thus properly elaborated precisely what Mazegen wrote:
Nevím, jestli chápu, na co se vlastně ptáš... šlo mi jenom o to, aby si taky někdo někdy ověřil to, co píše.
Razz

Laughing

It seems I can easily use my native language in this forum, because one has almost no problems with it!

As for XORing vs. MOVing, I agree that we saw it so many times in the old days, when code size was more important, that we don't need to think about what XOR EAX,EAX does. That's also why we don't use something like IMUL EAX,EAX,0.
Even though I don't much depend on code size, I still use shorter XOR EAX,EAX or SUB EAX,EAX instead of MOV EAX,0. Habit only.
Post 13 Dec 2005, 14:46
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
Tomasz Grysztar wrote:
... When I look at this instruction I don't see the XOR logical operation, I see the "zero this register, please" command.

PRECISELY!
In other words, you will NOT recognize the logical boolean operation when encountering:
XOR EAX, EDX.
You visual system, working as quickly as it can to keep up with your brain and your hands typing away, will FAIL TO RECOGNIZE that the second operand is NOT EAX, and a lot of time will be wasted trying to find a mistake that is probably not a typographical error.
Well, ok, you and Iron Felix are too clever, I agree, to fall for that error, but less clever people, (like me!) WILL WASTE INORDINATE amounts of time trying to understand what in the world is going on.....Unlike the situation with MazeGen's elegant poetry, which we all understood at a glance!
Rolling Eyes
Post 13 Dec 2005, 16:29
View user's profile Send private message Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
pelaillo wrote:
... in my mind I didn't think on storing a zero to it. In my mind I have "clear eax". So why to store and create an immediate value simply to clear it?
Readability depends on how well documented are your data structures and functions (well crafted names help a lot) but a single opcode couldn't affect it, moreover if it's the Standard Practice.
XOR is a mnemonic of an opcode instructing the processor to do a certain task. A task that an assembly programmer must know and use as it fits. You will always have more tasks than opcodes, so there will be more than one situation when the mnemonic does not correspond exactly with the task you want to accomplish.

I guess this is a brilliant argument, and I honestly have no good rejoinder. I confess defeat. I will attempt from now on, to avoid insisting that one must use MOV EAX, Zero, to ensure the most understandable, most obvious, most evident, most readable method of clearing a register.
Smile
Post 13 Dec 2005, 16:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  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.