题目要求
统计字符数。从键盘输入一行字符,统计字母、空格、数字、其他宇符的个数,并显示。要求:提示输入一行宇符串;键盘输入宇符串,Enter 键结束输入,并换行显示结果。
题目代码
DATAS SEGMENT
;此处输入数据段代码
msg DB 0ah, 0dh, 'please input string enter:quit$'
alpCount DB 0ah, 0dh, 'alpCount:$'
spaceCount DB 0ah, 0dh, 'spaceCount:$'
numCount DB 0ah, 0dh, 'numCount:$'
otherCount DB 0ah, 0dh, 'otherCount:$'
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
;此处输入代码段代码
mov ch, 0 ;字母
mov cl, 0 ;空格
mov bh, 0 ;数字
mov bl, 0 ;其他字符
input:
MOV AH, 1
INT 21H
cmp al, 13
je output
cmp al, ' '
je isSpace
cmp al, '0'
jl isOther
cmp al, '9'
jle isNum
cmp al, 'A'
jl isOther
cmp al, 'Z'
jle isAlp
cmp al, 'a'
jl isOther
cmp al, 'z'
jle isAlp
jmp isOther
isSpace:
inc cl
jmp input
isOther:
inc bl
jmp input
isNum:
inc bh
jmp input
isAlp:
inc ch
jmp input
output:
add ch, '0'
add cl, '0'
add bh, '0'
add bl, '0'
MOV DX, OFFSET alpCount
MOV AH, 09
INT 21H
MOV DL, ch
MOV AH,02H
INT 21H
MOV DX, OFFSET spaceCount
MOV AH, 09
INT 21H
MOV DL, cl
MOV AH,02H
INT 21H
MOV DX, OFFSET numCount
MOV AH, 09
INT 21H
MOV DL, bh
MOV AH,02H
INT 21H
MOV DX, OFFSET otherCount
MOV AH, 09
INT 21H
MOV DL, bl
MOV AH,02H
INT 21H
MOV AH,4CH
INT 21H
CODES ENDS
END START