Assembly 如何在汇编8086中使用中断以彩色打印字符串

Assembly 如何在汇编8086中使用中断以彩色打印字符串,assembly,x86-16,Assembly,X86 16,我正在用汇编8086编写一个NIM游戏。快完成了,但我面临一个问题 我有一个程序,打印桩(每个桩包含一些棍子)。它运行得很好,除了一件事。我想给棍子上色以使它看起来更好。因此,我搜索并找到了这样做的中断:INT 10h/AH=09h 在描述中,它建议该中断用于“在光标位置写入字符和属性”。然而,我不使用它来写字符,我使用它来为另一个中断设置颜色。 它在某种程度上工作正常,但并不总是如此。所以我想知道它是如何工作的,以及我是否用对了它 我还发现了以下用法: 以下是我对这些部件的代码: set_c

我正在用汇编8086编写一个NIM游戏。快完成了,但我面临一个问题

我有一个程序,打印桩(每个桩包含一些棍子)。它运行得很好,除了一件事。我想给棍子上色以使它看起来更好。因此,我搜索并找到了这样做的中断:INT 10h/AH=09h

在描述中,它建议该中断用于“在光标位置写入字符和属性”。然而,我不使用它来写字符,我使用它来为另一个中断设置颜色。 它在某种程度上工作正常,但并不总是如此。所以我想知道它是如何工作的,以及我是否用对了它

我还发现了以下用法:

以下是我对这些部件的代码:

set_color macro par ;macro to set a color for printing
   pusha
   mov bl, par  
   mov ah, 9 
   mov al, 0 
   int 10h
   popa 
endm
这就是我打印的地方:

print_pile  proc ;print the piles. this is where my problem lies.
pusha

mov al, nl ; print a new line
call print_ch
lea dx, top ;print top of border
call print_msg 
xor si, si
mov cx, piles
xor bl, bl

pile_loop: ;print pile number
lea dx, pile_num1
call print_msg
call set_cursor
lea dx, pile_num2
call print_msg
mov temp, si
mov al, b. temp
inc al
add al, 30h
call print_ch

mov al, ' ' ;print sticks in each pile in numbers
call print_ch
mov al, '('
call print_ch
mov al, pile1[si]
add al, 30h
call print_ch
mov al, ')'
call print_ch
mov al, ' '
call print_ch

lea dx, shape 
mov bl, pile1[si]
cmp bl, 0
jz no_print
    print_loop: ;prints sticks in each pile using an ascii character
    set_color light_red ; here i want to print abovesaid shapes in a color
    call print_msg
    dec bl
    cmp bl, 0

    jnz print_loop

no_print:

call set_cursor

inc si    
dec cx
or cx, cx
jnz pile_loop
lea dx, star2
call print_msg
lea dx, top
call print_msg
popa
ret
print_pile endp
下面是我的问题的一个例子:

正如你所看到的,最后一堆有两种颜色

谢谢你的帮助

我的完整代码可以找到——更容易阅读

另外,我使用的是emu8086,我的英语很抱歉。

print\u msg(DX=shape)
通过
Int 21h/09打印两个字符。因此,您必须通过
Int 10h/09h
set\u color
中设置两个字符的属性。因此,插入一个
mov-cx,2

set_color macro par ;macro to set a color for printing
       pusha
       mov bl, par
       mov ah, 9
       mov al, 0
       mov cx, 2   ; number of times to write character
       int 10h
       popa
endm