;从键盘输入一个字符串(长度<80),统计其字母、数字及其他字符的个数
.8086
.model small
.stack
BinToDec macro Regs,Memo,Msg;定义宏实现8位寄存器的数转成10进制存到内存的
push ax
mov al,Regs
mov ah,0
mov cl,10
div cl
add al,30h
mov Memo,al
add ah,30h
mov Memo[1],ah
lea dx,Msg
mov ah,9
int 21h
pop ax
endm
.data
Msg1 db 'Please input string:$'
String db 80 dup(?)
Msg2 db 0dh,0ah,'Letter:'
letter db 2 dup(0)
db '$'
Msg3 db 0dh,0ah,'Number:'
number db 2 dup(0)
db '$'
Msg4 db 0dh,0ah,'Other Character:'
character db 2 dup(0)
db '$'
.code
.startup
lea dx,Msg1
mov ah,9
int 21h
mov cx,80
mov bx,0
again:;again后是输入字符串的过程,可以用21号中断中的10号代替
mov ah,1
int 21h
mov string[bx],al
cmp al,0dh
jz count
inc bx
loop again
count:
mov cx,bx
mov si,0
mov bx,0
mov dh,0;bl存储其他字符数目,bh存储数字数目,dh存储字母数目
total:
cmp string[si],'0'
jae number1
inc bl
jmp next
number1:
cmp string[si],'9'
jae total1
inc bh
jmp next
total1:
cmp string[si],'A'
jae letter1
inc bl
jmp next
letter1:
cmp string[si],'Z'
jae total2
inc dh
jmp next
total2:
cmp string[si],'a'
jae letter2
inc bl
jmp next
letter2:
cmp string[si],'z'
jae total3
inc dh
jmp next
total3:
inc bl
next:
inc si
loop total
BinToDec dh,letter,Msg2
BinToDec bh,number,Msg3
BinToDec bl,character,Msg4
.exit 0
end