The IN and OUT instructions
Input and output of data through I/O ports.
The IN instruction format
| Instruction | Description |
|---|---|
| IN AL, imm8 | Input a byte from port imm8 into AL. |
| IN AX, imm8 | Input a word from port imm8 into AX. |
| IN AL, DX | Input a byte from the port whose address is in DX into AL. |
| IN AX, DX | Input a word from the port whose address is in DX into AX. |
Copies data from the I/O port whose address is specified in the second operand into the AL or AX register (the first operand). The port address can be specified directly (imm8 for ports 0-255) or through the DX register (for ports 0-65535).
The OUT instruction format
| Instruction | Description |
|---|---|
| OUT imm8, AL | Output a byte from AL to port imm8. |
| OUT imm8, AX | Output a word from AX to port imm8. |
| OUT DX, AL | Output a byte from AL to the port whose address is in DX. |
| OUT DX, AX | Output a word from AX to the port whose address is in DX. |
Copies data from the AL or AX register (the second operand) to the I/O port whose address is specified in the first operand.
Usage example
Reading a scan code from the keyboard port (60h) and outputting the value to the sound generator port (42h).
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov dx, 60h ; Load the keyboard port address into DX in al, dx ; Read a byte from port 60h (scan code) into AL mov dx, 42h ; Load the timer port address (channel 2) into DX out dx, al ; Output the byte read into port 42h mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Processor status flags
CF
NoPF
NoAF
NoZF
NoSF
NoTF
NoIF
NoDF
NoOF
No