# `neg`

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

**Two's complement negation**

Category: Arithmetic

Replaces the operand with its two's complement, which inverts every bit and then adds one.

8086 and later · accepts the `lock` prefix with a memory operand

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

Used in: [A bouncing ball](https://asm-editor.specy.app/learn/courses/x86/examples/bouncing-ball.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 | depends on the result |
| PF | depends on the result |
| AF | depends on the result |
| ZF | depends on the result |
| SF | depends on the result |
| DF | not changed |
| OF | depends on the result |

## Forms

- `neg r/m` (8, 16, 32, 64)
  - `neg r/m8`
  - `neg r/m16`
  - `neg r/m32`: 386 and later
  - `neg r/m64`

## Operands

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

## Description

`NOT`, similarly, performs one's complement (inverts all
the bits).

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        neg rax

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