I am trying to write a simply code that uses nested loop, prints the character in the following pattern,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
and here is the code, and The code works absolutely fine
MOV AX, @DATA ; INITIALIZE DS
MOV DS, AX
; PRINT X
MOV CX,10
MOV BX,10
L2:
PUSH CX
MOV CX,BX
L1:
MOV DX, OFFSET HW ; LOAD THE STRING
MOV AH,09H
INT 21H
Loop L1
SUB BX,01
POP CX
MOV DX,0AH
MOV AH,02H
INT 21H
Loop L2
MOV AH, 4CH ; RETURN CONTROL TO DOS
INT 21H
but as soon as i use clear screen using video interrupt the output completely mess up,
Here is the output,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
and here is the code for it,
.MODEL SMALL
.STACK 100H
.DATA
HW DB "X$"
.CODE
MAIN PROC
MOV AX, @DATA ; INITIALIZE DS
MOV DS, AX
; CLEAR SCREEN
MOV AH, 06H
MOV AL, 00H
MOV CX, 00H
MOV DH, 25
MOV DL, 80
MOV BH, 0FH
INT 10H
; PRINT X
MOV CX,10
MOV BX,10
L2:
PUSH CX
MOV CX,BX
L1:
MOV DX, OFFSET HW ; LOAD THE STRING
MOV AH,09H
INT 21H
Loop L1
SUB BX,01
POP CX
MOV DX,0AH
MOV AH,02H
INT 21H
Loop L2
MOV AH, 4CH ; RETURN CONTROL TO DOS
INT 21H
MAIN ENDP
END MAIN
but when i remove the line feed that leave a line after each iteration, i.e
MOV DX,0AH
MOV AH,02H
INT 21H
the output is following as expected,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I donot understand what the clear screen code has to do with the line feed code ? why they are messing up with each other. ?
Same issue occur when i am using Cursor Position set code instead of clear screen,
MOV AH, 02H
MOV BH, 00H
MOV CX, 0000H
MOV DX, 0C22H
INT 10H
The output suppose to be the following in the middle of my screen,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
but it is displaying as below,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
X
XX
XXX
XX
X
Part of your code:
Why are you using page 0h? Sure about you are using that page? How? I know its done with:
VIDEO – GET CURRENT VIDEO MODE
VIDEO – SET CURSOR POSITION
Source: Ralph Brown’s interrupts page.
Display Pages
Graphics adapters can store several screens of text data (this is because displaying one screen of graphics requires significantly more memory than text). To fully use the display memory, it is divided into display pages. One display page can hold the data for one screen. The pages are numbered starting with 0; the number of pages available depends on the adapter and the display mode selected.
For 80 x 25 text mode, each display page is 4 KB. Display page 0 for text mode starts at address B800:0000h.
The active display page is the page currently being displayed. For 80 x 25 text mode, the memory requirement is 80 x 25 = 2000 words = 4000 bytes (i.e., the display does not use all of the 4 KB or 4096 bytes in the display page memory).
The video controller displays the first WORD in the active display page at the upper left corner of the screen (0,0), then displays the next WORD at (1,0), etc., displaying the screen row by row. The screen display can be looked at as the image of a two-dimensional array.
Source is here.