汇编的练手题2

;从键盘输入一个字符串(长度<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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值