OUT

Output to Port

Opcodes

Hex Mnemonic Encoding Long Mode Legacy Mode Description
EF OUT DX, EAX B Valid Valid Output doubleword in EAX to I/O port address in DX.
EF OUT DX, AX B Valid Valid Output word in AX to I/O port address in DX.
EE OUT DX, AL B Valid Valid Output byte in AL to I/O port address in DX.
E7 ib OUT imm8, EAX A Valid Valid Output doubleword in EAX to I/O port address imm8.
E7 ib OUT imm8, AX A Valid Valid Output word in AX to I/O port address imm8.
E6 ib OUT imm8, AL A Valid Valid Output byte in AL to I/O port address imm8.

Instruction Operand Encoding

Op/En Operand 0 Operand 1 Operand 2 Operand 3
A NA NA NA imm8
B NA NA NA NA

Description

Copies the value from the second operand (source operand) to the I/O port specified with the destination operand (first operand). The source operand can be register AL, AX, or EAX, depending on the size of the port being accessed (8, 16, or 32 bits, respectively); the destination operand can be a byte-immediate or the DX register. Using a byte immediate allows I/O port addresses 0 to 255 to be accessed; using the DX register as a source operand allows I/O ports from 0 to 65,535 to be accessed.

The size of the I/O port being accessed is determined by the opcode for an 8-bit I/O port or by the operand-size attribute of the instruction for a 16- or 32-bit I/O port.

At the machine code level, I/O instructions are shorter when accessing 8-bit I/O ports. Here, the upper eight bits of the port address will be 0.

This instruction is only useful for accessing I/O ports located in the processor's I/O address space. See Chapter 13, "Input/Output," in theIntel®64 and IA-32 Architectures Software Developer's Manual, Volume 1, for more information on accessing I/O ports in the I/O address space.

This instruction's operation is the same in non-64-bit modes and 64-bit mode.

Pseudo Code

IF ((PE = 1) and ((CPL > IOPL) or (VM = 1)))
	(* Protected mode with CPL > IOPL or virtual-8086 mode *)
	IF (Any I/O Permission Bit for I/O port being accessed = 1)
		(* I/O operation is not allowed *)
		#GP(0);
	ELSE
		(* I/O operation is allowed *)
		DEST = SRC; (* Writes to selected I/O port *)
	FI;
ELSE
	(Real Mode or Protected Mode with CPL <= IOPL *)
	DEST = SRC; (* Writes to selected I/O port *)
FI;

Flags Affected

None.

Exceptions

64-Bit Mode Exceptions

Same as protected mode exceptions.

Compatibility Mode Exceptions

Same as protected mode exceptions.

Virtual-8086 Mode Exceptions

Exception Description
#UD If the LOCK prefix is used.
#PF(fault-code) If a page fault occurs.
#GP(0) If any of the I/O permission bits in the TSS for the I/O port being accessed is 1.

Real-Address Mode Exceptions

Exception Description
#UD If the LOCK prefix is used.

Protected Mode Exceptions

Exception Description
#UD If the LOCK prefix is used.
#GP(0) If the CPL is greater than (has less privilege) the I/O privilege level (IOPL) and any of the corresponding I/O permission bits in TSS for the I/O port being accessed is 1.