匯編:統(tǒng)計字符串內(nèi)各種字符的數(shù)目
;3_7 用戶輸入一個由數(shù)字‘0’~‘9’英文大寫字母‘A’~‘Z’;以及英文小寫字母‘a’~‘z’組成的ASCII 字符串,
;字符串的結(jié)束符為 CR(即回車符,其ASCII 碼為0DH),字符串總長度不超過256 個。
;要求統(tǒng)計傳送的字符總數(shù)以及其中各種字符的數(shù)目
DATA SEGMENT
SUM DB 00H ;總數(shù) 計數(shù)器
CAPITAL DB 00h ;大寫字母個數(shù) 計數(shù)器
small db 00h ;小寫字母個數(shù) 計數(shù)器
num db 00h ;數(shù)字個數(shù) 計數(shù)器
result db The amout all of the zifu in this string is ,$
result1 db The amout of the number in the string is ,$
result2 db The amout of the big capital is ,$
result3 db The amout of the small capital is ,$
string db 256 dup (?) ;保存輸入的字符
kongzi DB 0DH,0AH,$ ;換行使用
buffer DB 256 DUP(0) ;目標(biāo)內(nèi)存
results DB 256 DUP(?)
tital db Please input the string you want to be done : ,0dh,0ah,$
tip db Do you want to have a try again (if yes: "y" ,else "n"): ,$
tip1 db welcome to use the program again ,the original is WQ ,$
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
lea dx,tital
mov ah,09h
int 21h
mov di,0
again:
mov ah,01h
int 21h
mov string[di],al
inc di
cmp al,0dh
jnz again
cld ;將方向標(biāo)志位置零 串操作遞增
main: lods string ;字符串裝入指令 把字符串一個個裝入al
INC SUM
CMP AL,0DH
JE DONE
CMP AL,30H
Jb main
cmp al,41h
jb k1
CMP AL,61H
Jb k2
JMP main
DONE:
lea dx,result ;輸出SUM
mov ah,09h
int 21h
DEC SUM
MOV AX,0
MOV AL,SUM
MOV BL,10
DIV BL
MOV DX,AX
ADD DX,3020H ;為什么要加20呢?
cmp dl,30h
jnz wuling
mov dl,20h
wuling:
MOV AH,02h
INT 21H
MOV DL,DH ;這是在干什么?
MOV AH,2h ;2號調(diào)用每次只輸出一個字符,即dl
INT 21H
LEA DX,kongzi ;換行
MOV AH,09H
INT 21H
評論