查找匹配字符串所在的位置【精品文档-doc】
查找匹配字符串所在的位置
data segment
keyword db 11,0,11 dup(?)
sentence db 50,0,50 dup(?)
exit_yon db 2,0,2 dup(?)
mess1 db 'Enter Keyword:','$'
mess2 db 'Enter Sentence:','$'
mess3 db 'Match at location:','$'
mess4 db ' H of the sentence.','$'
string1 db 'No Match!',13,10,'$' data ends
code segment
assume cs:code,ds:data,es:data start:
mov ax,data
mov ds,ax
mov es,ax
lea dx,mess1
mov ah,09h
int 21h
lea dx,keyword
mov ah,0ah
int 21h
mov bx,dx
lea si,keyword
add si,2
mov cx,[bx+1]
mov keywo_num,cx
call crlf
lea dx,mess2
mov ah,09h
int 21h
lea dx,sentence
mov ah,0ah
int 21h
mov bx,dx
lea di,sentence
add di,2
mov cx,[bx+1]
mov sent_num,cx
and cx,00ffh
mov ax,keywo_num
and ax,00ffh
sub cx,ax
jl matchno
mov cx,keywo_num
and cx,000fh
mov bx,di
jmp compare cmpnext:
mov dx,bx
lea ax,sentence
add ax,02h
sub dx,ax
mov ax,sent_num
and ax,00ffh
sub ax,dx
mov dx,keywo_num
and dx,00ffh
sub ax,dx
jz matchno
inc bx
mov di,bx
lea si,keyword
add si,2
mov cx,keywo_num
and cx,00ffh compare:
mov dx,[di]
mov ax,[si]
cmp dl,al
jnz cmpnext
inc di
inc si
loop compare matchyes:
call crlf
lea dx,mess3
mov ah,09h
int 21h
lea ax,sentence
sub bx,ax
dec bx
call printf_h
lea dx,mess4
mov ah,09h
int 21h
jmp exit
matchno:
call crlf
lea dx,string1
mov ah,09
int 21h
again:
jmp start
programend:
mov ah,4ch
int 21h
crlf proc near
mov dl,13
mov ah,02h
int 21h
mov dl,10
mov ah,02h
int 21h
ret
crlf endp
printf_h proc near
mov al,bl
and al,11110000b
mov cl,4h
shr al,cl
mov dl,al
sub dl,09h
jle o_num1
add al,00110000b
add al,07h
mov ah,02h
mov dl,al
int 21h
jmp lobit
o_num1:
add al,00110000b
mov ah,02h
mov dl,al
int 21h
lobit:
mov al,bl
and al,00001111b
mov dl,al
sub dl,09h
jle o_num2
add al,00110000b
add al,07h
mov ah,02h
mov dl,al
int 21h
jmp printfh_exit o_num2:
add al,00110000b
mov ah,02h
mov dl,al
int 21h
printfh_exit:
ret
printf_h endp
code ends
end start