OUT
The OUT instruction in Z80 assembly is used to send data to an I/O port. On the ZX Spectrum, this can be used to interact with various peripherals such as the speaker or a printer or other external devices.
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 OUT instruction, we are sending the next byte value from the chosen register to the peripheral that is listening.
Example
In the example above, the data is loaded into register A. We then send that data to a port which we specified as 254/$FE in this case.
| Instruction | Description | Opcode |
|---|---|---|
| OUT (C), A | Direct addressing a port (0-255) to send data from register A | D3?? |
| OUT (C), A | Using the C register we can use indirect addressing (0-255) to send data from register A | ED79 |
| OUT (C), B | Using the C register we can use indirect addressing (0-255) to send data from register B | ED41 |
| OUT (C), C | Using the C register we can use indirect addressing (0-255) to send data from register C | ED49 |
| OUT (C), D | Using the C register we can use indirect addressing (0-255) to send data from register D | ED51 |
| OUT (C), E | Using the C register we can use indirect addressing (0-255) to send data from register E | ED59 |
| OUT (C), H | Using the C register we can use indirect addressing (0-255) to send data from register H | ED61 |
| OUT (C), L | Using the C register we can use indirect addressing (0-255) to send data from register L | ED69 |