装配:打印不同颜色的线

时间:2015-10-21 02:08:48

标签: visual-studio assembly colors masm irvine32

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

代码:

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?有解决方法吗?

1 个答案:

答案 0 :(得分:2)

如果您需要在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