Let’s say you want to check if EAX is equal to 5, and perform different actions based on the result of that comparison. An if-statement, in other words.
; … some code …
cmp eax, 5
je .if_true
; Code to run if comparison is false goes here.
jmp short .end_if
.if_true:
; Code to run if comparison is true goes here.
.end_if:
; … some code …
This will jump if the “equal flag” (also known as the “zero flag”) in the FLAGS register is set. This gets set as a result of arithmetic operations, or instructions like TEST and CMP.
For example: (if memory serves me right this is correct 🙂
cmp eax, ebx ; Subtract EBX from EAX — the result is discarded
; but the FLAGS register is set according to the result.
je .SomeLabel ; Jump to some label if the result is zero (ie. they are equal).
; This is also the same instruction as “jz”.