6-1 FUNDAMENTAL I/O CONSIDERATIONS

On the 8086, all programmed communications with the I/O ports is done by the IN and OUT instructions defined in Fig. 6-2.

                   Figure 6-2 IN and OUT instructions

       Name               Mnemonic and Format           Description
Input
  Long form, byte         IN AL, PORT                   (AL) <- (PORT)
  Long form, word         IN AX, PORT                   (AX) <- (PORT+1:PORT)
  Short form, byte        IN AL, DX                     (AL) <- ((DX))
  Short form, word        IN AX, DX                     (AX) <- ((DX)+1:(DX))
Output
  Long form, byte         OUT PORT, AL                  (PORT) <- (AL)
  Long form, word         OUT PORT, AX                  (PORT+1:PORT) <- (AX)
  Short form, byte        OUT DX, AL                    ((DX)) <- (AL)
  Short form, word        OUT DX, AX                    ((DX)+1:(DX)) <- (AX)

  Note: PORT is a constant ranging from 0 to 255
  Flags: No flags are affected
  Addressing modes: Operands are limited as indicated above.

If the second operand is DX, then there is only one byte in the instruction and the contents of DX are used as the port address. Unlike memory addressing, the contents of DX are not modified by any segment register. This allows variable access to I/O ports in the range 0 to 64K. The machine language code for the IN instruction is:

Although AL or AX is implied as the first operand in an IN instruction, either AL or AX must be specified so that the assembler can determine the W-bit.

Similar comments apply to the OUT instruction except that for it the port address is the destination and is therefore indicated by the first operand, and the second operand is either AL or AX. Its machine code is:

Note that if the long form of the IN or OUT instruction is used the port address must be in the range 0000 to 00FF, but for the short form it can be any address in the range 0000 to FFFF (i.e. any address in the I/O address space). Neither IN nor OUT affects the flags.

The IN instruction may be used to input data from a data buffer register or the status from a status register. The instructions

IN  AX, 28H
MOV DATA_WORD, AX
would move the word in the ports whose address are 0028 and 0029 to the memory location DATA_WORD.

PRETHODNA FOLIJA SADRZAJ SLEDECA FOLIJA