;統計字符串中大寫字母、小寫字母、數字、其他字符的個數
DATAS SEGMENT
buf db '12ADdf#gh592HKL*','$'
tp1 db 0;大寫字母個數
tp2 db 0;小寫字母個數
tp3 db 0;數字的個數
tp4 db 0;其他字符的個數
str1 db 'the number of big is:','$'
str2 db 'the number of small is:','$'
str3 db 'the number of number is:','$'
str4 db 'the number of other is:','$'
str5 db 0dH,0aH,'$';換行
DATAS ENDS
STACKS SEGMENT
;此處輸入堆棧段代碼
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
lea si, buf
mov cx, 16;設置循環次數
again:
;字符串結尾,結束程序
cmp byte ptr[si],'&'
je exit
;0-9
cmp byte ptr[si],30h;小於30,其他字符加1
jb L1
cmp byte ptr[si],39h;大於39進一步比較
jbe L2
cmp byte ptr[si],41h
jb L1
cmp byte ptr[si],5AH
jbe L3
cmp byte ptr[si],61h
jb L1
cmp byte ptr[si],7AH
jbe L4
L1:
inc tp4
jmp L5
L2:
inc tp3
jmp L5
L3:
inc tp1
jmp L5
L4:
inc tp2
jmp L5
L5:
add si,1
loop again
;顯示大寫字母
lea dx,str1
mov ah,09h
int 21h
mov bl,tp1
call disp ;調用子程序
mov ah,09h
lea dx,str5
int 21h
;顯示小寫字母
lea dx,str2
mov ah,09h
int 21h
mov bl,tp2
call disp ;調用子程序
mov ah,09h
lea dx,str5
int 21h
;顯示數字
lea dx,str3
mov ah,09h
int 21h
mov bl,tp3
call disp ;調用子程序
mov ah,09h
lea dx,str5
int 21h
;顯示其他
lea dx,str4
mov ah,09h
int 21h
mov bl,tp4
call disp ;調用子程序
mov ah,09h
lea dx,str5
int 21h
exit:
MOV AH,4CH
INT 21H
disp PROC ;顯示BX中的數
mov ch,4
roll:
mov cl,4
rol bx,cl
mov dl,bl
and dl,0fh
cmp dl,9
jbe next1
add dl,07h
next1:
add dl,30h
mov ah,02h
int 21h
dec ch
jnz roll
RET
disp ENDP
CODES ENDS
END START
我的CSDN博客地址:http://blog.csdn.net/qw963895582/article
