JE/JNE和JZ/JNZ的区别。

时间:2021-08-18 03:16:59

In x86 assembly code, are JE and JNE exactly the same as JZ and JNZ?

在x86汇编代码中,JE和JNE是否与JZ和JNZ完全相同?

2 个解决方案

#1


82  

JE and JZ are just different names for exactly the same thing: a conditional jump when ZF (the "zero" flag) is equal to 1.

JE和JZ是完全相同的名称:当ZF(“0”标志)等于1时的条件跳转。

(Similarly, JNE and JNZ are just different names for a conditional jump when ZF is equal to 0.)

(类似地,当ZF = 0时,JNE和JNZ只是条件跳转的不同名称。)

You could use them interchangeably, but you should use them depending on what you are doing:

你可以交替使用它们,但是你应该根据你在做什么来使用它们:

  • JZ/JNZ are more appropriate when you are explicitly testing for something being equal to zero:

    当您显式地测试某个值为0时,JZ/JNZ更合适:

    dec  ecx
    jz   counter_is_now_zero
    
  • JE and JNE are more appropriate after a CMP instruction:

    在CMP指导下,我和JNE更合适:

    cmp  edx, 42
    je   the_answer_is_42
    

    (A CMP instruction performs a subtraction, and throws the value of the result away, while keeping the flags; which is why you get ZF=1 when the operands are equal and ZF=0 when they're not.)

    (CMP指令执行减法,并抛出结果的值,同时保留标记;这就是为什么当操作数相等时,ZF=1,而当不相等时,ZF=0)

#2


30  

From the Intel's manual - Instruction Set Reference, the JE and JZ have the same opcode (74 for rel8 / 0F 84 for rel 16/32) also JNE and JNZ (75 for rel8 / 0F 85 for rel 16/32) share opcodes.

根据Intel的手册-指令集参考,JE和JZ具有相同的操作码(rel8 / 0F 84代表rel 16/32), JNE和JNZ(75代表rel8 / 0F 85代表rel 16/32)共享操作码。

JE and JZ they both check for the ZF (or zero flag), although the manual differs slightly in the descriptions of the first JE rel8 and JZ rel8 ZF usage, but basically they are the same.

JE和JZ它们都检查ZF(或0标志),尽管手册中对第一个JE rel8和JZ rel8 ZF用法的描述略有不同,但基本上它们是相同的。

Here is an extract from the manual's pages 464, 465 and 467.

以下是手册第464、465和467页的摘录。

 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).

#1


82  

JE and JZ are just different names for exactly the same thing: a conditional jump when ZF (the "zero" flag) is equal to 1.

JE和JZ是完全相同的名称:当ZF(“0”标志)等于1时的条件跳转。

(Similarly, JNE and JNZ are just different names for a conditional jump when ZF is equal to 0.)

(类似地,当ZF = 0时,JNE和JNZ只是条件跳转的不同名称。)

You could use them interchangeably, but you should use them depending on what you are doing:

你可以交替使用它们,但是你应该根据你在做什么来使用它们:

  • JZ/JNZ are more appropriate when you are explicitly testing for something being equal to zero:

    当您显式地测试某个值为0时,JZ/JNZ更合适:

    dec  ecx
    jz   counter_is_now_zero
    
  • JE and JNE are more appropriate after a CMP instruction:

    在CMP指导下,我和JNE更合适:

    cmp  edx, 42
    je   the_answer_is_42
    

    (A CMP instruction performs a subtraction, and throws the value of the result away, while keeping the flags; which is why you get ZF=1 when the operands are equal and ZF=0 when they're not.)

    (CMP指令执行减法,并抛出结果的值,同时保留标记;这就是为什么当操作数相等时,ZF=1,而当不相等时,ZF=0)

#2


30  

From the Intel's manual - Instruction Set Reference, the JE and JZ have the same opcode (74 for rel8 / 0F 84 for rel 16/32) also JNE and JNZ (75 for rel8 / 0F 85 for rel 16/32) share opcodes.

根据Intel的手册-指令集参考,JE和JZ具有相同的操作码(rel8 / 0F 84代表rel 16/32), JNE和JNZ(75代表rel8 / 0F 85代表rel 16/32)共享操作码。

JE and JZ they both check for the ZF (or zero flag), although the manual differs slightly in the descriptions of the first JE rel8 and JZ rel8 ZF usage, but basically they are the same.

JE和JZ它们都检查ZF(或0标志),尽管手册中对第一个JE rel8和JZ rel8 ZF用法的描述略有不同,但基本上它们是相同的。

Here is an extract from the manual's pages 464, 465 and 467.

以下是手册第464、465和467页的摘录。

 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).