Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 7-27
PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS
at higher addresses and work toward lower ones, or they can begin at lower
addresses and work toward higher ones. The DF flag in the EFLAGS register controls
whether the registers are incremented (DF = 0) or decremented (DF = 1). The STD
and CLD instructions set and clear this flag, respectively.
The following repeat prefixes can be used in conjunction with a count in the ECX
register to cause a string instruction to repeat:
• REP — Repeat while the ECX register not zero.
• REPE/REPZ — Repeat while the ECX register not zero and the ZF flag is set.
• REPNE/REPNZ — Repeat while the ECX register not zero and the ZF flag is clear.
When a string instruction has a repeat prefix, the operation executes until one of the
termination conditions specified by the prefix is satisfied. The REPE/REPZ and
REPNE/REPNZ prefixes are used only with the CMPS and SCAS instructions. Also,
note that a REP STOS instruction is the fastest way to initialize a large block of
memory.
7.3.10 String Operations in 64-Bit Mode
The behavior of MOVS (Move String), CMPS (Compare string), SCAS (Scan string),
LODS (Load string), and STOS (Store string) instructions in 64-bit mode is similar to
their behavior in non-64-bit modes, with the following differences:
• The source operand is specified by RSI or DS:ESI, depending on the address size
attribute of the operation.
• The destination operand is specified by RDI or DS:EDI, depending on the address
size attribute of the operation.
• Operation on 64-bit data is supported by using the REX.W prefix.
7.3.10.1 Repeating String Operations in 64-bit Mode
When using REP prefixes for string operations in 64-bit mode, the repeat count is
specified by RCX or ECX (depending on the address size attribute of the operation).
The default address size is 64 bits.
7.3.11 I/O Instructions
The IN (input from port to register), INS (input from port to string), OUT (output
from register to port), and OUTS (output string to port) instructions move data
between the processor’s I/O ports and either a register or memory.
The register I/O instructions (IN and OUT) move data between an I/O port and the
EAX register (32-bit I/O), the AX register (16-bit I/O), or the AL (8-bit I/O) register.
The I/O port being read or written to is specified with an immediate operand or an
address in the DX register.