www.pudn.com > long3.rar > long3.Asm


 
;输入一个字符串,长度小于80,统计其字母,数字与其它字符的个数 
.386 
 
;* 数据段  
;****************************************************** 
dseg	segment	use16 
 
;------------------------------------------------------ 
;MY OWN DATA 
 
be	db	'please input your string: ','$' 
 
data    db	80,?,80 dup(?) 
output  db	'The string has',0dh,0ah 
num	db	0,20h,20h 
	db	'numbers' ,0dh,0ah 
char	db	0,20h,20h 
	db	'letters',0dh,0ah 
other	db	0,20h,20h 
	db	'other characters','$' 
 
d	db 	5 dup(?)	 
;------------------------------------------------------ 
 
dseg	ends 
 
 
 
 
 
;****************************************************** 
;* 代码段  
;****************************************************** 
 
cseg	segment	use16 
;------------------------------------------------------ 
         
assume	ds:dseg,cs:cseg 
start:	mov ax,dseg 
	mov ds,ax 
	 
;------------------------------------------------------ 
;MY OWN CODE 
 
 
 
 
;提示输入 
		lea dx,be 
		mov ah,9 
		int 21h 
;输入字符串 
		lea dx, data 
		mov ah,0ah 
		int 21h 
		 
		 
 
 
 
 
;判断 
	 
		mov bx,1 
		 
 
check:		inc bx 
		cmp data[bx],0dh 
		je deal 
 
		cmp  data[bx],30h	 
		jb  others 
		cmp data[bx],7ah 
		ja  others 
 
		cmp  data[bx],39h 
		jbe  numbers 
		cmp  data[bx],61h 
		jae  	chars 
 
		cmp  data[bx],41h 
		jb  others 
		cmp  data[bx],5ah 
		ja  others 
 
		 
chars:		inc char		 
		jmp check 
			 
others:		inc other 
		jmp check		 
				 
 
numbers:	 
		inc num		 
		jmp check 
		 
 
deal:		 
		mov ax,0 
		mov al,num 
		call bintodec 
		mov 	ax,	word ptr d 
		mov	word ptr num, ax 
		 
		 
		mov al,char 
		call bintodec 
		mov 	ax,	word ptr d 
		mov	word ptr char, ax 
	 
		mov al,other 
		call bintodec 
		mov 	ax,	word ptr d 
		mov	word ptr other, ax 
	 
		 
 
exit:		 
		 
		mov dl,0dh 
		mov ah, 2 
		int 21h 
		mov dl ,0ah 
		mov ah,2 
		int 21h 
 
		lea dx,output 
		mov ah,9 
		int 21h 
 
;------------------------------------------------------ 
 
              MOV       ah,4CH 
              int       21H 
bintodec	proc 
		push	ax 
		push	bx 
		push	dx 
		push	si 
		push	di 
		mov 	si,	0 
		 
		or	ax,	ax 
		jz	selfexit 
		xor	bl,	bl 
		lea	di,	table 
selfnext:	cwd 
		div	word ptr cs:[di] 
		cmp	bl,	0 
		jnz	writeinto 
		cmp	al,	0 
		je	skip 
		mov	bl,	1 
writeinto:	or	al,	30h 
		mov	d[si],	al 
		inc	si 
skip:		mov	ax,	dx 
		add	di,	2 
		cmp	cs:word ptr [di], 1 
		jne	selfnext 
selfexit:	or	al,	30h 
		mov	d[si],	al 
		inc	si 
		 
		pop	di 
		pop	si 
		pop	dx 
		pop	bx 
		pop	ax 
		ret 
table		dw	10000,1000,100,10,1 
bintodec	endp 
 
     
;------------------------------------------------------ 
cseg      ends 
;****************************************************** 
             end	start  ;程序结束