在 x86 汇编代码中,
JE
和 JNE
与 JZ
和 JNZ
完全相同吗?
JE
和 JZ
只是同一事物的不同名称:
当 ZF
(“零”标志)等于 1 时条件跳转。
(同样,
JNE
和JNZ
只是条件跳转的不同名称
当 ZF
等于 0 时。)
您可以互换使用它们,但您应该根据情况使用它们 你在做什么:
JZ
/JNZ
更合适
对于等于零的东西:
dec ecx
jz counter_is_now_zero
JE
指令之后使用
JNE
和 CMP
更合适:
cmp edx, 42
je the_answer_is_42
(
CMP
指令执行减法,并丢弃结果的值,同时保留标志;这就是为什么当操作数相等时会得到ZF=1
和 ZF=0
当它们不存在时。)JE
和JZ
具有相同的操作码(74
用于rel8/0F 84
用于rel 16/32)还有JNE
和JNZ
() 75
for rel8 / 0F 85
for rel 16/32)共享操作码。
JE
和JZ
它们都检查ZF
(或零标志),尽管手册在第一个JE
rel8和JZ
rel8ZF
用法的描述上略有不同,但基本上它们是一样的。
以下是手册第 658-660 页的摘录:
Op Code | mnemonic | Description
-----------|-----------|-----------------------------------------------
74 cb | JE rel8 | Jump short if equal (ZF=1).
74 cb | JZ rel8 | Jump short if zero (ZF ← 1).
0F 84 cw | JE rel16 | Jump near if equal (ZF=1). Not supported in 64-bit mode.
0F 84 cw | JZ rel16 | Jump near if 0 (ZF=1). Not supported in 64-bit mode.
0F 84 cd | JE rel32 | Jump near if equal (ZF=1).
0F 84 cd | JZ rel32 | Jump near if 0 (ZF=1).
75 cb | JNE rel8 | Jump short if not equal (ZF=0).
75 cb | JNZ rel8 | Jump short if not zero (ZF=0).
0F 85 cd | JNE rel32 | Jump near if not equal (ZF=0).
0F 85 cd | JNZ rel32 | Jump near if not zero (ZF=0).
je : Jump if equal:
399 3fb: 64 48 33 0c 25 28 00 xor %fs:0x28,%rcx
400 402: 00 00
401 404: 74 05 je 40b <sims_get_counter+0x51>