•They are equivalent if you want to test for zero, but
CMP instruction affects more
flags
•TEST EAX, EAX
•CMP EAX, 0
•CMP instruction is used to compare for inequality
•CMP EAX, 0 ; > 0 or < 0 ?
•TEST instruction is used to see if individual bit is
set
•TEST EAX, 2 ; 2
== 0010bin or in C
language: if (var & 0x2)
•
•Warning: TEST
instruction cannot be used to compare for equality or inequality:
•Suppose EAX has 2
•TEST EAX, 4 ; 0010bin AND 0100bin = 0000bin (ZF is set)
•TEST EAX, 6 ; 0010bin AND 0110bin = 0010bin (ZF is cleared)