8086CPU assembly: Display String

Source: Internet
Author: User
Tags mul
Topic Requirements

Show "Welcome to masm!" in red in the 5th column of row 8th Writing Ideas

1. Place characters in the address of the segment
2. Calculate the position of the 8th and 5th columns (Knowledge Points: Understanding how the memory address segment Controls screen character display)
3. Write characters and attributes to the video memory corresponding location assembly code

Assume Ds:data,cs:code data segment db ' Welcome to masm! ', 0 data ends code segment Start:mov Ax,data
            mov Ds,ax mov si,0; in 8086CPU assembly language, the screen is 80*25 (column * width); memory address start to end bit: B8000-BFFFFH        ; 00 11 is a column: 00 is the character itself, 11 is the character attribute, 0000 0000 (76543210) are represented: 7 is blinking, 654 is the background rgb,3 is highlighted, and 210 is the font RGB MOV dh,8 Line mov dl,5; column mov cl,4; font attribute (red) call show; Enter subroutine M  OV ax,4c00h int 21h Show:push CX; This program pressed into the key CX and SI is not too necessary, here is for the normative write, the following pop also push Si mov ax,0a0h; to represent a row, you need to use A0 bytes Dec DH; On line 8th, we say, the computer is line 7th, since 0 is the beginning of the calculation Mul D H; Line 8th * The unit of the line is the first position of the 8th row mov Bx,ax; the results of the multiplication of DH and ax are saved in BX, and the subsequent use of MOV al,2; a column needs The Mul DL is represented by 2 bytes, and the 5th column begins where the DL is multiplied by the ax Sub ax,2; the first position of the 5th column is add Bx,ax;

           The first position of the 5th column in row 8th mov ax,0b800h; memory at first address MOV es,ax; will initially address segment to ES mov di,0; initialize mo for subsequent memory segment offset addresses
            v al,cl; Release the font properties CL into AL, because CL defaults to do the cyclic use of S:mov cl,ds:[si]; Welcome to MASM this word assigned value to cl,[Why do you want to give CL to see for yourself]   mov ch,0; cx=ch+cl, if the CL loop gets to the DB-defined character 0 o'clock, CX equals 0, at which point the jcxz can jump to ok jcxz OK mov es:[bx+di],cl

            ; The string obtained by CL from DB is stored in memory [di is an even increment, because the even bits hold the character itself] mov es:[bx+di+1],al; the character attribute of Cl is passed to al[di with an even increase, so the character attribute of the odd digit needs to be added 1] Inc si; Si increased by 1, is one to get the characters in the DB add di,2;d i is incremented by an even number because the memory uses 2 bytes to handle a character [high (even bit) exists character itself
            , low (odd digit) holds character property] loop s; loop this loop until CX is 0, i.e.: cl=ds:[si]=0 ok:pop si pop cx RET; return to main program code ends end start
Run Results

Memory control attached (b800h)

00 11 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00

The character itself, 11 (here to illustrate using 11 distinction) is a character attribute (16 binary)

Character attribute meaning:
0 0 0 0 0 0 0 0
7 6 5 4 3 2 1 0 (upper and lower one by one corresponding, for the following convenience, with this line of numbers instead)
7 This position 1 o'clock, for flashing
654 is the background color, respectively: RGB, that is, red, green, blue
3 This position is highlighted at 1 o'clock
210 is the font color, respectively: RGB, that is, red, green, blue
Example: 41 02 is: A

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.