REPNE and REPNZ name the F2h prefix. In front of SCAS or CMPS it repeats while CX is not 0 and the compare finds the elements different. Each round: stop if CX = 0, compare once, step SI / DI, decrease CX, stop if ZF = 1. Its main use is REPNE SCASB: search ES:DI for the byte in AL.

Ends becauseZFWhere
a match was found1DI is one past the match
CX ran out, no match0DI is past the searched block
CX was 0 at the startunchangednothing searched

Test ZF (JE found / JNE not found) and not CX: a match on the last element leaves CX = 0 as well. Going forward over bytes the match is at DI - 1, its 0-based index is DI - start - 1, and N - CX elements were looked at.

CLD
MOV DI, OFFSET TXT1
MOV CX, 8 ; length of the text
MOV AL, 'w'
REPNE SCASB ; stop at the first "w"
JNE MISS1
MOV AX, DI
SUB AX, OFFSET TXT1 + 1 ; 0-based index: 3
ADD AL, '0' ; digit -> character
MOV DL, AL
MOV AH, 02h ; DOS: print DL
INT 21h
JMP DONE1
MISS1:
MOV DL, '-'
MOV AH, 02h
INT 21h
DONE1:
TXT1 DB 'hi world'

With CX = 0FFFFh and AL = 0 the same search measures a 0-terminated string (see SCASB / SCASW). REPNE CMPSB finds the first position where two strings hold the same byte, which is less common.

Pitfalls: forgetting CLD, forgetting that the search is in ES (set it in an .EXE), and reading DI as the match itself instead of one past it. In front of MOVS, STOS or LODS use REP, not REPNE.