home *** CD-ROM | disk | FTP | other *** search
-
- ;
- ; General purpose string search/matching routine for 8086
- ; Copyright (C) 1986 Ray Duncan, June 1986
- ;
- ; Call with: DS:SI = pattern address
- ; BX = pattern length
- ; ES:DI = address of string to be searched
- ; DX = length of string to be searched
- ;
- ; Returns: CY = True if no match
- ; or
- ; CY = False if match, and
- ; ES:DI = pointer to matched string
- ;
- strndx proc near
-
- mov bp,si ; save pattern offset
- dec bx ; decr. pattern length by one
- cld
-
- s1: mov si,bp ; AL := first char of pattern
- lodsb
- mov cx,dx ; remaining searched string length
- repnz scasb ; look for match on first char.
- jnz s3 ; searched string exhausted, exit
- mov dx,cx ; save new string length
- mov cx,bx ; get pattern length - 1
- repz cmpsb ; compare remainder of strings
- jz s2 ; everything matched
- add di,cx ; no match, restore string addr
- sub di,bx ; advanced by one char.
- cmp dx,bx ; searched string exhausted?
- ja s1 ; some string left, try again
- jmp s3 ; no match, jump to return
-
- s2: sub di,bx ; match was found,
- dec di ; let ES:DI = addr of matched string
- clc ; and return CY=False
- ret
-
- s3: stc ; no match, return CY=True
- ret
-
- strndx endp
- ;