Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 11th, 2007, 7:34 AM   #1
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 349
Rep Power: 10 Klarre is on a distinguished road
[x86]Instruction test setting the zero flag

Was currently stepping through an application and found a piece of code that I could not understand.

My question is:
How can a TEST instruction set the ZERO flag when testing a byte with the same byte?

...
TEST, CL, CL
JE SHORT Application.004013B4 ; When will this row be executed?
...

Thanks for your help!

/Klarre
__________________
http://klarre.se/
Klarre is offline   Reply With Quote
Old Aug 11th, 2007, 7:44 AM   #2
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 349
Rep Power: 10 Klarre is on a distinguished road
When CL = 0 of course...
__________________
http://klarre.se/
Klarre is offline   Reply With Quote
Old Aug 11th, 2007, 10:24 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 8,368
Rep Power: 19 DaWei will become famous soon enoughDaWei will become famous soon enough
True. The TEST instruction ANDs the two operands and sets the flags accordingly. If the two operands are the same thing, the result will be zero only if the operand(s) are zero. It is really a dumb thing to do, in this case. Comparing CL to zero and jumping accordingly would be much clearer. But coders often do dumb things. That's why they wear dirty teeshirts and smell bad.
__________________
Contributor's Corner:
Politically Incorrect
DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 11th, 2007, 9:28 PM   #4
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,676
Rep Power: 11 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by DaWei
True. The TEST instruction ANDs the two operands and sets the flags accordingly. If the two operands are the same thing, the result will be zero only if the operand(s) are zero. It is really a dumb thing to do, in this case. Comparing CL to zero and jumping accordingly would be much clearer. But coders often do dumb things. That's why they wear dirty teeshirts and smell bad.
It might be like how, in the bad old days (which I'm sure you remember ), some assembly coders used XOR (E)AX, (E)AX rather than MOV (E)AX, 0 because it was one byte shorter. I don't have my asm resources handy, but I'd expect TEST reg, reg is a few bytes shorter than TEST reg, imm32, unless it stores the immediate value as an 8-bit quantity, and sign-extends it.

I agree though, the clarity leaves something to be desired. However, if this was compiler-generated assembly (as seems likely from the context), the programmer has no business expecting it to be clear if optimizations are enabled.
__________________
My microwave has settings for snake, gremlin, and puppy.
lectricpharaoh is offline   Reply With Quote
Old Mar 9th, 2008, 8:29 AM   #5
Irwin
Newbie
 
Join Date: Mar 2008
Posts: 9
Rep Power: 0 Irwin is on a distinguished road
Re: [x86]Instruction test setting the zero flag

Arguing about the readability of things such as 'XOR REG,REG'/'TEST REG,REG' is stupid. Someone should not be complaining about how they can understand somebody elses source when it's such a simple matter.

Furthermore, such instructions are not only shorter, they are a few clocks faster.
Irwin is offline   Reply With Quote
Old Mar 9th, 2008, 5:17 PM   #6
The Dark
Programming Guru

 
Join Date: Jun 2005
Posts: 1,631
Rep Power: 12 The Dark will become famous soon enoughThe Dark will become famous soon enough
Re: [x86]Instruction test setting the zero flag

Dredging up a six month old thread to call people stupid, and having your first two posts in a forum call people stupid, is a sure way to make a name for yourself. Unfortunately, that name isn't a very nice one.
The Dark is offline   Reply With Quote
Old Mar 10th, 2008, 3:33 AM   #7
Irwin
Newbie
 
Join Date: Mar 2008
Posts: 9
Rep Power: 0 Irwin is on a distinguished road
Re: [x86]Instruction test setting the zero flag

Quote:
Originally Posted by The Dark View Post
Dredging up a six month old thread to call people stupid, and having your first two posts in a forum call people stupid, is a sure way to make a name for yourself. Unfortunately, that name isn't a very nice one.
Fortunately for me, the first page goes back further than 6 months Albeit the fact that the main benefactors of the thread probably won't see it, others who are looking into the subject probably will. So I'm not too concerned about making a name for myself, good or bad.

For you to even bring up the argument of repertoire in a forum which is essentially made for helping others is laughable, so please; consider this my first and only response to you.
Irwin is offline   Reply With Quote
Old Mar 10th, 2008, 4:09 AM   #8
The Dark
Programming Guru

 
Join Date: Jun 2005
Posts: 1,631
Rep Power: 12 The Dark will become famous soon enoughThe Dark will become famous soon enough
Re: [x86]Instruction test setting the zero flag

I wasn't having a go at you because you haven't posted much, if that is what you mean by "argument of repertoire". Extra helpers here are always welcome. Calling people who are asking questions and people who are answering them "stupid" is not helping, in fact it is a great hindrance to a forum such as this as it is likely to turn people away.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Boolean Flag issue dwizzle13 Visual Basic .NET 4 Dec 7th, 2006 6:58 PM
test score brad sue C++ 7 Oct 3rd, 2006 8:37 AM
test lostcauz Coder's Corner Lounge 9 Jul 18th, 2006 4:20 PM
Separating Axis Test. Desperate for help xennon C++ 0 Apr 24th, 2005 8:08 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:05 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC