home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
assemblr
/
tools
/
conv_a11
/
posch.asm
< prev
next >
Wrap
Assembly Source File
|
1989-11-04
|
2KB
|
77 lines
;Faster string search routine to substitute the POS()
;function (for characters only) in Turbo Pascal 4 or 5.
;
;Declare as follows:
; {$F+}
; {$L POSCH.OBJ}
; FUNCTION posCH(Ch : CHAR; Str : STRING) : BYTE; EXTERNAL;
;Call as follows:
; location := posCH(Ch, Str);
;
;Courtesy of Toad Hall
;Total stack (caller's plus work stack)
cstk STRUC
bpsave DW 0 ;save BP here
retaddr DD 0 ;points to return address
straddr DD 0 ;points to string address
chr DB 0 ;actual character
cstk ENDS
PARAMSIZE EQU SIZE chr + SIZE straddr ;size of parameter list
PUBLIC PosCH ;function name declaration
CODE SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CODE
;Entry point to PosCH function
PosCH PROC FAR
push bp
mov bp,sp
mov dx,DS ;save caller's DS
cld
;Get and save string text length and address
lds si,[bp.straddr]
lodsb ;get string length
or al,al ;if string text is null
jz NoMatch ; then exit
mov bx,si ;save address ofs
xor ah,ah ;clear msb
mov cx,ax ;CX = string length
mov al,[bp.chr] ;snarf char
mov di,DS ;DS has string's seg
mov ES,di ;into ES for the scas
mov di,si ;string offset
repne scasb ;search
jnz NoMatch ;not found, exit
Match1:
mov ax,di ;just past char found
; sub ax,2 ;adjust DI psn
sub ax,bx ;- start of strtxt
; add ax,2 ; in strtxt where pattern is found
jmp SHORT EndSearch ;exit function
NoMatch:
xor ax,ax ;no match, return a 0
EndSearch:
mov DS,dx ;recover
mov sp,bp ;recover last stack psn
pop bp ;recover BP
ret PARAMSIZE ;return with AX the posCH value
PosCH ENDP
CODE ENDS
END