View Single Post
Old Aug 11th, 2007, 8:28 PM   #4
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote