汇编中的循环:TASM on 8086 (DosBox) Solve on how to Horizontal and Vertical Number
Loops in Assembly: TASM on 8086 (DosBox) Solve on how to Horizontal and Vertical Number
我的代码是:
Mov ah,02
Mov cl,0A
Mov dh,30
Mov dl,dh
Int 21
Mov dl,20
Int 21
Add dh,01
Loop 0106
Mov ah,02
Mov cl,09
Mov bl,31
Mov dl,0A
Int 21
Mov dl,0D
Int 21
Mov dl,bl
Int 21
Add bl,01
Loop 0106
与您的标题所说的使用 TASM 相反,屏幕截图和代码对应于 DOS DEBUG.EXE。看到这个 info about writing a TASM program.
让我们从评论代码开始(这是您在发布之前应该做的事情!):
Mov ah,02 ; DOS.PrintCharacter
Mov cl,0A ; Count for the 1st loop
Mov dh,30 ; '0'
0106 is address of top of the 1st loop.
Mov dl,dh
Int 21 ; This prints a digit
Mov dl,20 ; ' '
Int 21 ; This interjects a space character
Add dh,01 ; Next character
Loop 0106 ; Go to top of the 1st loop
Mov ah,02 ; DOS.PrintCharacter
Mov cl,09 ; Count for the 2nd loop
Mov bl,31 ; '1'
01?? is address of top of the 2nd loop.
Mov dl,0A ; Linefeed
Int 21
Mov dl,0D ; Carriage return
Int 21
Mov dl,bl ; Current character
Int 21
Add bl,01 ; Next character
Loop 0106 ; Go to top of the 1st (????????) loop
第一个循环
- 当你的程序启动时,你不应该依赖pre-existing注册内容。不要假设
CX
寄存器为 0。您需要使用 mov cx, 0A
(十进制 10)初始化循环计数器。 loop
指令依赖于 CX
,而不仅仅是 CL
.
- 屏幕截图第一行的数字之间没有任何 space。您应该删除插入 space 字符
Mov dl,20
Int 21
. 的行
第二个循环
- 这里可以用
mov cl, 09
(十进制数 9)初始化循环计数器,因为之前的 loop
指令将 CX
寄存器留在 0。
- 因为这是一个单独的循环,
loop
指令必须转到另一个目的地。
节目
Mov ah,02 ; DOS.PrintCharacter
Mov cx,0A ; Count for the 1st loop
Mov dl,30 ; '0'
0107 is address of top of the 1st loop.
Int 21 ; This prints a digit
Add dl,01 ; Next character
Loop 0107 ; Go to top of the 1st loop
Mov cl,09 ; Count for the 2nd loop
Mov bl,31 ; '1'
0112 is address of top of the 2nd loop.
Mov dl,0D ; Carriage return
Int 21
Mov dl,0A ; Linefeed
Int 21
Mov dl,bl ; Current character
Int 21
Add bl,01 ; Next character
Loop 0112 ; Go to top of the 2nd loop
int 20 ; DOS.Terminate
我的代码是:
Mov ah,02
Mov cl,0A
Mov dh,30
Mov dl,dh
Int 21
Mov dl,20
Int 21
Add dh,01
Loop 0106
Mov ah,02
Mov cl,09
Mov bl,31
Mov dl,0A
Int 21
Mov dl,0D
Int 21
Mov dl,bl
Int 21
Add bl,01
Loop 0106
与您的标题所说的使用 TASM 相反,屏幕截图和代码对应于 DOS DEBUG.EXE。看到这个 info about writing a TASM program.
让我们从评论代码开始(这是您在发布之前应该做的事情!):
Mov ah,02 ; DOS.PrintCharacter
Mov cl,0A ; Count for the 1st loop
Mov dh,30 ; '0'
0106 is address of top of the 1st loop.
Mov dl,dh
Int 21 ; This prints a digit
Mov dl,20 ; ' '
Int 21 ; This interjects a space character
Add dh,01 ; Next character
Loop 0106 ; Go to top of the 1st loop
Mov ah,02 ; DOS.PrintCharacter
Mov cl,09 ; Count for the 2nd loop
Mov bl,31 ; '1'
01?? is address of top of the 2nd loop.
Mov dl,0A ; Linefeed
Int 21
Mov dl,0D ; Carriage return
Int 21
Mov dl,bl ; Current character
Int 21
Add bl,01 ; Next character
Loop 0106 ; Go to top of the 1st (????????) loop
第一个循环
- 当你的程序启动时,你不应该依赖pre-existing注册内容。不要假设
CX
寄存器为 0。您需要使用mov cx, 0A
(十进制 10)初始化循环计数器。loop
指令依赖于CX
,而不仅仅是CL
. - 屏幕截图第一行的数字之间没有任何 space。您应该删除插入 space 字符
Mov dl,20
Int 21
. 的行
第二个循环
- 这里可以用
mov cl, 09
(十进制数 9)初始化循环计数器,因为之前的loop
指令将CX
寄存器留在 0。 - 因为这是一个单独的循环,
loop
指令必须转到另一个目的地。
节目
Mov ah,02 ; DOS.PrintCharacter
Mov cx,0A ; Count for the 1st loop
Mov dl,30 ; '0'
0107 is address of top of the 1st loop.
Int 21 ; This prints a digit
Add dl,01 ; Next character
Loop 0107 ; Go to top of the 1st loop
Mov cl,09 ; Count for the 2nd loop
Mov bl,31 ; '1'
0112 is address of top of the 2nd loop.
Mov dl,0D ; Carriage return
Int 21
Mov dl,0A ; Linefeed
Int 21
Mov dl,bl ; Current character
Int 21
Add bl,01 ; Next character
Loop 0112 ; Go to top of the 2nd loop
int 20 ; DOS.Terminate