Mnemonics

IN

Input and Output Group
Expansion:
IN
Usage:
in {r}, {c|00-FF}

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

; Example ld a, ($FE) ; read data from port 254 (keyboard or joystick input) in a, ($FE) ; store the input data in the A register

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

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

Example

; Example in a, ($FE) ; read the keyboard status rla ; rotate left through carry (to check bit 0) jr nc, NotPressed ; jump if not pressed ; key pressed, add your code here NotPressed: ; continue with your program

See also