📄 strsrch.asm.bak
字号:
data segment
messin db 'Please input a string:',13,10,'$'
messout db 13,10,'The number of computer included in the string is: $'
strin label byte
max db 100
act db ?
str db 100 dup(?)
count db ?
keyword db 'computer'
data ends
code segment
;-------------------------------------------
main proc far
assume cs:code,ds:data,es:data
start:
push ds
sub ax,ax
push ax
mov ax,data ;数据段不分配好,将导致所有数据都找不到!
mov ds,ax
mov es,ax
call input
call srch
call output
exit:
ret
main endp
;---------------------------
input proc near
lea dx,messin ;输出提示信息
mov ah,09h
int 21h
lea dx,strin ;输入字符串
mov ah,0ah
int 21h
cmp act,0 ;输入字符串为空时直接退出
je exit
ret
input endp
;---------------------------
srch proc near
mov ax,0
mov dl,act ;dx中存储要比较的次数,字符串长度-(查找串长度-1)
mov dh,0
sub dx,7
lea bx,str
comp: mov di,bx
lea si,keyword
mov cx,8 ;每次比较的字符个数等于匹配字符串的长度
repe cmpsb
jnz no_match
inc ax
no_match:
inc bx ;原字符串指针下移
dec dx ;剩余比较次数减一
jnz comp
ret
srch endp
;---------------------------
output proc near
mov count,ax
lea dx,messout ;输出结果提示信息
mov ah,09h
int 21h
mov bx,count
call binidec
ret
output endp
;---------------------------
binidec proc near;用bx传递参数
push bx
push cx
push si
push di
mov cx,10000
call dec_div
mov cx,1000
call dec_div
mov cx,100
call dec_div
mov cx,10
call dec_div
mov cx,1
call dec_div
pop di
pop si
pop cx
pop bx
ret
binidec endp
;---------------------------
dec_div proc near
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,02h
int 21h
ret
dec_div endp
;---------------------------
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -