Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- TASM 2.x / MASM 6.x Assembly Language - <b>repne repeat while not equal flags: not altered</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
REPNE            Repeat While not Equal              Flags: not altered

REPNE  string-instruction

          Logic:    while CX <> 0                    ;for MOVS, LODS or STOS
                        execute string instruction
                        CX . CX - 1
                   ------------------------------------------
                    while CX <> 0                    ;for CMPS or SCAS
                        execute string instruction
                        CX . CX - 1
                        if ZF <> 0 terminate loop    ;This is only difference
                                                     ;between REP and REPNE

    REPNE is a prefix that may be specified before any string instruction
    (CMPS, LODS, MOVS, SCAS, and STOS). REPNE 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 set after the string instruction executes. Compare this to REP,
    which will terminate if the Zero Flag is clear.)

  --------------------------------------------------------------------------
   Operands                  Clocks   Transfers  Bytes   Example
      -                        2          -        1     REPNE SCASB
  --------------------------------------------------------------------------

       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
                      set--done only for CMPS and SCAS--is performed after
                      the instruction is executed.

                      REPNE and REPNZ are synonyms for the same
                      instruction.

                      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.

  -------------------------------- Example ---------------------------------

    The following example will find the first byte equal to 'A' in the
    100-byte buffer at STRING.

          CLD                     ;Scan string in forward direction
          MOV     AL,'A'          ;Scan for 'A'
          LEA     DI, STRING      ;Address to start scanning at
          MOV     CX,100          ;Scanning 100 bytes
  REPNE   SCASB                   ;   ...and scan it
          DEC     DI              ;Back up DI to point to the 'A'

    Upon termination of the repeated SCASB instruction, CX will be equal
    to zero if a byte value of 'A' was not found in STRING, and non-zero
    if it was.

See Also: REP MOVS STOS CMPS SCAS LODS CLD STD

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson