'Loops in Assembly: TASM on 8086 (DosBox) Solve on how to Horizontal and Vertical Number
Solution 1:[1]
Contrary to what your title says about using TASM, the screenshot and the code correspond to DOS DEBUG.EXE. See this info about writing a TASM program.
Let's start by commenting the code (something that you should have done before posting!):
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
The 1st loop
- When your program starts, you should not rely on pre-existing register content. Don't assume that the
CXregister is 0. You need to initialize the loop counter withmov cx, 0A(10 decimal). Theloopinstruction depends onCX, not justCL. - The screenshot does not have any spaces between the digits on the first row. You should remove the lines that interject a space character
Mov dl,20Int 21.
The 2nd loop
- Here it is fine to initialize the loop counter with
mov cl, 09(9 decimal) because the previousloopinstruction will have left theCXregister at 0. - Because this is a separate loop, the
loopinstruction has to go to another destination.
The program
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

