Furthermore, with the CMP instruction, the destination operand doesn't change. Just the flags.
Let me illustrate. Let's say EAX = 00000005
and EBX = 00000005
. If we do this arithmetic operation:
CMP EAX, EBX
What's happening, is in effect this:
EAX - EBX
---->
00000005 - 00000005
Since the result would be 0
, but we don't change the destination operand in a CMP instruction, the zero flag is set to 1
(since it's true).
So, as we saw, depending on the result of the previous arithmetic operation, flags can be set accordingly:

CMP
sets all the flags based on the intermediate results ofSUB
that it performs. read here: godevtool.com/GoasmHelp/usflags.htm – Paweł Łukasik Mar 10 '19 at 9:56cmp
documentation first: The comparison is performed by subtracting the second operand from the first operand and then setting the status flags in the same manner as theSUB
instruction.. But that's not a good way to check whether a register is zero or not – phuclv Mar 11 '19 at 16:13