rep movs
Repeat Move String
Moves ECX bytes/words from [ESI] to [EDI].
Details
Copies ECX/RCX bytes or words from the memory location at DS:[ESI/RSI] to ES:[EDI/RDI], decrementing or incrementing the pointers based on the Direction Flag (DF), and decrementing the counter. Repeats until RCX=0 or an interrupt occurs. No flags are modified by the instruction itself, though DF controls direction. The REP prefix causes automatic looping at the microarchitectural level.
Pseudocode Operation
while (RCX != 0) {
if (OperandSize == 8) {
[RDI] ← [RSI];
if (DF == 0) { RSI ← RSI + 1; RDI ← RDI + 1; } else { RSI ← RSI - 1; RDI ← RDI - 1; }
} else if (OperandSize == 16) {
[RDI] ← [RSI];
if (DF == 0) { RSI ← RSI + 2; RDI ← RDI + 2; } else { RSI ← RSI - 2; RDI ← RDI - 2; }
} else {
[RDI] ← [RSI];
if (DF == 0) { RSI ← RSI + 4; RDI ← RDI + 4; } else { RSI ← RSI - 4; RDI ← RDI - 4; }
}
RCX ← RCX - 1;
}
Example
Encoding
Operands
-
dest
Implicit memory for MOVS: ES:[DI] destination, DS:[SI] source -
src
Memory operand
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| 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 | DX. | Output (count) doublewords from (src) to port |
| 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. |
Description
Operation
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;
Flags Affected
None. Exceptions (All Operating Modes) Exceptions may be generated by an instruction associated with the prefix. REP—Repeat String Operation (Prefix) Vol. 2B 4-564