|
REP/REPE/REPZ/REPNE/REPNZ -- Repeat Following String Operation
Opcode | Instruction | Clocks |
Description | Example |
F3 6C | rep insb | 13+6*(E)CX, |
Input (E)CX bytes from port DX into ES:[(E)DI] | rep insb |
F3 6D | rep insw | 13+6*(E)CX, |
Input (E)CX words from port DX into ES:[(E)DI] | rep insw |
F3 6D | rep insl | 13+6*(E)CX, |
Input (E)CX dwords from port DX into ES:[(E)DI] | rep insl |
F3 A4 | rep movsb | 5+4*(E)CX |
Move (E)CX bytes from [(E)SI] to ES:[(E)DI] | rep movsb |
F3 A5 | rep movsw | 5+4*(E)CX |
Move (E)CX words from [(E)SI] to ES:[(E)DI] | rep movsw |
F3 A5 | rep movsl | 5+4*(E)CX |
Move (E)CX dwords from [(E)SI] to ES:[(E)DI] | rep movsl |
F3 AA | rep stosb | 5+5*(E)CX |
Fill (E)CX bytes at ES:[(E)DI] with AL | rep stosb |
F3 AB | rep stosw | 5+5*(E)CX |
Fill (E)CX words at ES:[(E)DI] with AX | rep stosw |
F3 AB | rep stosl | 5+5*(E)CX |
Fill (E)CX dwords at ES:[(E)DI] with EAX | rep stosl |
F3 A6 | repe cmpsb | 5+9*N |
Find nonmatching bytes in ES:[(E)DI] and [(E)SI] | repe cmpsb |
F3 A7 | repe cmpsw | 5+9*N |
Find nonmatching words in ES:[(E)DI] and [(E)SI] | repe cmpsw |
F3 A7 | repe cmpsl | 5+9*N |
Find nonmatching dwords in ES:[(E)DI] and [(E)SI] | repe cmpsl |
F3 AE | repe scasb | 5+8*N |
Find non-AL byte starting at ES:[(E)DI] | repe scasb |
F3 AF | repe scasw | 5+8*N |
Find non-AX word starting at ES:[(E)DI] | repe scasw |
F3 AF | repe scasl | 5+8*N |
Find non-EAX dword starting at ES:[(E)DI] | repe scasl |
F2 A6 | repne cmpsb | 5+9*N |
Find matching bytes in ES:[(E)DI] and [(E)SI] | repne cmpsb |
F2 A7 | repne cmpsw | 5+9*N |
Find matching words in ES:[(E)DI] and [(E)SI] | repne cmpsw |
F2 A7 | repne cmpsl | 5+9*N |
Find matching dwords in ES:[(E)DI] and [(E)SI] | repne cmpsl |
F2 AE | repne scasb | 5+8*N |
Find AL, starting at ES:[(E)DI] | repne scasb |
F2 AF | repne scasw | 5+8*N |
Find AX, starting at ES:[(E)DI] | repne scasw |
F2 AF | repne scasl | 5+8*N |
Find EAX, starting at ES:[(E)DI] | repne scasl |
Operation
IF AddressSize = 16
THEN use CX for CountReg;
ELSE (* AddressSize = 32 *) use ECX for CountReg;
FI;
WHILE CountReg <> 0
DO
service pending interrupts (if any);
perform primitive string instruction;
CountReg := CountReg - 1;
IF primitive operation is CMPB, CMPW, SCAB, or SCAW
THEN
IF (instruction is REP/REPE/REPZ) AND (ZF=1)
THEN exit WHILE loop
ELSE
IF (instruction is REPNZ or REPNE) AND (ZF=0)
THEN exit WHILE loop;
FI;
FI;
FI;
OD;
Description
REP, REPE (repeat while equal), and REPNE (repeat while not equal) are prefix that are applied to string operation. Each prefix cause the string instruction that follows to be repeated the number of times indicated in the count register or (for REPE and REPNE) until the indicated condition in the zero flag is no longer met.
Synonymous forms of REPE and REPNE are REPZ and REPNZ, respectively.
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 precise action for each iteration is as follows:
- If the address-size attribute is 16 bits, use CX for the count register; if the address-size attribute is 32 bits, use ECX for the count register.
- Check CX. If it is zero, exit the iteration, and move to the next instruction.
- Acknowledge any pending interrupts.
- Perform the string operation once.
- Decrement CX or ECX by one; no flags are modified.
- Check the zero flag if the string operation is SCAS or CMPS. If the repeat condition does not hold, exit the iteration and move to the next instruction. Exit the iteration if the prefix is REPE and ZF is 0 (the last comparison was not equal), or if the prefix is REPNE and ZF is one (the last comparison was equal).
- Return to step 1 for the next iteration.
Repeated CMPS and SCAS instructions can be exited if the count is exhausted or if the zero flag fails the repeat condition. These two cases can be distinguished by using either the JCXZ instruction, or by using the conditional jumps that test the zero flag (JZ, JNZ, and JNE).
Flags Affected
ZF by REP CMPS and REP SCAS as described above
Protected Mode Exceptions
#UD if a repeat prefix is used before an instruction that is not in the list above; further exceptions can be generated when the string operation is executed; refer to the descriptions of the string instructions themselves
Real Address Mode Exceptions
Interrupt 6 if a repeat prefix is used before an instruction that is not in the list above; further exceptions can be generated when the string operation is executed; refer to the descriptions of the string instructions themselves
Virtual 8086 Mode Exceptions
#UD if a repeat prefix is used before an instruction that is not in the list above; further exceptions can be generated when the string operation is executed; refer to the descriptions of the string instructions themselves
Notes
Not all input/output ports can handle the rate at which the REP INS and REP OUTS instructions execute.
[Home Page dell'ITIS "Fermi"]
[80386 Programmer's Reference Manual Index]
[Previous]
[Next]
|