江编最后一个程序

本文介绍了一个使用汇编语言实现的简单程序,该程序提示用户输入文本,并统计输入中0到9数字字符出现的次数。通过具体的代码示例,展示了如何使用INT 21H中断来显示消息、读取用户输入并处理ASCII码。

DATAS SEGMENT
msg db "Please input text : ",'$'
buf db 15
db ?
b2 db 15 dup(?)
db 13,10,'$'
result db 13,10,"the result is:",'$'
DATAS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS
START:
MOV AX,DATAS
MOV DS,AX

;;;;;;;;;;; BEGIN ;;;;;;;;;;;;;;;;;

mov ah, 9
mov dx,offset msg
int 21h ;display the msg:Please input:

mov ah, 0ah
mov dx,offset buf ;wait for input and save the text to the buf
int 21h

mov si,offset buf
inc si
xor cx,cx
mov cl,[si]

mov dl,cl
mov ah,2
;int 21h

mov dl,30h
compare: ;loop to compare to 0 and 9
inc si
mov al,[si]
cmp al,39h ;big than 9
ja plus
cmp al,30h ;low than 0
jb plus
jmp again
plus:
inc dl ;count ++
again:
loop compare ;loop again
mov cl,dl
mov ah,9
mov dx,offset result
int 21h ;output information: the result is

mov ah,2
mov dl,cl
int 21h ;output the count

;;;;;;;;;;;;;; END ;;;;;;;;;;;;;;

MOV AH,4CH
INT 21H ;program exit to dos
CODES ENDS
END START
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值