IA-32 Assembly Language Reference Manual

Input from Port (in, ins)

in{bwl}  	imm8
in{bwl}  	(%dx)
ins{bwl}
Operation

imm[8|16|32] -> [AL|AX|EAX]

DX -> [AL|AX|EAX] DX -> ES:(E)DI

Description

in transfers a byte, word, or long from the immediate port into the byte, word, or long memory address pointed to by the AL, AX, or EAX register, respectively.

The second form of the in instruction transfers a byte, word, or long from a port (0 to 65535), specified in the DX register, into the byte, word, or long memory address pointed to by the AL, AX, or EAX register, respectively.

When an 8-bit port is specified, the upper-eight bits of the port address will be 0.

The ins instruction transfers a string from a port specified in the DX register to the memory byte or word pointed to by the ES:destination index. Load the desired port number into the DX register and the desired destination address into the DI or EDI index register before executing the ins instruction. After a transfer occurs, the destination-index register is automatically incremented or decremented as determined by the value of the direction flag (DF). The index register is incremented if DF = 0 (DF cleared by a cld instruction); it is decremented if DF = 1 (DF set by a std instruction). The increment or decrement count is 1 for a byte transfer, 2 for a word, and 4 for a long. Use the rep prefix with the ins instruction for a block transfer of CX bytes or words.

Example

Transfer an immediate 8-bit port address into the AL register:

inb $0xff

Transfer a 16-bit port address, specified in the DX register, into the AX register:

inw (%dx)

Transfer a string from the port address, specified in the DX register, into the ES:destination index register:

insl