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.