2015-10-21 45 views
2

我試圖將兩個數字加在一起,然後用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中?有沒有解決這個問題的方法?

回答

2

如果你需要在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 
相關問題