代码解释如下:
;从键盘缓冲区中读取字节,根据读取的不同内容改变屏幕颜色
assume cs:code
code segment
start: mov ah,0 ;ah去控制颜色
int 16h ;从键盘缓冲区读取出数据 , ah存字符的通码,al为字符的ASCII码
mov ah,1
cmp al,'r' ;若按下r
je red
cmp al,'g' ;按下g
je green
cmp al,'b' ;按下b
je blue
jmp short startRet ;否则就结束
red: shl ah,1
green: shl ah,1
blue: mov bx,0b800h
mov es,bx
mov cx,2000
mov bx,1
s: and byte ptr es:[bx],11111000B ;循环修改字符的颜色,每个字符2个字节,奇数位字节控制颜色,一页是2000个字符
or es:[bx],ah
add bx,2
loop s
startRet: mov ax,4c00h
int 21h
;=========================================================
code ends
end start