# `jne`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/jne

**Jump if not equal (ZF == 0)**

Category: Control flow

Jumps to the target when the last comparison found not equal (ZF is 0).

8086 and later

Also written as: `jnz`

[Intel's reference: Jcc](https://intel.github.io/SDM/instruction/Jcc.html)

Used in: [Loops](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/loops.md) (x86-64 assembly), [Arrays, strings and the string instructions](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/arrays-strings-and-the-string-instructions.md) (x86-64 assembly), [Length of a string](https://asm-editor.specy.app/learn/courses/x86/examples/string-length.md) (x86-64 assembly), [Bubble sort](https://asm-editor.specy.app/learn/courses/x86/examples/bubble-sort.md) (x86-64 assembly), [Print an unsigned number in bases 2 through 36](https://asm-editor.specy.app/learn/courses/x86/examples/number-to-string.md) (x86-64 assembly), [Drawing shapes on the screen](https://asm-editor.specy.app/learn/courses/x86/examples/drawing-on-the-screen.md) (x86-64 assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/x86/examples/bouncing-ball.md) (x86-64 assembly), [Move a square with the keyboard](https://asm-editor.specy.app/learn/courses/x86/examples/keyboard-control.md) (x86-64 assembly), [Paint with the mouse](https://asm-editor.specy.app/learn/courses/x86/examples/mouse-paint.md) (x86-64 assembly), [Sampled sound](https://asm-editor.specy.app/learn/courses/x86/examples/sampled-sound.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

Reads: ZF

## Forms

- `jne short imm8`
- `jne imm`
- `jne near imm32` · 386 and later

## Operands

- `imm8`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. The displacement must fit a signed byte, `-128` to `127`.
- `imm`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. NASM selects a short or near encoding according to the target’s reach and any size constraint.
- `imm32`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. In 64-bit mode the encoded displacement is signed 32-bit, `-2147483648` to `2147483647`, even though the target address is 64-bit.

## Description

The condition reads the current flags, commonly set by `cmp` or `test`. Signed comparisons use SF and OF; unsigned comparisons use CF. The [condition-code table](https://asm-editor.specy.app/documentation/x86/registers/condition-codes.md) lists the flag tests and synonymous mnemonics.

Write the target label or address, such as `jne retry`. NASM calculates a displacement from the end of the jump. The short form reaches −128 through 127 bytes from that point; the longer near form in 64-bit mode uses a signed 32-bit displacement (about ±2 GiB). NASM normally selects the short form when possible. `short` requires the short range, while `strict near` keeps the longer form.

Conditional jumps have no register or memory-indirect target form. To conditionally reach an arbitrary 64-bit address, branch around an indirect `jmp`.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        cmp rax, 12         ; sets the flags the condition reads
        jne taken
        mov rbx, 1          ; runs when the condition is false
        jmp done
taken:
        mov rbx, 2          ; runs when it is true
done:

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall
```
