# `neg`

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

Web page: https://asm-editor.specy.app/documentation/z80/instruction/neg

**Negate**

Category: Arithmetic

Negates A, giving its two's complement, which is the same as subtracting A from zero.

2 bytes · 8 cycles

Used in: [8-bit and 16-bit arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/arithmetic-logic-and-bits.md) (Z80 assembly), [The screen, keyboard and mouse through ports](https://asm-editor.specy.app/learn/courses/z80/talking-to-the-outside-world/screen-keyboard-and-mouse.md) (Z80 assembly), [The bigger of two numbers](https://asm-editor.specy.app/learn/courses/z80/examples/if-else.md) (Z80 assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/z80/examples/bouncing-ball.md) (Z80 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| S | set from the result |
| Z | set from the result |
| H | set from the result |
| P/V | holds the signed overflow |
| N | always 1 |
| C | set from the result |

## Forms

- `neg` · The contents of A are negated (two's complement). Operation is the same as subtracting A from zero.

## Example

```z80
        .org 0x8000
        ld a, 5
        neg
        halt
```
