home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Share Gallery 1
/
share_gal_1.zip
/
share_gal_1
/
LA
/
LA001.ZIP
/
CHASM.ARC
/
STRCOMP.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-10-31
|
3KB
|
74 lines
;==============================================================
; function StrComp(var Str1, Str2: AnyString): integer;
; external 'strcomp';
;
; External function for Turbo Pascal
;
; Compares two strings, returning an integer as follows:
;
; 0 : Str1 = Str2
; 1 : Str1 > Str2
; 2 : Str2 > Str1
;
; Turbo's string compare routine copies both strings onto
; the stack and compares the copies. This routine runs
; about 3 times faster by passing pointers and comparing
; the strings in place.
;
; Another advantage is that the integer result can be used to
; drive a CASE statement, eliminating multiple comparisons.
;================================================================
stack struc ;models structure of stack
oldbp dw 0000H ;saved BP register
retaddr dw 0000H ;return address to Turbo
str2ptr dw 0000H, 0000H ;address of 2nd parameter
str1ptr dw 0000H, 0000H ;address of 1st parameter
result dw 0000H ;funtion result field
endstruc
strcomp proc near
push bp ;establish addressability
mov bp, sp ;of parameters
push ds
lds si, str1ptr[bp] ;point to string 1
les di, str2ptr[bp] ;and string 2
mov cl, [si] ;CX <== length(Str1)
xor ch, ch ; ditto
inc si ;point to 1st char of string
mov dl, es:[di] ;DX <== length(Str2)
xor dh, dh ; ditto
inc di ;point to 1st char of string
mov bh, cl ;save lengths for later
mov bl, dl
cmp cl, dl ;use shorter length
jb s1 ;skip if CL has short one
xchg cl, dl ;otherwise switch them
s1 or cl, cl ;null string?
jz s2 ;skip if so
repe ;perform string comparison
cmpsb
jne s4
s2 cmp bh, bl ;substrings equal? if so,
;resolve by length comparison
s3 jne s4 ;test for equal option
xor ax, ax ;send 0 for equal
jmps exit
s4 jb s5 ;St1 > St2?
mov ax, 0001H ;send 1 if St1 greater
jmps exit
s5 mov ax, 0002H ;send 2 if St2 greater
exit pop ds
pop bp
ret 0AH
endp