# `out`

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

**Output**

Category: Input/output

Writes A or another register to an I/O port, addressed by BC or by A and nn.

2 bytes

Used in: [Ports: in and out](https://asm-editor.specy.app/learn/courses/z80/talking-to-the-outside-world/ports-in-and-out.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), [Print a string](https://asm-editor.specy.app/learn/courses/z80/examples/hello-world.md) (Z80 assembly), [Read two numbers and print their sum](https://asm-editor.specy.app/learn/courses/z80/examples/sum-of-two-numbers.md) (Z80 assembly), [Convert a number to a string in any base](https://asm-editor.specy.app/learn/courses/z80/examples/number-to-string.md) (Z80 assembly), [Drawing shapes on the screen](https://asm-editor.specy.app/learn/courses/z80/examples/drawing-on-the-screen.md) (Z80 assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/z80/examples/bouncing-ball.md) (Z80 assembly), [Move a square with the keyboard](https://asm-editor.specy.app/learn/courses/z80/examples/keyboard-control.md) (Z80 assembly), [The snake game](https://asm-editor.specy.app/learn/courses/z80/examples/snake.md) (Z80 assembly), [Flappy ASM](https://asm-editor.specy.app/learn/courses/z80/examples/flappy-asm.md) (Z80 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| S | not changed |
| Z | not changed |
| H | not changed |
| P/V | not changed |
| N | not changed |
| C | not changed |

## Forms

- `out (nn), a` · 11 cycles · Writes A to the port whose address has A in the high byte and `nn` in the low byte.

- `out (c), r` · 12 cycles · Writes `r` to the port whose 16-bit address is in BC.
  - `out (c), b`
  - `out (c), c`
  - `out (c), d`
  - `out (c), e`
  - `out (c), h`
  - `out (c), l`
  - `out (c), a`

## Pseudo-instructions

The assembler also accepts these forms, which are other ways to write Z80 instructions. Open a row to see what each form becomes.

- `out nn, a` · 11 cycles · Writes A to the port whose address has A in the high byte and `nn` in the low byte.
  - `out nn, a` → `out (nn), a`

- `out (bc), r` · 12 cycles · Writes `r` to the port whose 16-bit address is in BC.
  - `out (bc), b` → `out (c), b`
  - `out (bc), c` → `out (c), c`
  - `out (bc), d` → `out (c), d`
  - `out (bc), e` → `out (c), e`
  - `out (bc), h` → `out (c), h`
  - `out (bc), l` → `out (c), l`
  - `out (bc), a` → `out (c), a`

## Undocumented

Zilog’s manual does not list these forms, but the Z80 runs them.

- `out (c), 0` · 12 cycles · Writes zero to the port whose 16-bit address is in BC.

## Pseudo-instructions · Undocumented

The assembler also accepts these forms, which are other ways to write Z80 instructions. Open a row to see what each form becomes. Zilog’s manual does not list these forms, but the Z80 runs them.

- `out (bc), 0` · 12 cycles · Writes zero to the port whose 16-bit address is in BC.
  - `out (bc), 0` → `out (c), 0`

## Operands

- [`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.
- `r`: An 8-bit register: `a`, `b`, `c`, `d`, `e`, `h` or `l`.

## Example

```z80
        .org 0x8000
        ld a, 'H'
        out (0x10), a   ; the character port prints the byte as a character
        halt
```
