Repeat String Instruction                          

86/88

Y

186

Y

286

Y

386

Y

486

Y

REP string_instruction

Ovfl

N

Dir

N

Int

N

Trap

N

Sign

N

Zero

N

Aux

N

Prty

N

Carry

N

    REP is a prefix that may be specified before any string instruction
    (CMPS, LODS, MOVS, SCAS, and STOS). REP causes the string instruction
    following it to be repeated, as long as CX does not equal 0; CX is
    decremented after each execution of the string instruction.  (For CMPS
    and SCAS, REP will also terminate the loop if the Zero Flag is clear
    after the string instruction executes.)

       Notes:         If CX is initially 0, the REPeated instruction is
                      skipped entirely.

                      The test for CX equal to 0 is performed before the
                      instruction is executed.  The test for the Zero Flag
                      clear (done only for CMPS and SCAS) is performed
                      after the instruction is executed.

                      REP, REPE (Repeat While Equal), and REPZ (Repeat
                      While Zero) are all synonyms for the same
                      instruction.

                      REPNZ (Repeat Not Zero) is similar to REP, but when
                      used with CMPS and SCAS, will terminate with the
                      Zero Flag set, rather than cleared.

                      REP is generally used with the MOVS (Move String)
                      and STOS (Store String) instructions; it can be
                      thought of as "repeat while not end of string."

                      You do not need to initialize ZF before using
                      repeated string instructions.

                      A REPeated instruction that is interrupted between
                      repeats will correctly resume processing upon return
                      from the interrupt. However, if other prefixes are
                      used on a single instruction (for example, segment
                      override or LOCK) in addition to the REP, all
                      prefixes except the one that immediately preceded
                      the string instruction will be lost. Therefore, if
                      you must use more than one prefix on a single
                      instruction, you should disable interrupts before
                      the instruction, and enable them afterwards. Note
                      that even this precaution will not prevent a non-
                      maskable interrupt, and that lengthy string
                      operations may cause large delays in interrupt
                      processing.

------------------------------------ Timing ----------------------------------

OpCode          Instruction             386     286     86
F3 6C           REP INS r/m8, DX        13+6*CX 5+4*CX
F3 7D           REP INS r/m16, DX       13+6*CX 5+4*CX
F3 7D           REP INS r/m32, DX       13+6*CX
F3 A4           REP MOVS m8, m8         5+4*CX  5+4*CX  9+17*CX
F3 A5           REP MOVS m16, m16       5+4*CX  5+4*CX  9+17*CX
F3 A5           REP MOVS m32, m32       5+4*CX
F3 6E           REP OUTS DX, r/m8       5+12*CX 5+4*CX
F3 6F           REP OUTS DX, r/m16      5+12*CX 5+4*CX
F3 6F           REP OUTS DX, r/m32      5+12*CX
F3 AA           REP STOS m8             5+5*CX  4+3*CX  9+10*CX
F3 AB           REP STOS m16            5+5*CX  4+3*CX  9+10*CX
F3 AB           REP STOS m32            5+5*CX
F3 A6           REPE CMPS m8, m8        5+9*N   5+9*N   9+22*N
F3 A7           REPE CMPS m16, m16      5+9*N   5+9*N   9+22*N
F3 A7           REPE CMPS m32, m32      5+9*N
F3 AE           REPE SCAS m8            5+8*N   5+8*N   9+15*N
F3 AF           REPE SCAS m16           5+8*N   5+8*N   9+15*N
F3 AF           REPE SCAS m32           5+8*N

------------------------------------ Logic -----------------------------------

        while CX <> 0                   ; for MOVS, LODS, STOS
                execute string instruction
                CX = CX - 1

        while CX <> 0                   ; for CMPS, SCAS
                execute string instruction
                CX = CX - 1
                if ZF = 0 terminate

See Also REPNE MOVS STOS CMPS SCAS LODS REPE CLD STD


Copyright © 1985 to 2022 Beta Systems                            Last modified: Wednesday, January 05, 2022 .