分类统计字符个数
- 格式:doc
- 大小:26.50 KB
- 文档页数:3
程序接收用户键入的一行字符(用回车符结束),并按字母,数字及其他字符分类
计数,然后将结果存入以letter,digit和other为名的存储单元中。
DATAS SEGMENT
string db 32,0,32 dup(?)
letter db 0
digit db 0
other db 0
DATAS ENDS
STACKS SEGMENT
STACKS ENDS
CODES SEGMENT
main proc far
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
push ds
sub ax,ax
push ax
mov dx,datas ;datas segment addr
mov ds,ax ;into ds register
mov es,ax ;into es register
lea dx,string
mov ah,0ah
int 21h
mov letter,0
mov digit,0
mov other,0
sub cx,cx
mov cl,string+1
lea bx,string+2
l0:
mov al,[bx]
cmp al,30h
jl l1
cmp al,39h
jl l2
cmp al,41h
jl l1
cmp al,5ah
jl l3
cmp al,60h
jl l1
cmp al,7ah
jl l3
cmp al,7ah
jg l1
l1:
inc other
jmp l4
l2:
inc digit
jmp l4
l3:
inc letter
jmp l4
l4:
add bx,1
loop l0
add digit,30h
mov dl,digit
mov ah,02h
int 21h
add letter,30h
mov dl,letter
mov ah,02h
int 21h
add other,30h
mov dl,other
mov ah,02h
int 21h
mov ah,4ch
int 21h
ret
main endp
CODES ENDS
END START