8086汇编中有一道编程题,今天花了两个小时做完了,这里记录一下做的过程
题目是这样的:
在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串’welcome to masm!’
内存空间地址中,地址:B8000h ~ b8f9fh为显示缓存区,显示缓存区8页,每页总共25行,80个字符,每个字符占一个字,通常显示第一页,
屏幕中间:为12 13 14行,偏移量的计算公式就为:(160 * (行数 - 1)),那么:
12行对应6e0 ~ 77f 
13行对应780 ~ 81f 
14行对应820 ~ 8bf
而根据属性字节的公式:
| 12
 3
 
 |         7    6    5    4    3    2    1    0含义:  (BL) (R    G    B)  (I)  (R    G    B)
 闪烁      背景        高亮      前景
 
 | 
题目中三种颜色的属性字节应为:
绿色:             00000010b,十六进制为02h 
绿底红色:     00100100b ,十六进制为24h 
白底蓝色:        01110001b ,十六进制为71h
显示字符:welcome to masm! 共16个字, 因为有80个字,那么第33~48个字在中间。偏移量为:66 ~ 96
分析后有以下程序:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 
 | assume cs:code
 data segment
 db 'welcome to masm!'
 data ends
 
 color segment
 db 02h,24h,71h
 color ends
 
 code segment
 start:  mov ax,data
 mov ds,ax
 
 mov ax,0b86eh
 mov es,ax
 
 mov si,0
 mov cx,3
 mov di,0
 
 s0:     push cx
 
 mov bx,0
 mov bp,0
 
 mov cx,16
 s1:
 mov al,ds:[bx]
 mov es:[bp+si+66],al
 inc bp
 inc bx
 
 push ds
 mov ax,color
 mov ds,ax
 mov al,ds:[di]
 mov es:[bp+si+66],al
 pop ds
 
 inc bp
 loop s1
 
 add si,0a0h
 inc di
 
 pop cx
 loop s0
 
 mov ax,4c00h
 int 21h
 code ends
 end start
 
 |