我会稍微详细地解释一下。
x86中通常有两种条件跳转:
算术跳转 - 如 JZ(等于跳转)、JC(进位跳转)、JNC(不进位跳转)等。
比较跳转 - 如 JE(相等跳转)、JB(低于跳转)、JAE(高于或等于跳转)等。
因此,在执行算术或逻辑指令后,只能使用第一种类型的跳转:
sub eax, ebx
jnz .result_is_not_zero
and ecx, edx
jz .the_bit_is_not_set
仅在 CMP 指令后使用第二组指令:
cmp eax, ebx
jne .eax_is_not_equal_to_ebx
cmp ecx, edx
ja .ecx_is_above_than_edx
这样一来,程序会更易读,你也就不会迷惑了。
需要注意的是,有时这些指令实际上是同义词。JZ == JE; JC == JB; JNC == JAE等等。完整的表格如下。正如您所看到的,只有16个条件跳转指令,但有30个助记符-它们提供了更易读的源代码编写方法:
Mnemonic Condition tested Description
jo OF = 1 overflow
jno OF = 0 not overflow
jc, jb, jnae CF = 1 carry / below / not above nor equal
jnc, jae, jnb CF = 0 not carry / above or equal / not below
je, jz ZF = 1 equal / zero
jne, jnz ZF = 0 not equal / not zero
jbe, jna CF or ZF = 1 below or equal / not above
ja, jnbe CF and ZF = 0 above / not below or equal
js SF = 1 sign
jns SF = 0 not sign
jp, jpe PF = 1 parity / parity even
jnp, jpo PF = 0 not parity / parity odd
jl, jnge SF xor OF = 1 less / not greater nor equal
jge, jnl SF xor OF = 0 greater or equal / not less
jle, jng (SF xor OF) or ZF = 1 less or equal / not greater
jg, jnle (SF xor OF) or ZF = 0 greater / not less nor equal