Experiment 9 According to the material programming (see material on 188 page)
Programming: In the middle of the screen display green, green bottom red, white blue string 'Welcome to masm! '
Materials:
80x25 Color character mode displays the structure of the buffer:
Memory address space, b8000h~bffffh a total of 32KB of space, the mode of the display can display 25 lines, 80 characters per line, each character can have 256 attributes (background color, foreground color, flashing, highlighting and other combinations of information).
In this way, a character occupies two bytes in the display buffer, storing the ASCII code and attributes of the characters, respectively. In 80x25 mode, the content of one screen occupies 4,000 bytes in the display buffer.
The display buffer is divided into 8 pages, 4KB per page (about 4000B), and the display can display the contents of any page. In general, the contents of page No. 0 are displayed. In other words, the 4,000-byte content in the B8000H~B8F9FH is usually out of the display.
In a row, a character occupies two bytes of storage space (a word), the low-bit byte stores the ASCII code of the character, and the high-level byte stores the character's properties. A row has a total of 80 characters and a point of 160 bytes.
Format of the attribute byte:
7 6 5 4 3 2 1 0
Meaning BL r G B I R G B
Flashing background highlighting foreground
Note that the flashing effect must be visible in full-screen DOS mode.
Here is the complete code for my answer:
:>----------------------------------------------------------------------------------------
Assume CS:CODESG, DS:DATASG, SS:STACKSG
DATASG segment
DB ' Welcome to masm! ' ; The data content to be displayed is 16 bytes
Datasg ends
STACKSG segment
DW 0,0,0,0,0,0,0,0; Here we use stacks to save data.
STACKSG ends
CODESG segment
Color1:mov Ah, 00000010B; the word green
JMP OK
Color2:mov Ah, 00100100B; red letter on green background
JMP OK
Color3:mov Ah, 01110001B; white bottom Blue word
JMP OK
; procedure Entrance
Start:mov Ax, DATASG
MOV ds, ax
mov ax, 0b800h
mov es, ax; the first address of the memory space segment is saved with the ES segment register
mov di, 0780H; move between rows with Di, the value of the current DI is the first address of line 12th
mov cx, 3H; To display 3 rows of data content, cx=3
S0:push CX, the following loop nesting will also use CX, put it into the stack to save, and into the outer loop
MOV dx, CX;d x is synchronized with the outer cyclic CX values and is used to perform comparison operations for different color configuration jumps (i.e. Color1, Color2, Color3)
mov si, 0H; Si is used in conjunction with DS to fetch data in the DATASG (DS segment), which is removed by byte length
mov bx, 0H; BX is used to move the column in the display cache, moving two bytes at a time (because a character is to be displayed, to account for two bytes)
mov cx, 10H; 16 characters Total
S1:mov al, [Si]; assigns the ASCII value of the character (which is one byte length) to Al and into the inner loop
CMP DX, 0003H; compare to 3 is the first line to display, that is, the text that displays green
JZ Color1
CMP DX, 0002H; compare to 2 is the second line to display, that is, the text that displays the red character on the green
JZ Color2
CMP DX, 0001H; compare with 3 Whether it is the third line to display, that is, the text that displays the blue word on the white background
JZ Color3
Ok:mov es:[bx][di].40h, ax; add display characters with attribute bytes to the corresponding cache location
Inc si; plus 1 processing the next character to be displayed
Add bx, 2H; plus 2 jump to the next cache location
Loop S1
Add Di, 0a0h, a0h jumps to the next line in the video memory header address
Pop CX; Back to the outer loop body to restore CX values in the outer loop
Loop S0
mov ax, 4c00h
int 21H
CODESG ends
End Start
:<----------------------------------------------------------------------------------------
Summarize:
Finally can operate the video memory control display content, excited Ah! The nesting of the loop is not ripe, and at first I became a dead circle Halo ~ ~ ~
-------------The above exercises section and code reference Yu Wang Teacher's << assembly language >> Second Edition----------------
This article is from the "9256624" blog, please be sure to keep this source http://9266624.blog.51cto.com/9256624/1616618
Learning << Assembly language-Wang Shuang >> This book a period of time, self-completed a practical question (2)