汇编代码
DATAS SEGMENT
;此处输入数据段代码
letter db 0
digit db 0
other db 0
temp db 31,32 dup(?)
print db 'Please input a string:','$',13,10
digitnum db 13,10 ,"the total number of digit:","$"
letternum db 13,10 ,"the total number of letter:","$"
othernum db 13,10 ,"The total number of other character:","$"
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
lea dx,print
mov ah,09h
int 21h
lea dx,temp
mov ah,0ah
int 21h
mov si,1
lea bx,temp;取字符
mov cl,[bx+si];将用户输入字符个数赋值给cl寄存器,作为循环次数
add si,1
cmpseg:
mov al,[bx+si]
cmp al,0
je disp
cmp al,'0'
jae digitb
cmp al,'a'
jae letterb1
cmp al,'A'
jae letterb2
call otheradd
digitb:
cmp al,'9'
jbe digitadd
letterb1:
cmp al,'z'
jbe letteradd
letterb2:
cmp al,'Z'
jbe letteradd
digitadd:
;add digit,1
add si,1
inc byte ptr[digit]
loop cmpseg
letteradd:
;add letter,1
add si,1
inc byte ptr[letter]
loop cmpseg
otheradd:
add si,1
inc byte ptr[other]
loop cmpseg
disp:
lea dx, digitnum
mov AH, 09h
int 21h
mov dl,[digit]
add dl,30h
mov ah,2h
int 21h
lea dx, letternum
mov AH, 09h
int 21h
mov dl,[letter]
add dl,30h
mov ah,2h
int 21h
lea dx, othernum
mov AH, 09h
int 21h
mov dl,[other]
add dl,30h
mov ah,2h
int 21h
MOV AH,4CH
INT 21H
CODES ENDS
END START