Reputation: 173
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
Upvotes: 0
Views: 4967
Reputation: 11910
Part of your code:
MOV AH, 02H
MOV BH, 00H ----> this is page number
MOV CX, 0000H
MOV DX, 0C22H --->why such big number for column number?
INT 10H
Why are you using page 0h? Sure about you are using that page? How? I know its done with:
VIDEO - GET CURRENT VIDEO MODE
AH = 0Fh
int 10h
Return:
AH = number of character columns
AL = display mode (see #00010 at AH=00h)
BH = active page (see AH=05h) ---------------->you will need this
VIDEO - SET CURSOR POSITION
AH = 02h
BH = page number <--------------now you know what to put here
0-3 in modes 2&3
0-7 in modes 0&1
0 in graphics modes
DH = row (00h is top)
DL = column (00h is left)
int 10h
Return:
Nothing
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.
INT 10h Video Functions
00h: Set Video Mode. Selects the video mode and clears the screen automatically.
Input:
AH = 0
AL = 3 ; mode 3 = 80 cols x 25 rows color text
; to avoid clearing the screen use mode 83h to set high bit
AL = 6 ; sets medium resolution (640 x 200) graphics mode
When BIOS sets the display mode, it also clears the screen.
01h: Change Cursor Size
Input:
AH = 1
CH = starting scan line
CL = ending scan line
The text mode cursor is displayed as a small dot array at a screen position. For the MDA and EGA, the dot array is 14 rows (0-13). For the CGA, the array is 8 rows (0-7). Normally rows 6 and 7 are lit for the CGA and rows 11 and 12 for the MDA/EGA cursor.
02h: Set Cursor Position. Move cursor to specified position.
Input:
AH = 2
DH = row (0-24)
DL = col (0-79 for 80x25 display)
BH = video page number (usually 0)
03h: Get Cursor Position. Return row and column position of cursor.
Input:
AH = 3
BH = video page number (usually 0)
Output:
DH = row ; position
DL = col
CH = starting scan line ; size
CL = ending scan line
06h: Scroll the Screen or a Window Up
Input:
AH = 6
AL = number of lines to scroll (0 => whole screen)
BH = attribute for blank lines
CH, CL = row, column for upper left corner
DH, DL = row, column for lower right window
Scrolling the screen up one line means to move each display line UP one row and insert a blank line at the bottom of the screen. The previous top row disappears from the screen.
The whole screen or any rectangular area (window) may be scrolled. AL contains the number of lines to scroll. If AL = 0, all the lines are scrolled and this clears the screen or window.
Example: Clear the screen to black for the 80x25 display.
MOV AH, 6 ; scroll up function
XOR AL, AL ; clear entire screen
XOR CX, CX ; upper left corner is (0,0)
MOV DX, 184FH ; lower right corner is (4Fh, 18H)
MOV BH, 7 ; normal video attribute
INT 10H ; clear screen
07h: Scroll the Screen/Window down
Input:
AH = 7
AL = number of lines to scroll (0 => whole screen)
BH = attribute for blank lines
CH, CL = row, column for upper left corner
DH, DL = row, column for lower right corner
Same as function 6, but lines are scrolled down instead of up.
08h: Read character at cursor. Can be used in either text or graphics mode.
Input: AH = 8
BH = page number
Output: AH = attribute
AL = ASCII code of character
09h: Write character and attribute. Display any ASCII character at current position and set desired attribute. Can be used in graphics or video mode.
Input:
AH = 09
AL = ASCII character code
BH = video page number (usually 0)
BL = attribute to be used. (In video mode, sets foreground (pixel) color)
CX = repetition count
Note: cursor will not be moved beyond the last character displayed.
Also, if AL contains the ASCII code of a control character, a control function is not performed --- a display symbol is shown instead.
Example: change the attribute of the character under the cursor to reverse video for monochrome display.
MOV AH, 8 ; read character
XOR BH, BH ; on page 0
INT 10H ; character in AL, attribute in AH
MOV AH, 9 ; display character
MOV CX, 1 ; display 1 character
MOV BL, 70H ; reverse video attribute
INT 10H ; display character
0Ah: Write character. Display any ASCII character at current position without changing the current attribute. Can be used in text or video mode.
Input:
AH = 0Ah
AL = ASCII character code
BH = video page number (usually 0)
CX = repetition count
0Eh: Display Character and Advance Cursor
Input: AH = 0Eh
AL = ASCII code of character
BH = page number
BL = foreground color (graphics mode only)
This function displays the character in AL and advances the cursor to the next position in the row, or if at the end of a row, it sends it to the beginning of the next row. If the cursor is in the lower right corner, the screen is scrolled up and the cursor is set to the beginning of the last row. This is the BIOS function used by INT 21h, function 2, to display a character. The control characters bell (07h), backspace (08h), line feed (0Ah), and carriage return (0Dh) cause control functions to be performed.
Upvotes: 2