(ia32) for example,
test $eax, $eax
why would you ever want to do that? it does $eax & $eax, right? shouldn’t this always set the flag register to say that they are equal..?
addendum:
so test will set the ZF (as mentioned below) if the register is zero. so is test (as used above) mainly just used to tell if a register is empty? and ZF is set if so?
It’ll set
ZF(the zero flag) if the register is zero. That’s probably what it’s most commonly used to test. It’ll also set other flags appropriately, but there’s probably far less use for those.Also, I should mention that
testdoesn’t really perform a comparison – it performs a bitwiseandoperation (throwing away the result, except for the flags).To perform a comparison of the operands, the
cmpinstruction would be used, which performs asuboperation, throwing away the results except for the flags. You are correct that awould not have much point, as the flags would be set according to a zero result every time.