-
Notifications
You must be signed in to change notification settings - Fork 99
REP
REP — Repeat String Operation (Prefix)
| Opcode | Instruction | Op/ En | 64-Bit Mode | Compat/ Leg Mode | Description1 |
| F3 6C | REP INS m8, DX | ZO | Valid | Valid | Input (count) bytes from port DX to (dest). |
| F3 6D | REP INS m16, DX | ZO | Valid | Valid | Input (count) words from port DX to (dest). |
| F3 6D | REP INS m32, DX | ZO | Valid | Valid | Input (count) doublewords from port DX to (dest). |
| F3 AC | REP LODS AL | ZO | Valid | Valid | Load (count) bytes from (src) to AL. |
| F3 AD | REP LODS AX | ZO | Valid | Valid | Load (count) words from (src) to AX. |
| F3 AD | REP LODS EAX | ZO | Valid | Valid | Load (count) doublewords from (src) to EAX. |
| F3 REX.W AD | REP LODS RAX | ZO | Valid | N.E. | Load (count) quadwords from (src) to RAX. |
| F3 A4 | REP MOVS m8, m8 | ZO | Valid | Valid | Move (count) bytes from (src) to (dest). |
| F3 A5 | REP MOVS m16, m16 | ZO | Valid | Valid | Move (count) words from (src) to (dest). |
| F3 A5 | REP MOVS m32, m32 | ZO | Valid | Valid | Move (count) doublewords from (src) to (dest). |
| F3 REX.W A5 | REP MOVS m64, m64 | ZO | Valid | N.E. | Move (count) quadwords from (src) to (dest). |
| F3 6E | REP OUTS DX, m8 | ZO | Valid | Valid | Output (count) bytes from (src) to port DX. |
| F3 6F | REP OUTS DX, m16 | ZO | Valid | Valid | Output (count) words from (src) to port DX. |
| F3 6F | REP OUTS DX, m32 | ZO | Valid | Valid | Output (count) doublewords from (src) to port DX. |
| F3 AA | REP STOS m8 | ZO | Valid | Valid | Fill (count) bytes at (dest) with AL. |
| F3 AB | REP STOS m16 | ZO | Valid | Valid | Fill (count) words at (dest) with AX. |
| F3 AB | REP STOS m32 | ZO | Valid | Valid | Fill (count) doublewords at (dest) with EAX. |
| F3 REX.W AB | REP STOS m64 | ZO | Valid | N.E. | Fill (count) quadwords at (dest) with RAX. |
NOTES:
- See Description section for details on (count), (src), and (dest).
| Op/En | Operand 1 | Operand 2 | Operand 3 | Operand 4 |
| ZO | N/A | N/A | N/A | N/A |
Repeats a string instruction the number of times specified in the count register. The count register is CX, ECX, or RCX, depending on the instruction’s address size. The REP (repeat) mnemonic is a prefix that can be added to the INS, OUTS, MOVS, LODS, and STOS instructions.
The REP prefixes apply only to one string instruction at a time. To repeat a block of instructions, use the LOOP instruction or another looping construct. The REP prefixes causes the associated instruction to be repeated until the count in register is decremented to 0.
Each of the string instructions uses a source address, a destination address, or both. The source address is DS:SI, DS:ESI, or DS:RSI, depending on the instruction’s address size; the DS segment may be overridden by an instruction prefix. The destination address is ES:DI, ES:EDI, or ES:RDI, depending on the instruction's address size; the ES segment may not be overridden. (Note that, in 64-bit mode, the base addresses of the CS, DS, ES, and SS segments are treated as zero.)
Similarly, the size of the count register is the instruction’s address size. Thus, the default count register in 64-bit mode is RCX; REX.W has no effect on the address size and the count register. If 67H is used to override the default address size, the size of the count register is also overridden. A repeating string operation can be suspended by an exception or interrupt. When this happens, the state of the registers is preserved to allow the string operation to be resumed upon a return from the exception or interrupt handler. The source and destination registers point to the next string elements to be operated on, the EIP register points to the string instruction, and the ECX register has the value it held following the last successful iteration of the instruction. This mechanism allows long string operations to proceed without affecting the interrupt response time of the system.
Use the REP INS and REP OUTS instructions with caution. Not all I/O ports can handle the rate at which these instructions execute. Note that a REP STOS instruction is the fastest way to initialize a large block of memory.
REP INS may read from the I/O port without writing to the memory location if an exception or VM exit occurs due to the write (e.g., #PF). If this would be problematic, for example because the I/O port read has side-effects, software should ensure the write to the memory location does not cause an exception or VM exit.
IF AddressSize = 16
THEN
Use CX for CountReg;
Implicit Source/Dest operand for memory use of SI/DI;
ELSE IF AddressSize = 64
THEN Use RCX for CountReg;
Implicit Source/Dest operand for memory use of RSI/RDI;
ELSE
Use ECX for CountReg;
Implicit Source/Dest operand for memory use of ESI/EDI;
FI;
WHILE CountReg ≠ 0
DO
Service pending interrupts (if any);
Execute associated string instruction;
CountReg ← (CountReg – 1);
OD;None.
Exceptions may be generated by an instruction associated with the prefix.
Source: Intel® 64 and IA-32 Architectures Software Developer's Manual, Combined Volumes (Order Number 325462-091US, March 2026)
Generated: 7-6-2026