对上面编写的程序进一步修改,若连续键入三个8,在显示器上显示“Good number”。按ESC键结束程序返回DOS。
时间: 2023-12-03 11:44:27 浏览: 59
下面是修改后的程序:
```assembly
.model small
.stack 100h
.data
msg1 db 'Enter a number (press Esc to exit): $'
msg2 db 'Good number', 0
count db 0
.code
mov ax, @data
mov ds, ax
start:
; print message to enter a number
mov ah, 9
lea dx, msg1
int 21h
; read a key from keyboard
mov ah, 1
int 21h
; check if the key is 8
cmp al, '8'
jne not_eight
; increment count and check if it is 3
inc count
cmp count, 3
jne not_good_number
; print "Good number" message
mov ah, 9
lea dx, msg2
int 21h
; reset count
mov count, 0
not_good_number:
jmp start
not_eight:
; check if the key is ESC
cmp al, 27
jne start
; exit program
mov ah, 4ch
int 21h
end
```
程序运行时,每次输入一个字符,程序会先检查这个字符是否为数字8,如果是,则累加计数器,如果累加后计数器的值为3,则在显示器上输出“Good number”;如果不是数字8,则直接跳回到输入下一个字符的步骤。如果输入的字符是ESC键,则程序退出并返回DOS。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)