![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: May 2005
Location: Sweden
Posts: 281
Rep Power: 3
![]() |
[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://www.klarre.se |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: May 2005
Location: Sweden
Posts: 281
Rep Power: 3
![]() |
When CL = 0 of course...
__________________
http://www.klarre.se |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 9
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3
![]() |
Quote:
), 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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 799
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#7 | |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
Re: [x86]Instruction test setting the zero flag
Quote:
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. |
|
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 799
Rep Power: 3
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Boolean Flag issue | dwizzle13 | Visual Basic .NET | 4 | Dec 7th, 2006 5:58 PM |
| test score | brad sue | C++ | 7 | Oct 3rd, 2006 7:37 AM |
| test | lostcauz | Coder's Corner Lounge | 9 | Jul 18th, 2006 3:20 PM |
| Separating Axis Test. Desperate for help | xennon | C++ | 0 | Apr 24th, 2005 7:08 AM |