Mnemonics

OUT

Input and Output Group
Expansion:
OUT
Usage:
out {0-255|r}, {r}

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

; Example ld a, ($01) ; load value to be sent into register a out ($FE), a ; send the value in register a to port 254 ($FE)

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.

Z80.CPU instructions
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

Example

; Example ld a, $10 ; load the value to enable the beeper into register A out ($FE), a ; send the value to port 254 to turn on the beeper nop ; short delay (No Operation) nop ; short delay (No Operation) ld a, $00 ; load the value to disable the beeper into register A out ($FE), a ; send the value to port 254 to turn off the beeper

See also