汇编实验九:在屏幕中间位置显示三行彩色字符串
80*25彩色字符模式显示缓冲区在B8000H到BFFFFH位置。一行80个字符号,160个字节。其中每个字的低位存储ASC2码,高位存储字符颜色属性。
属性格式:
7 6 5 4 3 2 1 0
BL R G B I R G B
7闪烁; 6、5、4背景; 3高亮; 2、1、0前景
0 1 0 0 1 0 1 0 4ah
0 1 0 0 0 1 0 1 45h
0 0 1 0 0 0 0 1 21h
1 assume cs:codes,ds:dates,ss:stacks 2 3 dates segment 4 db 4ah,45h,21h ;颜色 5 db 'welcome to masm!' 6 dates ends 7 stacks segment 8 db 6 dup (0) 9 stacks ends 10 codes segment 11 start: 12 mov ax,dates 13 mov ds,ax 14 15 mov ax,stacks 16 mov ss,ax 17 mov sp,25 ;3+16+6,指向栈底 18 19 mov ax,0b800h;彩色模式缓冲区 20 mov es, ax 21 22 ;(25-3)/2 = 11行 23 ;(80-16)/2 = 32列 24 ;(11-1)*160 + 32 = 1632 = 0660h 25 mov bx,0660h; 26 27 mov di,0 28 mov cx,3 29 setcolor: 30 push cx 31 push di;颜色存放偏移位置 32 33 mov ax,ds:[di];依次获取颜色值 34 mov di,ax 35 mov si,3 36 mov cx,16 37 setchar: 38 mov al,[si] 39 mov es:[bx],al;设置字符 40 mov ax,di 41 mov es:[bx+1],al;设置颜色属性 42 add bx,2 43 inc si 44 loop setchar 45 46 ;输出字符串16个字节加16个属性字节 47 ;160-16*2 = 0080h 48 add bx,0080h; 49 pop di 50 pop cx 51 inc di 52 loop setcolor 53 54 mov ax,4c00h 55 int 21h 56 codes ends 57 end start