我正在尝试编写一个使用嵌套循环的简单代码,以下列模式打印字符,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
这是代码,代码工作正常
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
但是一旦我使用清晰的屏幕使用视频中断输出就完全搞砸了,
这是输出,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
,这是代码,
.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
但是当我删除每次迭代后留下一行的换行符,即
MOV DX,0AH
MOV AH,02H
INT 21H
输出正如预期的那样,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
我不明白清晰的屏幕代码与换行代码有什么关系?为什么他们互相混淆。 ?
当我使用光标位置设置代码而不是清除屏幕时会发生同样的问题,
MOV AH, 02H
MOV BH, 00H
MOV CX, 0000H
MOV DX, 0C22H
INT 10H
输出假设在我的屏幕中间为
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
但显示如下,
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
X
XX
XXX
XX
X
答案 0 :(得分:2)
部分代码:
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
为什么使用第0h页?当然你正在使用那个页面?怎么样?我知道它完成了:
视频 - 获取当前视频模式
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
视频 - 设置光标位置
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
来源:Ralph Brown's interrupts page。
显示页面
图形适配器可以存储多个文本数据屏幕(这是因为显示一个图形屏幕所需的内存比文本要多得多)。为了充分利用显示存储器,它被分成显示页面。一个显示页面可以保存一个屏幕的数据。页面从0开始编号;可用页数取决于适配器和所选的显示模式。
对于80 x 25文本模式,每个显示页面为4 KB。文本模式的显示页面0从地址B800:0000h开始。
活动显示页面是当前显示的页面。对于80 x 25文本模式,内存要求为80 x 25 = 2000字= 4000字节(即显示器不使用显示页面内存中的所有4 KB或4096字节)。
视频控制器在屏幕左上角的活动显示页面中显示第一个WORD(0,0),然后在(1,0)等处显示下一个WORD,逐行显示屏幕。可以将屏幕显示视为二维阵列的图像。
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.