;从键盘输入一系列字符(以回车键结束),并按字母、数字及其它
;字符分类统计,最后显示这三类的统计结果
DATA SEGMENT
BUFFER DB 128,?,128 DUP(0)
NUM DW 0
WORDS DW 0
OTHER DW 0
CRLF DB 0AH,0DH,'$'
DATA ENDS
STACK SEGMENT PARA STACK
DW 128 DUP(?)
TOP LABEL WORD
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,SS:STACK,DS:DATA
MAIN PROC FAR
START:
MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
LEA SP,TOP
LEA DX,BUFFER ;INT 21H的0AH号功能:接收键盘字符串输入并以回车键结束
MOV AH,0AH
INT 21H
MOV AH,9
LEA DX,CRLF
INT 21H
LEA SI,BUFFER
INC SI
MOV CL,[SI]
XOR CH,CH
L0: INC SI
MOV AL,[SI]
CMP AL,30H ;判断数字
JL L1
CMP AL,39H
JA L1
INC NUM
JMP L4
L1: CMP AL,'A' ;判断大写字母
JL L2
CMP AL,'Z'
JA L2
INC WORDS
JMP L4
L2: CMP AL,'a' ;判断小写字母
JL L3
CMP AL,'z'
JA L3
INC WORDS
JMP L4
L3: INC OTHER ;若不是上面3类字符,则一定是其他字符
L4: LOOP L0
MOV CX,3
LEA SI,NUM
L5: MOV AH,2
MOV DX,[SI]
ADD DL,30H
INT 21H
ADD SI,2
MOV AH,9
LEA DX,CRLF
INT 21H
LOOP L5
MOV AH,4CH
INT 21H
CODE ENDS
MAIN ENDP
END START