home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8610.arc
/
DUNCLST.OCT
< prev
next >
Wrap
Text File
|
1986-10-31
|
7KB
|
204 lines
LISTING 1 for OCT 86 16-BIT TOOLBOX COLUMN
------------------------------------------
;
; Boyer-Moore text matching algorithm
; described in Scientific American Sept. 1984, pp. 67-68.
; Implemented for 8086 by Ray Duncan, June 1986.
;
; Call with: DS:SI = pattern address
; AX = pattern length
; ES:DI = address of string to be searched
; DX = length of string to be searched
; assumes "CTAB" in same segment as pattern string
;
; Returns: CY = True if no match
; or
; CY = False if match, and
; ES:DI = pointer to matched string
boyer proc near
mov bp,si ; save pattern offset
push di ; save searched string offset
push es ; save searched string segment
push dx ; save searched string length
push ds
pop es ; point to table with ES
mov cx,256 ; initialize all of table
mov di,offset ctab ; to length of pattern
cld
rep stosb
dec ax ; AX = pattern length - 1
xor cx,cx ; init pattern char. counter
xor bh,bh ; BX will be used to index,
; with char in the lower half
b1: ; build table of increments
; for each possible char. value
mov bl,[si] ; get character
mov dx,ax ; calc distance from end
sub dx,cx ; of pattern
mov [bx+ctab],dl ; put into table
inc si ; advance through pattern
inc cx
cmp cx,ax ; done with pattern?
jne b1 ; no, loop
pop dx ; restore searched string length
pop es ; restore searched string segment
pop di ; restore searched string offset
std ; strings will be compared
; from their ends backwards
b2: mov si,bp ; get pattern addr
add di,ax ; point to ends of strings
add si,ax
mov cx,ax ; get length to compare
inc cx
repz cmpsb ; now compare strings
jz b3 ; jump if whole string matched
inc di ; point to mismatched char
mov bl,es:[di] ; and fetch it, then
mov bl,[bx+ctab] ; get displacement amount
sub di,cx ; restore searched string address
add di,bx ; update searched string pointer
sub dx,bx ; update remaining length
cmp dx,ax ; enough left to compare again?
ja b2 ; jump if searched string not exhausted
stc ; no match, return CY=True
jmp b4
b3: inc di ; match found, return CY=False
clc ; and ES:DI = pointer to matched string
b4: cld ; return to caller with direction
ret ; flag cleared
boyer endp
;
; Table of possible byte values: if the value exists in the pattern
; string, its byte contains its offset from the end of the pattern.
; If the value does not occur in the pattern, its byte contains the
; length of the pattern.
ctab db 256 dup (?)
LISTING 2 FOR OCT 86 16-BIT TOOLBOX COLUMN
-------------------------------------------
;
; General string matching routine for 8086
; (brute force version using 8086 string primitives)
; by Ray Duncan, June 1986
;
; Call with: DS:SI = pattern address
; AX = 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
;
smatch proc near
mov bp,si ; save pattern offset
mov bx,ax ; BX := pattern length
dec bx ; decrement it 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
smatch endp
LISTING 3 for Oct 86 16-BIT TOOLBOX COLUMN
------------------------------------------
{ -------------------------------- }
{ C2I }
{ Convert .COM file to Inline Code }
{ by George F. Smith, 1986 }
{ }
{ Sample usage: }
{ A>C2I File.Com >File.inl }
{ -------------------------------- }
{$P1024,D-}
var
ctr, { LineSize counter }
bits : byte; { com file byte }
Com : file of byte; { com file handle }
const
LineSize = 70;
hex : array[0..15] of char = '0123456789ABCDEF';
BEGIN
Assign(Com,ParamStr(1)); { com file name from command line }
Reset(Com);
write('InLine ( ');
ctr := 10; { initialize counter }
While not eof(Com) do
begin
read(Com,bits); { Get com data . . . }
Write('/$', { . . . put it inline }
hex [ bits shr 4 and $0F ] ,
hex [ bits and $0F ] ,' ');
ctr := ctr + 5;
if ctr = LineSize then
begin
ctr := 0; { Reset counter and }
writeln; { start a new line }
end;
end;
Write(' );'); { Finish inline statement }
Write(^Z);
Close(Com);
END. { C2I }