【发布时间】:2015-02-01 23:21:31
【问题描述】:
我正在用 8086 程序集编写一个 NIM 游戏。它快完成了,但我遇到了一个问题。
我有一个打印堆的程序(每堆包含一些棍子)。它运行完美,除了一件事。我想给棒上色以获得更好的外观。所以我搜索并发现这样做的中断:INT 10h / AH = 09h
在描述中,它暗示此中断用于“在光标位置写入字符和属性”。但是,我不习惯用它来 write 个字符,我用它来设置另一个中断的颜色。 它在某种程度上可以正常工作,但并非总是如此。所以我想知道它是如何工作的,以及我是否以正确的方式使用它。
我还在这里找到了这种用法: How to print text in color with interrupts?
这是我的这些部分的代码:
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
这是我的问题的一个说明:
如您所见,最后一堆有两种颜色。
感谢您的帮助。
PS。我的完整代码可以在HERE 找到——更容易阅读。
PS。我正在使用emu8086,对不起我的英语。
【问题讨论】: