Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly TASM 1.4-在不清除屏幕的情况下更改背景色?_Assembly_X86_Dos_Tasm_16 Bit - Fatal编程技术网

Assembly TASM 1.4-在不清除屏幕的情况下更改背景色?

Assembly TASM 1.4-在不清除屏幕的情况下更改背景色?,assembly,x86,dos,tasm,16-bit,Assembly,X86,Dos,Tasm,16 Bit,我用的是Tasm 1.4。 我试图在不清除前一个文本的情况下更改背景和文本的颜色,但最终总是清除前一个文本,尽管颜色已更改 例如: mov ah,09h lea dx,text1 int 21h ;displays text1 mov ah,01h int 21h ;I input a character mov ah,06h mov bh,42h mov cx,0000h mov dx,184fh int 10h ;I u

我用的是Tasm 1.4。 我试图在不清除前一个文本的情况下更改背景和文本的颜色,但最终总是清除前一个文本,尽管颜色已更改

例如:

mov ah,09h
lea dx,text1
int 21h             ;displays text1
mov ah,01h
int 21h             ;I input a character
mov ah,06h
mov bh,42h
mov cx,0000h
mov dx,184fh
int 10h             ;I use this to change the text and background color
mov ah,02h
mov bh,00h
mov dh,0ch
mov dl,20h
int 10h             ;along with this
mov ah,09h
lea dx,text2
int 21h             ;displays text2
mov ah,02h
mov dl,al
int 21h             ;displays the inputted character
现在发生的是

  • 它显示文本1
  • 它要求输入
  • 我输入一个输入
  • 它将显示text2,后跟输入的字符,背景颜色变为红色,文本颜色变为绿色。但是,text1已从屏幕上清除
我还应该说,text1和text2完全可以放在同一个屏幕上


那么,如何获得相同的输出,但不清除屏幕上的text1呢?

只需直接写入视频内存,就可以了。如果您处于模式03h,则屏幕上有80x25个字符。每个字符有16位与其关联。8位用于文本/背景颜色,另8位用于显示的字符

要显示的字符是第一个字节,属性是第二个字节。 您可以在此处找到内存组织和属性位的简要说明:

下面的一些代码将保持文本内容不变,只为80x25屏幕上的所有文本设置属性字节。现在我使用nasm,自从我上次使用tasm已经15年了——我不确定是否有任何语法需要更改

;********************************************************
; Sets the text-mode attributes for the whole 80x25 screen
; call  with AL = attribute (hi nibble = background, lo-nibble = foreground)
;********************************************************
setTextAttributes:
    push    es              ; save the seg register
    mov     cx, 80*25       ; # of chars to do
    mov     bx, 0xB800      ; segment of the screen memory for this video mode
    mov     es, bx
    xor     di, di          ; point to char data of screen-pos 0,0
.setTextAttributesLoop:
    inc     di              ; advance by 1 to point to the attribute, rather than the char
    stosb                   ; store our attribute byte to [es:di] and increment di. di now points to a character
    loop    .setTextAttributesLoop
    pop     es
    ret

你好谢谢编辑:)要用该颜色清除整个屏幕吗?通过滚动,这就是将要发生的事情。但我不确定您希望输出是什么样子。嗨!谢谢实际上我不想用颜色清除整个屏幕,而是,只需在不清除屏幕的情况下更改背景和文本颜色。因此,您确实只希望
text2
中的内容后跟键入的字符以新的颜色方案显示。@PeterCordes正确如果您看到
int 21h
则它肯定不是裸机(无操作系统),必须存在DOS或DOS仿真层。在仍然支持16位代码的32位Windows环境中,您可以使用
int 21h
和许多不构成安全威胁的BIOS调用(读取硬盘的BIOS调用不会返回数据)。模拟Windows NT(或更高版本)命令提示符下的BIOS调用。大多数BIOS调用在保护模式下不可用。BIOS调用不依赖于操作系统。