DATAS SEGMENT
MSG1 DB 'Please enter a string of characters:','$'
MSG2 DB 'Number of numbers:','$'
MSG3 DB 'Number of letters:','$'
MSG4 DB 'Number of others:','$'
BUF DB 0FFH ;最多输入254个
DB ? ;实际输入个数
DB 0FFH DUP(?) ;输入缓冲区
RESULT DB 3 DUP(0)
DATAS ENDS
C_OUTPUT MACRO ASC ;定义单字符输出宏
MOV DL,ASC
MOV AH,02H
INT 21H
ENDM
S_OUTPUT MACRO ASC ;定义句子输出宏
LEA DX,ASC
MOV AH,09H
INT 21H
ENDM
CRLF MACRO ;定义回车、换行输出宏
C_OUTPUT 0AH
C_OUTPUT 0DH
ENDM
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
MAIN PROC FAR ;主程序
START:
MOV AX,DATAS
MOV DS,AX
CALL INPUT
CALL COUNT
CALL SHOW_RESULT
MOV AH,4CH
INT 21H
MAIN ENDP
INPUT PROC ;字符串输入子程序
S_OUTPUT MSG1
LEA DX,BUF
MOV AH,0AH
INT 21H
CRLF
RET
INPUT ENDP
COUNT PROC ;字符分类统计
LEA SI,BUF+2
CLD
BEGIN:
LODSB
CMP AL,30H
JB OTHER
CMP AL,3AH
JB NUMBER
CMP AL,41H
JB OTHER
CMP AL,5BH
JB CHAR
CMP AL,61H
JB OTHER
CMP AL,7BH
JB CHAR
JMP OTHER
OTHER:
INC RESULT+1
JMP CONTINUE
CHAR:
INC RESULT+2
JMP CONTINUE
NUMBER:
INC RESULT+3
JMP CONTINUE
CONTINUE:
DEC BUF+1
JNZ BEGIN
RET
COUNT ENDP
SHOW_RESULT PROC ;分类结果展示
MOV SI,1
S_OUTPUT MSG4
CALL BINIDEC
CRLF
MOV SI,2
S_OUTPUT MSG3
CALL BINIDEC
CRLF
MOV SI,3
S_OUTPUT MSG2
CALL BINIDEC
CRLF
RET
SHOW_RESULT ENDP
BINIDEC PROC ;二进制转换为10进制并输出
LEA BX,RESULT
MOV AL,[BX][SI] ;取出保存的计数结果
AND AX,00FFH
CMP AL,64H ;判断结果是否大于100
JA THREE
CMP AL,0AH ;判断结果是否大于10
JA TWO
JMP ONE
THREE: ;结果除以100得到百位数
MOV DL,64H
DIV DL
PUSH AX
ADD AL,30H
C_OUTPUT AL
POP AX
MOV AL,AH
AND AX,00FFH
JMP TWO
TWO: ;得到十位数
MOV DL,0AH
DIV DL
PUSH AX
ADD AL,30H
C_OUTPUT AL
POP AX
MOV AL,AH
AND AX,00FFH
JMP ONE
ONE: ;得到个位数
ADD AL,30H
C_OUTPUT AL
RET
BINIDEC ENDP
CODES ENDS
END MAIN