# `neg`

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

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

**Negate**

Category: Arithmetic

Replaces the destination operand with zero minus its value, at the given size.

Sizes .b .w .l, .w by default

Used in: [The screen, keyboard and mouse through traps](https://asm-editor.specy.app/learn/courses/m68k/talking-to-the-outside-world/screen-keyboard-and-mouse.md) (M68K assembly), [The bigger of two numbers](https://asm-editor.specy.app/learn/courses/m68k/examples/if-else.md) (M68K assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/m68k/examples/bouncing-ball.md) (M68K assembly), [Sampled sound](https://asm-editor.specy.app/learn/courses/m68k/examples/sampled-sound.md) (M68K assembly), [Numbers and sizes](https://asm-editor.specy.app/learn/courses/assembly-basics/introduction/numbers-and-sizes.md) (Assembly basics)

## Flags

| Flag | Effect |
| --- | --- |
| X | set from the result |
| N | set from the result |
| Z | set from the result |
| V | set from the result |
| C | set from the result |

## Forms

- `neg <ea>`
  - Operand: Dn, (An), (An)+, -(An), d(An), d(An,Xn), abs (data alterable)

## Operands

- [`<ea>`](https://asm-editor.specy.app/documentation/m68k/addressing-mode.md): An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With `opt p=68020`, an allowed `d(An,Xn)` or `d(PC,Xn)` mode also permits the corresponding 68020 indexed and memory indirect forms. See [68020 addressing](https://asm-editor.specy.app/documentation/m68k/addressing-mode/68020.md).

## Example

```m68k
move.b #1, d0
neg.b d0 ; d0 low byte = $FF (-1)

move.l #$80, d1
neg.b d1 ; $80 stays $80: +128 does not fit in a signed byte, so V is set

* --- Negating zero ---
move.l #0, d2
neg.l d2 ; d2 = 0, Z flag set

* --- Size matters ---
move.l #$100, d3
neg.b d3 ; only negates low byte (was $00)
```
