80386 Programmer's Reference Manual -- Opcode INS

INS/INSB/INSW/INSD -- Input from Port to String

OpcodeInstructionClocks DescriptionExample
6Cinsb 15,pm=9*/29** Input byte from port DX into ES:(E)DIinsb
6Dinsw 15,pm=9*/29** Input word from port DX into ES:(E)DIinsw
6Dinsl 15,pm=9*/29** Input dword from port DX into ES:(E)DIinsl


   *If CPL <= IOPL
  **If CPL > IOPL or if in virtual 8086 mode


IF AddressSize = 16
THEN use DI for dest-index;
ELSE (* AddressSize = 32 *)
   use EDI for dest-index;
IF (PE = 1) AND ((VM = 1) OR (CPL > IOPL))
THEN (* Virtual 8086 mode, or protected mode with CPL > IOPL *)
   IF NOT I-O-Permission (SRC, width(SRC))
   THEN #GP(0);
IF byte type of instruction
   ES:[dest-index] := [DX]; (* Reads byte at DX from I/O address space *)
   IF DF = 0 THEN IncDec := 1 ELSE IncDec := -1; FI;
IF OperandSize = 16
   ES:[dest-index] := [DX]; (* Reads word at DX from I/O address space *)
   IF DF = 0 THEN IncDec := 2 ELSE IncDec := -2; FI;
IF OperandSize = 32
   ES:[dest-index] := [DX]; (* Reads dword at DX from I/O address space *)
   IF DF = 0 THEN IncDec := 4 ELSE IncDec := -4; FI;
dest-index := dest-index + IncDec;


INS transfers data from the input port numbered by the DX register to the memory byte or word at ES:dest-index. The memory operand must be addressable from ES; no segment override is possible. The destination register is DI if the address-size attribute of the instruction is 16 bits, or EDI if the address-size attribute is 32 bits.

INS does not allow the specification of the port number as an immediate value. The port must be addressed through the DX register value. Load the correct value into DX before executing the INS instruction.

The destination address is determined by the contents of the destination index register. Load the correct index into the destination index register before executing INS.

After the transfer is made, DI or EDI advances automatically. If the direction flag is 0 (CLD was executed), DI or EDI increments; if the direction flag is 1 (STD was executed), DI or EDI decrements. DI increments or decrements by 1 if a byte is input, by 2 if a word is input, or by 4 if a doubleword is input.

INSB, INSW and INSD are synonyms of the byte, word, and doubleword INS instructions. INS can be preceded by the REP prefix for block input of CX bytes or words. Refer to the REP instruction for details of this operation.

Flags Affected


Protected Mode Exceptions

#GP(0) if CPL is numerically greater than IOPL and any of the corresponding I/O permission bits in TSS equals 1; #GP(0) if the destination is in a nonwritable segment; #GP(0) for an illegal memory operand effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page fault

Real Address Mode Exceptions

Interrupt 13 if any part of the operand would lie outside of the effective address space from 0 to 0FFFFH

Virtual 8086 Mode Exceptions

#GP(0) fault if any of the corresponding I/O permission bits in TSS equals 1; #PF(fault-code) for a page fault

[Home Page dell'ITIS "Fermi"] [80386 Programmer's Reference Manual Index] [Previous] [Next]