题目: 在屏幕中间分别显示绿色,绿底红色,白底蓝色的字符串’welcome to masm’
思路:
- 在data段存’welcome to masm’
- 确定屏幕中间位置
- 将data段的内容,复制到偶数地址处,因为偶数地址00,02,04…存放ASCII码
- 设置奇数地址处的颜色,因为奇数地址01,03,05…存放字节属性
- 一共需要设置三行,每行相差0A0H,第一行从B800:0000开始,第二行从B800:00A0开始,第二行从B800:0140开始
代码:
assume cs: code, ds: data
data segment
db 'welcome to masm!'
data ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, 0B872h ;B872h: middle of the screen
mov es, ax
mov bx, 0
mov si, 0
mov cx, 16
s: mov al, ds:[bx]
mov es:[0 + si], al ;copy the 1st line character
mov ah, 02h ;green character
mov es:[1 + si], ah
mov es:[0A0h + si], al ;copy the 2nd line character
mov ah, 24h ;green background and red character
mov es:[0A1h + si], ah
mov es:[140h + si], al ;copy the 3rd line character
mov ah, 71h ;white background and blue character
mov es:[141h + si], ah
inc bx
add si, 2
loop s
mov ax, 4c00h
int 21h
code ends
end start
运行结果: