Category : Files from Magazines
Archive   : PROGJRNL.ZIP
Filename : SEARCH.ASM
; (C) 1987 BY ADRIAN CRUM
;
; IMPLEMENTS A MODIFIED BOYER-MOORE ALGORITHM
; THE 'NEXT TABLE' IS REPLACED BY THE 8086 'SCASB' CAPABILITY
;
; CALLING PARAMETERS:
;
; BX = LENGTH OF PATTERN TO SEARCH FOR
; DX = OFFSET OF LAST BYTE OF TEXT TO BE SEARCHED
; SI = OFFSET OF FIRST BYTE OF TEXT TO BE SEARCHED
; DI = OFFSET OF PATTERN TO SEARCH FOR
; ES: = DS:
;
; RETURNS CARRY CLEAR AND SI=MATCHING TEXT OR CARRY SET IF NO MATCH.
SEARCH PROC NEAR
DEC BX ; BX = pattern length - 1
MOV AL,[BX+DI] ; Get the last char in pattern
MOV AH,AL ; Save the char in AH
CLD
COMPARE:
CMP SI,DX ; Reached end of text yet?
JA NOT_FOUND ; Yes, bail out
MOV CX,BX ; Put pattern length in CX
INC CX
CMP AL,[BX+SI] ; Last char in pattern match?
JNE SHIFT ; No, shift pattern
PUSH SI ; Save the pointers
PUSH DI ; Compare pattern with
REPZ CMPSB ; this portion of text
POP DI ; Restore pointers
POP SI
JE FOUND ; Match found, bail out
MOV CX,BX
INC CX ; CX = pattern length
SHIFT: PUSH DI ; Save the pointer
MOV AL,[BX+SI] ; Get non-matching char
MOV BX,CX ; Set up BX for possible jmp to
SHIFT1
REPNE SCASB ; Non-matching char in pattern?
JCXZ SHIFT1 ; No, proceed
ADD SI,CX ; Yes, shift pattern (CX) chars
JMP SHORT SHIFT2
SHIFT1: ADD SI,BX ; Shift pattern (pattern len) chars
SHIFT2: POP DI ; Restore pointer
MOV AL,AH ; Restore AL
JC NOT_FOUND ; If segment wrap, bail out
DEC BX ; BX = pattern length - 1
JMP COMPARE ; Loop
FOUND: INC BX
CLC ; Search successful
RET
NOT_FOUND:
STC ; Search unsuccessful
RET
SEARCH ENDP
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/