# `sbc`

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

**Subtract with carry**

Category: Arithmetic

Subtracts a value and the carry flag C from A, or a register pair and C from HL.

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), [call, ret and passing values](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/call-ret-and-passing-values.md) (Z80 assembly), [Length of a string](https://asm-editor.specy.app/learn/courses/z80/examples/string-length.md) (Z80 assembly), [Reverse a string in place](https://asm-editor.specy.app/learn/courses/z80/examples/reverse-a-string.md) (Z80 assembly), [Flappy bird](https://asm-editor.specy.app/learn/courses/z80/examples/flappy-bird.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

- `sbc a, r` · 1 byte · 4 cycles · Subtracts `r` and the carry flag from A.
  - `sbc a, b`
  - `sbc a, c`
  - `sbc a, d`
  - `sbc a, e`
  - `sbc a, h`
  - `sbc a, l`
  - `sbc a, a`

- `sbc a, (hl)` · 1 byte · 7 cycles · Subtracts (HL) and the carry flag from A.

- `sbc a, nn` · 2 bytes · 7 cycles · Subtracts `nn` and the carry flag from A.

- `sbc a, (ix+dd)` · 3 bytes · 19 cycles · Subtracts the value pointed to by IX plus `dd` and the carry flag from A.
  - `sbc a, (ix+dd)`
  - `sbc a, (iy+dd)`

- `sbc hl, rr` · 2 bytes · 15 cycles · Subtracts `rr` and the carry flag from HL.
  - `sbc hl, bc`
  - `sbc hl, de`
  - `sbc hl, hl`
  - `sbc hl, sp`

## Pseudo-instructions

Other spellings the assembler accepts; each form shows the instruction it becomes.

- `sbc r` · 1 byte · 4 cycles · Subtracts `r` and the carry flag from A.
  - `sbc b` → `sbc a, b`
  - `sbc c` → `sbc a, c`
  - `sbc d` → `sbc a, d`
  - `sbc e` → `sbc a, e`
  - `sbc h` → `sbc a, h`
  - `sbc l` → `sbc a, l`
  - `sbc a` → `sbc a, a`

- `sbc (hl)` · 1 byte · 7 cycles · Subtracts (HL) and the carry flag from A.
  - `sbc (hl)` → `sbc a, (hl)`

- `sbc nn` · 2 bytes · 7 cycles · Subtracts `nn` and the carry flag from A.
  - `sbc nn` → `sbc a, nn`

- `sbc (ix+dd)` · 3 bytes · 19 cycles · Subtracts the value pointed to by IX plus `dd` and the carry flag from A.
  - `sbc (ix+dd)` → `sbc a, (ix+dd)`
  - `sbc (iy+dd)` → `sbc a, (iy+dd)`

## Undocumented

Left out of Zilog's manual, but the Z80 runs them, and so does this emulator.

- `sbc a, ixh/l` · 2 bytes · 8 cycles · Subtracts `ixh/l` and the carry flag from A.
  - `sbc a, ixh`
  - `sbc a, ixl`
  - `sbc a, iyh`
  - `sbc a, iyl`

## Pseudo-instructions · Undocumented

Other spellings the assembler accepts; each form shows the instruction it becomes. Left out of Zilog's manual, but the Z80 runs them, and so does this emulator.

- `sbc ixh/l` · 2 bytes · 8 cycles · Subtracts `ixh/l` and the carry flag from A.
  - `sbc ixh` → `sbc a, ixh`
  - `sbc ixl` → `sbc a, ixl`
  - `sbc iyh` → `sbc a, iyh`
  - `sbc iyl` → `sbc a, iyl`

## Operands

- `r`: An 8-bit register: `a`, `b`, `c`, `d`, `e`, `h` or `l`.
- [`(hl)`](https://asm-editor.specy.app/documentation/z80/registers/operand-hl.md): The byte in memory at the address stored in `hl`.
- [`nn`](https://asm-editor.specy.app/documentation/z80/registers/operand-nn.md): An 8-bit immediate value, `0` to `255` or `-128` to `127`, written as a number, character constant or symbol.
- [`(ix+dd)`](https://asm-editor.specy.app/documentation/z80/registers/operand-ix-dd.md): The byte in memory at `ix + dd`, where `dd` is a signed displacement from `-128` to `127`, for example `(ix+5)` or `(ix-3)`. `(iy+dd)` works the same way.
- `rr`: A register pair: `bc`, `de`, `hl` or `sp`.
- [`ixh/l`](https://asm-editor.specy.app/documentation/z80/registers/register-ixh.md): The high or low byte of `ix`: `ixh` or `ixl`. For `iy`, use `iyh` or `iyl`.

## Example

```z80
        .org 0x8000
        ld a, 5
        ld b, 3
        sbc a, b
        halt
```
