AMD amd64 architecture User Manual

Page of 336
64
General-Purpose Programming
AMD64 Technology
24592—Rev. 3.15—November 2009
When operating in legacy protected mode or in long mode, the RFLAGS register’s I/O privilege level
(IOPL) field and the I/O-permission bitmap in the current task-state segment (TSS) are used to control
access to the I/O addresses (called I/O ports). See “Input/Output” on page 90 for further information.
General I/O
IN—Input from Port
OUT—Output to Port
The IN instruction reads a byte, word, or doubleword from the I/O port address specified by the source
operand, and loads it into the accumulator register (AL or eAX). The source operand can be an
immediate byte or the DX register.
The OUT instruction writes a byte, word, or doubleword from the accumulator register (AL or eAX) to
the I/O port address specified by the destination operand, which can be either an immediate byte or the
DX register.
If the I/O port address is specified with an immediate operand, the range of port addresses accessible
by the IN and OUT instructions is limited to ports 0 through 255. If the I/O port address is specified by
a value in the DX register, all 65,536 ports are accessible.
String I/O
INS—Input String
INSB—Input String Byte
INSW—Input String Word
INSD—Input String Doubleword
OUTS—Output String
OUTSB—Output String Byte
OUTSW—Output String Word
OUTSD—Output String Doubleword
The INSx instructions (INSB, INSW, INSD) read a byte, word, or doubleword from the I/O port
specified by the DX register, and load it into the memory location specified by ES:[rDI].
The OUTSx instructions (OUTSB, OUTSW, OUTSD) write a byte, word, or doubleword from an
implicit memory location specified by seg:[rSI], to the I/O port address stored in the DX register.
The INSx and OUTSx instructions are commonly used with a repeat prefix to transfer blocks of data.
The memory pointer address is not incremented or decremented. This usage is intended for peripheral
I/O devices that are expecting a stream of data.
3.3.14 Semaphores
The semaphore instructions support the implementation of reliable signaling between processors in a
multi-processing environment, usually for the purpose of sharing resources.