The CMPS primitive can be used to compare strings or words of arbitrary length.

        MOV SI, OFFSET STRG1       
        MOV DI, OFFSET STRG2
        MOV CX, LENGTH STRG1
        CLD
 NEXT:  CMPS STRG1,STRG2      ;COMPARE STRG1
        JNE EXIT              ;WITH STRG2 AND
        LOOP NEXT             ;BRANCH TO SAME IF
        JMP NEAR PTR SAME     ;THEY ARE EQUAL
 EXIT:   .
         . 
         . 
The other three string primitives SCAS,LODS and STOS, have single memory operands.Of these primitives only SCAS affects the condition flags.
        MOV DI, OFFSET LINE   ;PUT ADDR OF LINE IN DI
        MOV CX, 80            ;AND COUNT IN CX
        MOV AL, 20H           ;MOVE ASCII BLANK TO AL
        CLD                   ;START FROM THE FIRST ELEMENT
 NEXT:  SCAS LINE             ;CHECK FOR BLANK BRANCH
        LOOPE NEXT            ;IF LINE IS BLANK BRANCH
        JE NOT FOUND          ;TO NOT FOUND ELSE MOVE STRING
        MOV SI, DI            ;PUT ADDR OF FIRST NONBLANK
        DEC SI                ;CHARACTER IN SI
        MOV DI, OFFSET SYMBOL ;AND ADDR OF SYMBOL IN DI
        MOV CX, 31            ;PUT COUNT IN CX
 FILL:  STOS SYMBOL           ;FILL SYMBOL WITH BLANKS
        LOOP FILL
        MOV DI, OFFSET SYMBOL ;SETUP DI
        MOV CX, 31            ;AND CX
        JMP SHORT SCANE
 MOVE:  STOS SYMBOL
 SCANE: LODS LINE             ;MOVE STRING TO SYMBOL UNTIL A
        CMP AL, 20H           ;BLANK ISFOUND OR 31 CHARACTERS
        LOOPNE MOVE           ;HAVE BEEN MOVED
         .
         .
         .
    Figure 5-6 Example of the use of the SCAS,STOS and LODS primitives 
        

5-2 REP PREFIX

Because string operations inherently involve looping, the 8086 machine language includes a prefix that considerably simplifies the use of string primitives with loops.This prefix has machine code:

1 1 1 1 0 0 1 Z

where, for the CMPS and SCAS primitives, the Z bit helps control the loop.By prefixing MOVS,LODS and STOS, which donot affect the flags, with the REP prefix 11110011 they are repeated the number of times indicated by the CX register according to the following steps:
  1. If (CX)=0, exit the REP operation
  2. Perform the specified primitive
  3. Decrement CX by 1
  4. Repeat steps 1 through 3
For the CMPS and SCAS primitives, which do affects the flags, the prefix causes them to be repeated the numberof times indicated by the CX register or until the Z-bit does not match the ZF flag, whichever occurs first.

PRETHODNA FOLIJA SADRZAJ SLEDECA FOLIJA