⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string1.asm

📁 建立歌曲文档
💻 ASM
字号:
;This program is to find the times of "computer" in a string.
;Designer:yankun

stack segment para stack 'stack'
        dw 128 dup(?)
stack ends
;**************************************************************


data segment para 'data'
a  	 	db 	100 dup(?)
array  	db	40 dup(?)
wd		db	'computer'
frame		db	"***********************************************************$ "

tip	 	db	13d,10d,"Input the string:(enter space to end)$"
tip1	 	db	13d,10d,"The count of compurter is:$"
tip2	 	db	13d,10d,"No such word!$"

data ends
;**************************************************************
code segment 
    assume cs:code,ds:data,ss:stack
main proc far
start:
        mov ax,data
        mov ds,ax  ;let ds register have data segment address
            
            call        introduce
		call		input
		call 		space
		call 		count
		mov		ah,07
		int		21h
		ret
main 		endp
 ;**************************************************************
;Introduce								 ;//输出提示语句以及菜单

introduce 	proc		near
		lea         dx,frame
		mov		ah,09
		int		21h

		call		space
		lea         dx,frame
		mov		ah,09
		int		21h
		ret
introduce	endp

		


;***************************************************************
;Input a string							;//输入一字符串,保存在空间 a 里。
input	 	proc 		near
		lea 		dx,tip
		mov		ah,09h
		int		21h
		mov 		si,0
	next:	mov		ah,01
		int		21h
		cmp		al,20h
		jz		end1	
		mov		a[si],al
		inc 		si
		jmp		next		
	end1:	mov		a[si],al
		ret 	
input		endp
;****************************************************************
;To present a space							;//输出一个换行

space  	proc		 near
		mov		dl,0dh
		mov 		ah,02
		int		21h
		mov		dl,0ah
		mov		ah,02
		int		21h
		ret
space 	endp

;***************************************************************
;Count the times of  the word "computer"				;//查找计数过程
count		proc		near
		mov		bx,0


            mov		si,0
		mov		di,0
	first:cmp		a[si],20h
		jz		over
		mov		al,wd[di]					;//将COMPUTER单词放在wd字符串里
		cmp		al,a[si]					;//比较
		je		next1						;//相等进入内层循环
		inc		si
		jmp		first
     next1: cmp		di,7						;//内层循环判断是否完全匹配
		jz		addno
		inc		si
		inc		di
		jmp		first	
	addno:inc		bx						;//计数加一
		inc		si
		mov		di,0
		jmp		first
	over: cmp		bx,0						;//比较完毕
		jz		nofind
		lea		dx,tip1
		mov		ah,09h
		int		21h
		call        output					;//调用输出函数	
            jmp		exit
    nofind: lea		dx,tip2
		mov		ah,09h
		int		21h
	exit: ret

count   endp
;**********************************************************************************
;Output the times								;//将次数转化为十进制数来输出
output   	proc		near
		mov 		di,-1
    		mov 		ax,bx
     
thenext:
    		inc 		di
    		mov 		cl,10d   
    		div 		cl
    		mov 		array[di],ah
    		xor 		ah,ah
    		cmp 		al,0
    		jz  		print
    		jmp  		short thenext
    	
print:
            cmp 		di,0
   		jl  		wo
    	  	add		array[di],48
    		mov 		dl,array[di]
    		mov 		ah,02
    		int 		21h
    		sub 		di,1
    		jmp 		short print
   
wo: 		ret
output endp
;*************************************************************************8

code ends
        	end start









⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -