In assembler language the prefix is invoked by placing the appropriate repeat (REP) mnemonic before the primitive.

              Figure 5-7 REP prefix

    Name                   Mnemonic and Format    Termination Condition      

Repeat string operation    REP String Primitive*         (CX)=0
until CX=0

Repeat string operation    REPE String primitive**   (CX)=0 or (ZF)=0  
while equal or zero         or
                           REPZ

Repeat string operation    REPNE String primitive**  (CX)=0 or (ZF)=0 
while not equal or          or  
not zero                   REPNZ

         *MOVS,LODS or STOS
         **CMPS or SCAS

         Note: In all cases (CX) <- (CX)-1 with each operation.
As an example of the use of the REP prefix let us reconsider the program sequence for moving a string within memory given in Fig. 5-2(b).By replacing the explicit loop
           MOVE:  MOVS STRING2, STRING1
                  LOOP MOVE
with
           REP    MOVS string2, STRING1
not only is the code simplified, but the execution time is reduced from
  
            18 + 17 = 35 clock cycles per iteration
to 
            9 + 17 = 26 clock cycles
for the first iteration and 17 clock cycles for each subsequent iteration.
            MOV  BX, TABLE SIZE      ;LOAD NO.OF ENTRIES INTO BX 
            LES  DI, TABLEPT         ;LOAD OFFSET AND SEGMENT ADDRESS
                                     ;OF THE ARRAY TO BE SEARCHED
            MOV  DX, DI              ;SAVE OFFSET IN DX
            LDS  SI, SYMBOLPT        ;LOAD OFFSET AND SEGMENT ADDRESS
                                     ;OF THE SYMBOL TOBE SEARCHED FOR
            CLD                      ;START FROM THE FIRST ENTRY
 LOOP1:     MOV  CX, 8               
            REPE CMPSB               ;COMPARE TWO CORRESPONDING
            JE   FOUND               ;CHARACTERS UNTIL NO MATCH 
            ADD  DX, 20              ;POINT TO THE NEXT TABLE ENTRY
            MOV  DI, DX
            MOV  SI, OFFSET SYMBOL   ;POINT TO THE FIRST CHARACTER  
            DEC  BX
            JNE  LOOP1
 NOT FOUND:  .
             .
 FOUND:      .
             .        
     Figure 5-8  Search a table for a given name with eigthcharacters 



            MOV   CX, LENGTH ASCII_STG ;INITIALIZE SEARCH
            MOV   AL, '$'
            MOV   DI, OFFSET ASCII_STG
            CLD
 LOOP1:     REPNZ SCAS ASCII_STG       ;SEARCH FOR '$' AND
            JNZ   DONE
            MOV   BYTE PTR[DI-1],'_'   ;REPLACE WITH '_'
            JMP   SHORT LOOP1
 DONE:       .
             .
             .
       Figure 5-9  Replace each "$" in a character string with a "_"
  

PRETHODNA FOLIJA SADRZAJ SLEDECA FOLIJA