Accessing I/O Ports 
Pentium provides two types of instructions for accessing I/O ports:
Register I/O instructions
Block I/O instructions

Register I/O instructions are used to transfer data between the accumulator (Al, AX, or EAX) and an I/O port. Block I/O instructions are used for block transfer of data between memory and I/O ports.

Register I/O Instructions

Pentium provides two register I/O instructions: IN and OUT. The IN instruction is used to read data from an I/O port, and the OUT instruction is used to write data to an I/O port. A port address can be any value in the range 0 to FFFFH. The first 256 ports (i.e. ports with address in the range 0 to FFH) are directly addressable -i.e., the port address is given as part of the instruction- by IN and OUT instructions. Port addresses greater than 255 have to be stored in the DX register. Both IN/OUT instructions can be used to read/write 8-, 16-, or 32-bit data.

The syntax and semantics of the IN and OUT instructions are illustrated in the table below:

InstructionDescription
IN AL, port AL<-[port]
IN AL, DX AL<-[DX]
IN AX, port AX<-[port+1:port]
IN AX, DX AX<-[DX+1:DX]
IN EAX, port EAX<-[port+3:port]
IN EAX, DX AX<-[DX+3:DX]
OUT port, AL [port]<-AL
OUT DX, AL DX]<-AL
OUT port, AX [port+1:port]<-AX
OUT DX, AX [DX+1:DX]<-AX
OUT port, EAX [port+3:port]<-AX
OUT DX, EAX [DX+3:DX]<-AX

Note that the port address is the source in the IN instruction while it is the destination in the OUT instruction signifying the direction of the data movement. The accumulator operand, (AL, AX, or EAX), in the IN/OUT instructions determines whether a byte, word, or double word it to be Read/Written from/to the specified port.

For example, the instruction IN AX, 20 will read a word starting from port 20 and store it in AX. So, the AL register will get a byte from port 20 while the AH register will get a byte from port 21. Similarly, the instruction OUT 20, EAX will output a double word from register EAX to the ports [23:20].

Block I/O Instructions

Pentium provides the following block I/O instructions that can be used to move blocks of data between I/O ports and memory:
INS: INSB, INSW, INSD
OUTS: OUTSB. OUTSW, OUTSD

These instructions are similar to string instructions. Like the move string instructions, the repeat prefix REP can be used with these instructions. The port address has to be specified in the DX register.

For the INS instructions, a byte, word, or double word is input from the specified port in DX and stored in the corresponding locations pointed by ES:[DI]. Then, the DI index is either incremented (DF=0) or decremented (DF=1) by 1 (INSB), 2 (INSW), or 4 (INSD).

For the OUTS instructions, a byte, word, or double word is output from the locations pointed by DS:[SI] to the corresponding specified port in DX. Then, the SI index is either incremented (DF=0) or decremented (DF=1) by 1 (OUTSB), 2 (OUTSW), or 4 (OUTSD).

The syntax and semantics of the INS and OUTS instructions are illustrated in the table below:

InstructionDescription
INSB ES:[DI]<-[DX] ;
IF (DF=0)
DI=DI+1
ELSE
DI=DI-1
INSW ES:[DI+1:DI]<-[DX+1:DX] ;
IF (DF=0)
DI=DI+2
ELSE
DI=DI-2
INSD ES:[DI+3:DI]<-[DX+3:DX] ;
IF (DF=0)
DI=DI+4
ELSE
DI=DI-4
OUTSB [DX]<-DS:[SI] ;
IF (DF=0)
SI=SI+1
ELSE
SI=SI-1
OUTSW [DX+1:DX]<-DS:[SI+1:SI] ;
IF (DF=0)
SI=SI+2
ELSE
SI=SI-2
OUTSD [DX+3:DX]<-DS:[SI+3:SI] ;
IF (DF=0)
SI=SI+4
ELSE
SI=SI-4