任务:编程序,在屏幕的中间分别显示绿色、绿底红色、白底蓝色的字符串 ‘YantaiUniversity’
提示:要计算出“屏幕的中间”对应的内存单元,然后将字符以及对应的属性字节写入到内存中。
参考解答:
assume cs:codeseg, ds:datasg
datasg segment
 db 'welcome to masm!'
datasg ends
codeseg segment
start:
 mov ax, datasg
 mov ds, ax
 mov ax, 0B800H
 mov es, ax
mov si, 0
 mov di, 820H+80-16 ;820H+(0+160)/2-16,屏幕第13行中间
mov cx, 16
 w: mov al, [si]
 mov es:[di], al
 inc di
 mov al, 02H ;属性字节,由此控制显示效果
 mov es:[di], al
 inc si
 inc di
 loop w
 mov ax, 4c00h
 int 21h
beg_copy:
 mov ax, 0
 add ax, ax
 wait
end_copy: nop
codeseg ends
end start
运行结果:
