IN
The IN instruction in Z80 assembly is used to read data from an I/O port. On the ZX Spectrum, this can be used to interact with various peripherals such as the keyboard or certain expansion devices (including joysticks).
Note that the port range available is 00-FF (0-255) for direct and indirect addressing.
This flexibility allows you to interact with a wide range of peripherals and devices connected to the ZX Spectrum. Each time we use the IN instruction, we are asking for the next value that the peripheral has to send and we store each request in our chosen register.
Example
In the example above, the input data from the specified I/O port (254, which is commonly used for keyboard and joystick inputs) is loaded into the accumulator (register A).
| Instruction | Description | Opcode |
|---|---|---|
| IN A, {??} | Direct addressing a port (0-255) to read data into register A | DB?? |
| IN A, (C) | Using the C register we can use indirect addressing (0-255) to read data into register A | ED78 |
| IN B, (C) | Using the C register we can use indirect addressing (0-255) to read data into register B | ED40 |
| IN C, (C) | Using the C register we can use indirect addressing (0-255) to read data into register C | ED48 |
| IN D, (C) | Using the C register we can use indirect addressing (0-255) to read data into register D | ED50 |
| IN E, (C) | Using the C register we can use indirect addressing (0-255) to read data into register E | ED58 |
| IN H, (C) | Using the C register we can use indirect addressing (0-255) to read data into register H | ED60 |
| IN L, (C) | Using the C register we can use indirect addressing (0-255) to read data into register L | ED68 |