repne scas

Repeat Scan String Not Equal

REPNE SCAS m

Scans [EDI] for AL/AX/EAX until match or ECX=0.

Pseudocode Operation

while (RCX != 0) {
  if (OperandSize == 8) {
    result ← AL - [RDI];
    if (DF == 0) { RDI ← RDI + 1; } else { RDI ← RDI - 1; }
  } else if (OperandSize == 16) {
    result ← AX - [RDI];
    if (DF == 0) { RDI ← RDI + 2; } else { RDI ← RDI - 2; }
  } else if (OperandSize == 32) {
    result ← EAX - [RDI];
    if (DF == 0) { RDI ← RDI + 4; } else { RDI ← RDI - 4; }
  } else {
    result ← RAX - [RDI];
    if (DF == 0) { RDI ← RDI + 8; } else { RDI ← RDI - 8; }
  }
  RCX ← RCX - 1;
  OF ← OverflowFlag(result); SF ← SignBit(result); ZF ← (result == 0); AF ← AuxiliaryFlag(result); CF ← CarryFlag(result); PF ← ParityFlag(result);
  if (ZF == 1) break;
}

Encoding

Binary Layout
F2
+0
 
Format Legacy
Opcode F2 AE
Extension Base

Operands

  • dest
    Implicit memory for SCAS (compare accumulator with ES:[DI])

Related

More in Base

Instruction Forms

Opcode Instruction Op/En 64/32-bit Mode CPUID Description
F2 AE REPNE SCAS m8 Compares AL with the byte at [RDI], repeating while not equal and (E/R)CX is nonzero, decrementing (E/R)CX each iteration.
F2 AF REPNE SCAS m32 Doubleword form of REPNE SCAS.

Description

Repeats SCAS (compare AL/AX/EAX/RAX against a string element) while ZF=0 (not equal) and the count register is nonzero. Commonly used to locate a byte value (e.g. a NUL terminator) within a buffer.