;es:di = string to search ;ds:si = string to search for ;cx = length of string to search ;dx = length of string to search for ;for a backwards search, set di and si to the end bytes and set df. ;call instr ;di = offset found at or -1 if not found ;destroys cx, dx, oh,al instr: lodsb ; al = op1[0]; op1++ sub dx, 1 ; len2-- jc .found ; if len2 was 0 then quit now sub cx, dx ; len1 -= len2 jc .notfound ; if len1 flipped goto notfound .loop: jcxz .notfound ; if len1==0 jmp notfound repne scasb ; op1 = instr(op1[], op2[0])+1 jne .notfound ; if not instr(op1[], op2[0]) goto notfound push cx push si push di mov cx, dx repe cmpsb pop di pop si pop cx jne .loop ; if op1[] != op2[] goto instrhere dec di .found: clc ret .notfound: mov di, -1 stc ret