# `in`

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

**Input**

Category: Input/output

Reads a byte from an I/O port into a register, with the 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), [Read two numbers and print their sum](https://asm-editor.specy.app/learn/courses/z80/examples/sum-of-two-numbers.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), [Play a tune](https://asm-editor.specy.app/learn/courses/z80/examples/play-a-tune.md) (Z80 assembly), [Chiptune](https://asm-editor.specy.app/learn/courses/z80/examples/chiptune.md) (Z80 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| S | depends on the result |
| Z | depends on the result |
| H | always 0 |
| P/V | holds the parity of the result |
| N | always 0 |
| C | not changed |

## Forms

- `in a, (nn)` · 11 cycles · Flags: S: not changed, Z: not changed, H: not changed, P/V: not changed, N: not changed, C: not changed · Reads a byte into A from the port whose address has A in the high byte and `nn` in the low byte.

- `in r, (c)` · 12 cycles · Reads a byte into `r` from the port whose 16-bit address is in BC.
  - `in b, (c)`
  - `in c, (c)`
  - `in d, (c)`
  - `in e, (c)`
  - `in h, (c)`
  - `in l, (c)`
  - `in a, (c)`

## 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.

- `in a, nn` · 11 cycles · Flags: S: not changed, Z: not changed, H: not changed, P/V: not changed, N: not changed, C: not changed · Reads a byte into A from the port whose address has A in the high byte and `nn` in the low byte.
  - `in a, nn` → `in a, (nn)`

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

## Undocumented

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

- `in (c)` · 12 cycles · Reads a byte from the port whose 16-bit address is in BC and uses it only to set the flags.

## 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.

- `in (bc)` · 12 cycles · Reads a byte from the port whose 16-bit address is in BC and uses it only to set the flags.
  - `in (bc)` → `in (c)`

## 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
        in a, (0x11)    ; ask the console for a number
        add a, a        ; double it
        out (0x11), a   ; print the result
        halt
```
