IA-32 Assembly Language Reference Manual

I/O Instructions

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

Output from Port (out, outs)

out{bwl} 	imm8
out{bwl} 	(%dx)
outs{bwl}
Operation

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

[AL|AX|EAX] -> DX

ES:(E)DI -> DX

Description

Transfers a byte, word, or long from the memory address pointed to by the content of the AL, AX, or EAX register to the immediate 8-, 16-, or 32-bit port address.

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

The outs instruction transfers a string from the memory byte or word pointed to by the ES:source index to the port addressed in the DX register. Load the desired port number into the DX register and the desired source address into the SI or ESI index register before executing the outs 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 outs instruction for a block transfer of CX bytes or words.

Example

Transfer a word from the AX register into the 16-bit port address, 0xff:

outw $0xff

Transfer a long from the EAX register into the 32-bit port address specified by the DX register:

outl (%dx)

Transfer a string from the memory byte or word pointed to by the ES:source index to the port addressed in the DX register:

outsl