# `loopne`

[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/loopne

**Loop while not equal**

Category: Control flow

Decrements rcx by one and jumps to the short target if the counter is non-zero and ZF is 0.

8086 and later

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

## 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

- `loopne imm8`
- `loopne imm8, ecx` · 386 and later
- `loopne imm8, rcx`

## 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`.

## Description

`loope` / `loopz` additionally require ZF = 1; `loopne` / `loopnz` require ZF = 0. The instructions do not change flags.

In 64-bit mode, the default counter is `rcx`; `a32` selects `ecx`. A 16-bit `cx` counter is unavailable in this mode. A zero initial counter wraps to its maximum value when decremented.

Write a target label or address. NASM calculates a signed 8-bit displacement from the end of the instruction (−128 through 127 bytes). There is no longer near encoding.

## Example

```x86
global _start

section .text
_start:
        mov rcx, 5          ; the counter this family reads
        xor rax, rax
again:
        add rax, rcx
        cmp rax, 0          ; the conditional forms read the flags too
        loopne again        ; jumps while rcx is not zero and the last comparison differed

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