From aldeid
Jump to navigation Jump to search
You are here:


  • The jnz (or jne) instruction is a conditional jump that follows a test.
  • It jumps to the specified location if the Zero Flag (ZF) is cleared (0).
  • jnz is commonly used to explicitly test for something not being equal to zero whereas jne is commonly found after a cmp instruction.


jnz location
jne location


Example 1

call   ds:InternetReadFile    ; call function InternetReadFile
mov    [ebp+var_4], eax       ; eax stores the result of the function
cmp    [ebp+var_4], 0         ; test if function return is 0
jnz    short loc_4010E5       ; if function InternetReadFile des not return 0, jump to loc_4010E5

Example 2

Following C code:

int x = 1;
int y = 2;
if(x == y){
    printf("x equals y.\n");
    printf("x is not equal to y.\n");

Can be disassembled as follows:

00401006        mov    [ebp+var_4], 1
0040100D        mov    [ebp+var_8], 2
00401014        mov    eax, [ebp+var_4]
00401017        cmp    eax, [ebp+var_8]            ; if x=y, the cmp will set the ZF to 1
0040101A        jnz    short loc_40102B            ; jump if ZF not set (if x!=y)
0040101C        push   offset aXEqualsY_           ; "x equals y.\n"
00401021        call   printf
00401026        add    esp, 4
00401029        jmp    short loc_401038
0040102B loc_40102B:
0040102B        push   offset aXIsNotEqualToY      ; "x is not equal to y.\n"
00401030        call   printf