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:

CMPsets all the flags based on the intermediate results ofSUBthat it performs. read here: http://www.godevtool.com/GoasmHelp/usflags.htm – Paweł Łukasik Mar 10 '19 at 09:56cmpdocumentation 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 theSUBinstruction.. But that's not a good way to check whether a register is zero or not – phuclv Mar 11 '19 at 16:13