Home > Blockchain >  Loops in Assembly: 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

Time:04-25

My code is:

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

enter image description here

CodePudding user response:

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 CX register is 0. You need to initialize the loop counter with mov cx, 0A (10 decimal). The loop instruction depends on CX, not just CL.
  • 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,20 Int 21.

The 2nd loop

  • Here it is fine to initialize the loop counter with mov cl, 09 (9 decimal) because the previous loop instruction will have left the CX register at 0.
  • Because this is a separate loop, the loop instruction 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
  • Related