主要思想,分别与对应的ASCII值从小到大比较,决定是否是字符,数字等
datarea segment
str db "please input a string:$"
buf db 11
db ?
db 11 dup(?)
srlf db 0Ah,0Dh,"$"
count db "integer counts:"
db 1 dup(?) ;数字个数
db " lowercase counts:"
db 1 dup(?) ;小写子母个数
db " capital counts:"
db 1 dup(?) ;大写子母个数
db " other counts:"
db 1 dup(?) ;其它字符的个数
db ' $'
intercounts db '0' ;数字个数
lowercasecounts db '0';小写字符个数
capitalcounts db '0' ;大写字符个数
othercounts db '0' ;其它字符个数
str db "please input a string:$"
buf db 11
db ?
db 11 dup(?)
srlf db 0Ah,0Dh,"$"
count db "integer counts:"
db 1 dup(?) ;数字个数
db " lowercase counts:"
db 1 dup(?) ;小写子母个数
db " capital counts:"
db 1 dup(?) ;大写子母个数
db " other counts:"
db 1 dup(?) ;其它字符的个数
db ' $'
intercounts db '0' ;数字个数
lowercasecounts db '0';小写字符个数
capitalcounts db '0' ;大写字符个数
othercounts db '0' ;其它字符个数
datarea ends
;**************************************
stacks segment
db 200 dup(?) ;申请200个字节空间
stacks ends
prognam segment
;**********************************
main proc far
assume cs:prognam,ds:datarea,ss:stacks
start:
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov ah,9
int 21h
mov ah,10
lea dx,buf
int 21h
lea dx,srlf
mov ah,9
int 21h
mov bx,-1
mov cx,10
lopt:
add bx,1
mov al,buf[bx]
mov ah,0
cmp ax,30h ;和0的ASCII码作比较
jz lopint
js lopoth
cmp ax,39h ;和9的ASCII码作比较
jz lopint
js lopint
cmp ax,41h ;和A的作比较
jz lopcap
js lopoth
cmp ax,5Ah ;和Z作比较
jz lopcap
js lopcap
cmp ax,61h ;和a作比较
jz loplow
js lopoth
cmp ax,7ah ;和Z作比较
jz loplow
js loplow
jmp lopoth
lopint: ;给数字个数加一
add intercounts,1
loop lopt
jmp addcount
loplow: ;给小写子母个数加1
add lowercasecounts,1
loop lopt
jmp addcount
lopcap: ;给大写子母个数加一
add capitalcounts,1
add bx,1
loop lopt
jmp addcount
lopoth: ;给其他字符加一
add othercounts,1
loop lopt
jmp addcount
addcount: ;将数都加到字符串count的问号位置
mov al,intercounts
mov count[15],al
mov al,lowercasecounts
mov count[33],al
mov al,capitalcounts
mov count[51],al
mov al,othercounts
mov count[66],al
mov dx,offset count
mov ah,09h
int 21h
mov ah,4ch
int 21h
int 21h
mov ah,10
lea dx,buf
int 21h
lea dx,srlf
mov ah,9
int 21h
mov bx,-1
mov cx,10
lopt:
add bx,1
mov al,buf[bx]
mov ah,0
cmp ax,30h ;和0的ASCII码作比较
jz lopint
js lopoth
cmp ax,39h ;和9的ASCII码作比较
jz lopint
js lopint
cmp ax,41h ;和A的作比较
jz lopcap
js lopoth
cmp ax,5Ah ;和Z作比较
jz lopcap
js lopcap
cmp ax,61h ;和a作比较
jz loplow
js lopoth
cmp ax,7ah ;和Z作比较
jz loplow
js loplow
jmp lopoth
lopint: ;给数字个数加一
add intercounts,1
loop lopt
jmp addcount
loplow: ;给小写子母个数加1
add lowercasecounts,1
loop lopt
jmp addcount
lopcap: ;给大写子母个数加一
add capitalcounts,1
add bx,1
loop lopt
jmp addcount
lopoth: ;给其他字符加一
add othercounts,1
loop lopt
jmp addcount
addcount: ;将数都加到字符串count的问号位置
mov al,intercounts
mov count[15],al
mov al,lowercasecounts
mov count[33],al
mov al,capitalcounts
mov count[51],al
mov al,othercounts
mov count[66],al
mov dx,offset count
mov ah,09h
int 21h
mov ah,4ch
int 21h
ret
main endp
prognam ends
end start
main endp
prognam ends
end start