# `cmova`

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

**Move if above (CF == 0 and ZF == 0)**

Category: Data movement

Copies the source into the destination when the last comparison found above (CF is 0 and ZF is 0).

Pentium Pro and later

Also written as: `cmovnbe`

[Intel's reference: CMOVcc](https://intel.github.io/SDM/instruction/CMOVcc.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: CF, ZF

## Forms

- `cmova reg, r/m` (16, 32, 64)
  - `cmova reg16, r/m16`
  - `cmova reg32, r/m32`
  - `cmova reg64, r/m64`

## Operands

- `reg`: A general-purpose register matching the operation’s size, for example `al`, `ax`, `eax` or `rax`.
- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.

## Description

The condition reads the current flags, as the conditional jumps do; the [condition-code table](https://asm-editor.specy.app/documentation/x86/registers/condition-codes.md) lists the tests and the other spellings of each.

The source is read whether or not the condition holds, so a memory source must be readable even when nothing moves. With 32-bit operands the destination is written either way: when the condition fails it keeps its low 32 bits, but the upper half of its 64-bit register is still cleared. The 16- and 64-bit forms leave a destination they do not move into untouched. There is no immediate source and no memory destination.

Every x86-64 processor has these instructions; some older 32-bit processors do not.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        mov rbx, 99
        cmp rax, 12
        cmova rax, rbx      ; copies rbx into rax only when the condition holds

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