以下程序对你的问题做了简化,只统计字母、数字、其他,供参考。
code segment
assume cs:code
org 100h
start: jmp bb
instr db 256 dup(' ')
db 10,13,'$'
innum dw 0
letstr db 10,13,'Letter:'
letter db 256 dup(' ')
letternum dw 0
numstr db 10,13,'Number:'
number db 256 dup(' ')
numbernum dw 0
othstr db 10,13,'Othser:'
other db 256 dup(' ')
othernum dw 0
;=======
bb: push cs
pop es
push cs
pop ds
lea di,instr
bb1: mov ah,1
int 21h
cmp al,13
je next1
mov [di],al
inc word ptr[innum]
inc di
jmp bb1
next1:
lea si,instr
mov cx,innum
lp:
cmp byte ptr[si],'0'
jl n2
cmp byte ptr[si],'9'
jg n2
mov al,[si]
mov di,numbernum
mov byte ptr number[di],al
inc word ptr[numbernum]
jmp n5
n2:
cmp byte ptr[si],'a'
jl n3
cmp byte ptr[si],'z'
jg n3
mov al,[si]
mov di,letternum
mov byte ptr letter[di],al
inc word ptr[letternum]
jmp n5
n3:
cmp byte ptr[si],'A'
jl n4
cmp byte ptr[si],'Z'
jg n4
mov al,[si]
mov di,letternum
mov byte ptr letter[di],al
inc word ptr[letternum]
jmp n5
n4:
mov al,[si]
mov di,othernum
mov byte ptr other[di],al
inc word ptr[othernum]
n5:
inc si
loop lp
;=============
mov di,letternum
mov byte ptr letter[di+1],'$'
mov di,numbernum
mov byte ptr number[di+1],'$'
mov di,othernum
mov byte ptr other[di+1],'$'
;==========
mov ah,9
lea dx,letstr
int 21h
mov ah,9
lea dx,numstr
int 21h
mov ah,9
lea dx,othstr
int 21h
mov ax,letternum
call show
mov ax,numbernum
call show
mov ax,othernum
call show
mov ah,4ch
int 21h
;============
show proc near
push cx
push dx
push di
push ax
mov ah,2
mov dl,10
int 21h
mov dl,13
int 21h
pop ax
mov di,10
xor cx,cx
p1: xor dx,dx
div di
add dx,30h
push dx
inc cx
cmp ax,0
jne p1
mov ah,2
p2: pop dx
int 21h
loop p2
pop di
pop dx
pop cx
ret
show endp
code ends
end start