如何更改程序集中当前光标位置的背景颜色

how to change the background color of the current cursor position in assembly

我正在使用低级汇编(16 位)进行编码,我希望用户能够在类似 "paint" 的程序中更改背景颜色。我已经让一切正常工作了,WASD 和颜色(你把光标位置设为绿色)space,代码:

mov ah, 09h
mov bl, 00100101b
mov cx, 1d
int 10h

但是当我想用 'x' 或 'q' 代码将其改回时:

mov ah, 09h
mov bh, 0
mov bl, 00010000b
mov cx, 1d
int 10h

它将背景颜色更改为蓝色。但它也在该块上放置了 'x' 或 'q'!

我怎样才能只将背景颜色设为蓝色(光标仍设为黑色)而不放置 'x' 或 'q'(使用 x 或 q 字符)?

mov ah, 09h
mov bh, 0
mov bl, 00010000b
mov cx, 1d
int 10h

此代码段会将 AL 寄存器 中的任何字符写入屏幕!在文本视频屏幕上,它将显示蓝色背景色和黑色前景色。

为了仅更改背景颜色,您需要先阅读屏幕上的内容。为此目的使用 BIOS 功能 08h:

mov  bh, 0         ;Display page
mov  ah, 08h
int  10h           ;Gives character in AL (keep it!), and attribute in AH
mov  bl, 00010000b ;Blue background
and  ah, 15        ;Keep existing foreground color in low nibble
or   bl, ah        ;Combine in new attribute byte
mov  cx, 1
mov  ah, 09h
int  10h