装配:打印不同颜色的线条

Assembly: Printing a line in Different Colors

我正在尝试将两个数字相加,然后用 colors 中提到的 4 种不同颜色打印 resultMsg

代码:

INCLUDE Irvine32.inc

.data

prompt1     BYTE        "Please type your first integer:", 0dh, 0ah, 0
prompt2     BYTE        "Please type your second integer:", 0dh, 0ah, 0
resultMsg       BYTE        "The sum is ", 0
colors      BYTE        yellow, blue, red, green

.code
main PROC
call clrscr
call InteractiveSum
mov  eax, 5000
call Delay



exit
main ENDP

InteractiveSum PROC
    mov edx,OFFSET prompt1
    call WriteString
    call ReadInt
    mov ebx,eax
    call Crlf
    mov edx, OFFSET prompt2
    call WriteString
    call ReadInt
    add eax, ebx
    mov edx, OFFSET resultMsg
    call WriteString
    call WriteInt

ret
InteractiveSum ENDP

END main

我正在使用 Irvine32.inc 库,并且正在研究 SetTextColor 功能。它看起来非常适合我在这里尝试做的事情,但在示例中...

.data
str1 BYTE "Color output is easy!",0

.code
mov  eax,yellow + (blue * 16)
call SetTextColor
mov  edx,OFFSET str1
call WriteString
call Crlf

看来颜色必须放入 eax,这就是我存储两个数字之和的地方,因为如果我是正确的,它必须存储在那里 WriteInt?有解决办法吗?

如果您需要在 EAX 中存储其他内容,而它已经包含一个值,您必须保留它始终可以将 EAX 存储在堆栈上,然后从那里检索它。

push eax                         ; Add this line
mov  eax,yellow + (blue * 16)
call SetTextColor
pop  eax                         ; Add this line
mov  edx,OFFSET str1
call WriteString
call Crlf