home *** CD-ROM | disk | FTP | other *** search
- ; Function to perform comparison between a far and
- ; near string. A brute force method is used for searching.
- ; Use to find the "PATH=" string in the master environment.
- ; Returns pointer to start of string if match is found.
- ; Returns null pointer if not.
- ; char far *findstr(char far *str1, char *str2);
- ; For Turbo C 2.0, small/tiny model.
- ; Written and tested with Turbo Assembler 1.0
- ; By Goh King Hwa, 20 Dec 1989.
- ; Bug Fix: 27 Jan 1990
-
- _TEXT segment byte public 'CODE'
- assume cs:_TEXT
- _findstr proc near
- push bp
- mov bp,sp
- push ds
- push si
- push di
-
- mov ax,ds
- mov es,ax ;move DS to ES
- cld ;auto-increment mode
-
- findEnd: ;find end of near string
- mov cx,-1 ;set for maximum count
- mov di,[bp+8]
- xor al,al ;zero AL
- repnz scasb ;repeat until EOS
- mov bx,di ;end of near string save in BX
-
- mov di,[bp+8] ;ES:DI points to near string
- lds si,[bp+4] ;DS:SI points to far string
-
- cmp byte ptr [si],0
- je notfound ;null far string, exit
- cmp byte ptr es:[di],0
- je notfound ;null near string, exit
-
- search:
- mov dx,si ;save marker
- mov cx,-1 ;set for maximum count
- repz cmpsb ;until the first non-matching character
- cmp bx,di ;check against end of string
- jne notfound ;if BX == DI, string matches
- found:
- mov ax,dx ;restore old DI
- mov dx,ds ;remember segment address
- jmp short exit
- notfound:
- xor ax,ax ;return zero
- xor dx,dx ;if string not found
- exit:
- pop di
- pop si
- pop ds
- pop bp
- ret
- _findstr endp
- _TEXT ends
-
- public _findstr
- end
-