汇编实验 查找匹配的字符串

;PROGRAM TITLE GOES HERE–search
;*******************************
datarea segment
mess1 db ‘Enter keyword:’,’ ′ m e s s 2 d b ′ E n t e r S e n t e n c e : ′ , ′ ' mess2 db 'Enter Sentence:',' mess2dbEnterSentence:,
mess3 db ‘Match at location:’,’ ′ m e s s 4 d b ′ N o m a t c h ! ′ , 13 , 10 , ′ ' mess4 db 'No match!',13,10,' mess4dbNomatch!,13,10,
mess5 db ‘match.’,13,10,’$ ’
mess6 db ‘H of the sentence.’,13,10,’$ ’
;
stoknin1 label byte
max1 db 10
act1 db ?
stokn1 db 10 dup(?)
;
stoknin2 label byte
max2 db 50
act2 db ?
stokn2 db 50 dup(?)
datarea ends
;*********************************
prognam segment
;---------------------------------
main proc far
assume cs:prognam ,ds:datarea,es:datarea
start::
push ds
sub ax,ax
sub bx,bx
push ax
mov ax,datarea
mov ds,ax
mov es,ax
;MAIN PART-------------
lea dx,mess1 ;输入关键字
mov ah,09
int 21h
lea dx,stoknin1
mov ah,0ah
int 21h
cmp act1,0
je exit
a10: ;输入句子
call crlf
lea dx,mess2
mov ah,09
int 21h
lea dx,stoknin2
mov ah,0ah
int 21h
cmp act2,0
je nmatch
mov al,act1
cbw
mov cx,ax
push cx
mov al,act2
sub al,act1
js nmatch
mov di,0
mov si,0
lea bx,stokn2;
inc al
a20:
mov ah,[bx+di] ;开始比较
cmp ah,stokn1[si] ;不等则转到bx+1
jne a30 ;bx+1
inc si
inc di
;inc bx
dec cx
cmp cx,0
je match
jmp a20
a30:
inc bx
dec al
cmp al,0
je nmatch
mov si,0
mov di,0
pop cx
push cx
jmp a20
exit:
call crlf
ret
nmatch: ;no match则输出No match
call crlf
lea dx,mess4
mov ah,09
int 21h
jmp a10
match: ;match则输出位置信息
call crlf
lea dx,mess3
mov ah,09
int 21h
sub bx,offset stokn2
inc bx
call trans
lea dx,mess6
mov ah,09
int 21h
jmp a10
crlf proc near ;回车,换行
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
crlf endp
trans proc near ;转换为16进制,参考书上例6.3
mov ch,4 ;number of digits
rotate: mov cl,4 ;set count to 4bits
rol bx,cl ;left digit to right
mov al,bl ;mov to al
and al,0fh ;mask off left digit
add al,30h ;convert hex to ASCII
cmp al,3ah ;is it>9?
jl printit ;jump if digit=0 to 9
add al,7h ;digit is A to F
printit:
mov dl,al ;put ASCII char in DL
mov ah,2 ;Display Output funct
int 21h ;call DOS
dec ch ;done 4 digits?
jnz rotate ;not yet
ret ;return from trans
trans endp ;
main endp
;----------------------------------
prognam ends
;**********************************
end start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值