Pentium provides two types of instructions for accessing I/O ports:
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 InstructionsPentium 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:
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 InstructionsPentium provides the following block I/O instructions that can be used to move blocks of data between I/O ports and memory:
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: