When you use the cmp instruction, it is essentially just subtracting whatever you pass to it. It is checking if the both are equal, and mathematically an easy way to do this is by subtracting it by the other argument. Now if they are actually equal, the subtraction result will be zero, right? So it just subtracts, and if they are equal and the result is zero, it sets the Zero Flag (ZF) to 1. In x86_64 this flag lives in the flags register (RFLAGS), a special register that holds several status flags like this one. But here’s the stealthy part: cmp doesn’t save the subtraction result anywhere, it only updates the flags. So later if you want to perform some function or do something else if they are not equal, you can do that if the Zero Flag is 0! And do something if the Zero Flag is 1. So it is 1 if they are equal, and 0 if they are not equal.

Now let’s slow down and dive deeper at the same time. When the cmp instruction sets the flags, you very well might want to do something, otherwise what’s the purpose of comparing! But before that recall that we have a jump instruction, which jumps to the specified label (a label is literally just a label for a bunch of code, you can specify a label by almost any name and following it a colon. And it’s a good practice to write whatever is inside that label in an indented manner), instead of saying just do this if equal to and do this if not equal to as in Python or other languages. Back to what we were discussing, so there are two possibilities you might want to choose. The first one is jump if the Zero Flag is 1, meaning the subtraction result was zero. In assembly, or in x86_64 to be more specific, you can do this using the je instruction. This means “jump if equal”, you can follow the instruction with the label of something you want to do when equal. Now the other situation, quite obviously, is the “jump if not equal” situation. You can do this using the jne instruction, which jumps when the Zero Flag is 0. You can follow this instruction with whatever label or the bunch of code you want to execute if the provided things are not equal.