我今天在考试中得到了这个问题,我为它写了一些代码。我想让你告诉我我哪里出错了。
问题:对于 8086 微处理器,编写执行以下任务的代码。它要求用户输入数据并计算按键次数。
在执行 ALP 时,获得第一条消息“计数按键次数,按退出键停止”。(不带引号),如果用户输入转义,则显示第二条消息“counting keypresses”,并将计数结果存储在 BX 中并以二进制显示。也按下键(输入数据时),输入键应在下一行回显。
解决方案:(我写的)
.model tiny
.data
text1 db "counting keypresses,press escape to stop $"
text2 db "counting keypresses"
.code
.startup
mov dx,offset text1 ;displaying text1 (i guess so)
mov ah,09h
int 21h
and bx,00h
label1 mov ah,01h ;(getting input from user and incrementing bx on every click)
int 21h
inc bx
cmp al,1bh ;comparing with 'escape'
np label1
mov dx,offset text2 ;if zero then do this i.e display text2
mov ah,09h
int 21h
mov dx,offset bx ;display bx
mov ah,09h
int 21h
.exit
end
我不确定我添加的评论是否合适。我知道我的代码不正确,事实上它根本不正确,但我设法在我一晚准备的基础上写了这个。所以如果有人能告诉我,我做错了什么,那么我将非常感激. 因为我真的需要在下次考试中表现出色。