loops - 汇编语言 x86 - 寄存器集、算术和循环
问题描述
我正在尝试解决有关循环的问题。我使用的是推送和弹出方法,而不是使用单独的寄存器来存储数据。
.model small
.stack
.code
m proc
mov ax,0b800h
mov es,ax
mov di,7d0h
mov ah,7 ; normal attribute
mov al,'A'
mov cx,5
x: stosw
push ax ;mov dl,al ; dl='A'
push di
mov al,'1'
stosw
pop di
add di,158
pop ax ;mov al,dl
inc al
loop x
mov ah,4ch
int 21h
m endp
end m
我无法循环播放mov al, '1'
.
输出应该是这样的:
A1
B2
C3
D4
E5
任何人都可以显示正确的代码吗?谢谢你。
解决方案
考虑所涉及的 ASCII 码:
Letter Digit Difference
A1 65 49 16
B2 66 50 16
C3 67 51 16
D4 68 52 16
E5 69 53 16
看到差异总是 16 吗?这就是下一个解决方案所利用的:
...
mov ax, 0700h + 'A' ; WhiteOnBlack 'A'
x: stosw ; Stores one letter from {A, B, C, D, E}
sub al, 'A' - '1' ; Convert from letter to digit
stosw ; Stores one digit from {1, 2, 3, 4, 5}
add al, 'A' - '1' + 1 ; Restore AL and at the same time increment
add di, 160 - 4 ; Move down on the screen
cmp al, 'E'
jbe x
...
您并不总是需要使用CX
和LOOP
指令来处理循环。无论如何,LOOP
出于速度原因,应避免使用该指令!
推荐阅读
- mongodb - 在带有 mgo 驱动程序的 Upsert 上使用 $setOnInsert
- json - 打开一堆 JSON 文件并更改一个键的值
- ios - 一周左右后如何调试 react-native iOS 应用程序在启动时崩溃
- node.js - 通过公开环聊创建 Google 日历活动
- sql - 如何获取其中包含“/”的数字
- heroku - Heroku 上的 Monorepo 出现“bash: node: command not found”错误
- python - Python“For Loop”在调试模式下工作,但从终端正常运行时却不行?
- bash - 如何编写文本文件,然后在同一个 Bash 脚本中读取它?
- sql - 无法连接到末尾带有 CHAR(0) 的字符串
- javascript - .expect 断言在页面模型中移动到函数时不起作用