题目要求
统计字符数。从键盘输入一行字符,统计字母、空格、数字、其他宇符的个数,并显示。要求:提示输入一行宇符串;键盘输入宇符串,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 ENDSSTACKS SEGMENT;此处输入堆栈段代码
STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS
START:MOV AX,DATASMOV DS,AX;此处输入代码段代码mov ch, 0 ;字母mov cl, 0 ;空格mov bh, 0 ;数字mov bl, 0 ;其他字符input:MOV AH, 1 INT 21Hcmp al, 13je outputcmp al, ' 'je isSpacecmp al, '0'jl isOthercmp al, '9'jle isNumcmp al, 'A'jl isOthercmp al, 'Z'jle isAlpcmp al, 'a'jl isOthercmp al, 'z'jle isAlpjmp isOtherisSpace:inc cljmp inputisOther:inc bljmp inputisNum:inc bhjmp inputisAlp:inc chjmp inputoutput:add ch, '0'add cl, '0'add bh, '0'add bl, '0'MOV DX, OFFSET alpCountMOV AH, 09INT 21HMOV DL, chMOV AH,02HINT 21HMOV DX, OFFSET spaceCountMOV AH, 09INT 21HMOV DL, clMOV AH,02HINT 21HMOV DX, OFFSET numCountMOV AH, 09INT 21HMOV DL, bhMOV AH,02HINT 21HMOV DX, OFFSET otherCountMOV AH, 09INT 21HMOV DL, blMOV AH,02HINT 21HMOV AH,4CHINT 21H
CODES ENDSEND START