# `cmpi`

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

**Compare immediate**

Category: Comparison

Subtracts the immediate value from the second operand and sets the flags, leaving the operand unchanged.

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

Used in: [Branching and control flow](https://asm-editor.specy.app/learn/courses/assembly-basics/think-in-assembly/branching-and-control-flow.md) (Assembly basics)

## Flags

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

## Forms

- `cmpi #imm, <ea>`
  - Destination: Dn, (An), (An)+, -(An), d(An), d(An,Xn), abs (data alterable)

## 68020 only

These forms require the 68020. Select `opt p=68020` before any code or data.

- `cmpi #imm, <ea>`
  - Destination: d(PC), d(PC,Xn)

## Operands

- [`#imm`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/immediate.md): An immediate value written after `#`: a number, character or label, such as `#10`, `#$FF` or `#'a'`. It must fit the operation’s size: byte `-128` to `255`, word `-32768` to `65535`, or long `-2147483648` to `4294967295`; signed and unsigned spellings are accepted.
- [`<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).

## Description

The operand and X are unchanged.

On the 68020, the second operand may also be PC-relative memory, as in `cmpi.w #1, flag(pc)`.

## Example

```m68k
move.l #10, d0
cmpi.w #10, d0
seq d1 ; d1 = $FF (equal)

move.l #5, d2
cmpi.w #10, d2
slt d3 ; d3 = $FF (5 < 10)
sgt d4 ; d4 = $00
```
