2017-03-01 37 views
0

我試圖添加兩位數字並將結果打印到VDU,返回的最大數字不會超過3位數。嘗試添加兩位數字並打印到VDU(總計低於100)

到目前爲止,我已經能夠爲我的VDU添加一個雙位數字,但我不確定我將如何去複製這個並將這些數字加在一起。

到目前爲止,我已經把該代碼是:

In 00 
sub al, 30 
mul al, 0a 
push al 

in 00 
sub al, 30 
pop bl 
add al, bl 

push al 
mod al, 0a 
add al, 30 
mov [c1], al 

pop al 
div al, 0a 
add al, 30 
mov [c0], al 
end 
+2

這不是8086,8086不能推8位'al'。你到目前爲止所做的代碼確實是一些代碼,這是一些代碼。如果你將更多的代碼放入機器,它將執行更多的代碼。也許它甚至會做一些有趣的事情。如果你確實希望每個部分都做某些特別感興趣的事情,那麼也許應該添加關於應該發生什麼的評論,以便其他人可以判斷你是否正確。也許即使你能夠認識到它是否按預期工作,如果不能,也必須有所不同。 – Ped7g

回答

0

你似乎是使用大量的,根本是無效的8086或x86代碼指令!

in 00   Use a DOS function to get a character 
mul al, 0a  Move the number 10 to an extra register 
push al  Push a complete word to to stack 
pop bl   Pop a complete word off the stack 
mod al, 0a  Use the remainder you get from a division 
div al, 0a  Move the number 10 to an extra register 

這是它可能是什麼樣子(沒有應用優化):

mov ah, 01h Input a character for the tens 
int 21h 
sub al, 30h Turn into number 
mov bl, 10 
mul al, bl  Multiplies AL by BL : So times 10 
push ax 

mov ah, 01h Input a character for the units 
int 21h 
sub al, 30h Turn into number 
mov ah, 0  Clear AH so addition works correctly 
pop bx 
add ax, bx  Add tens and units 


Here anything else! 

mov bl, 10 
div bl   Divides AX by BL : Gives remainder in AH, quotient in AL 

add ah, 30h Turn into character 
mov [c1], ah 

add al, 30h Turn into character 
mov [c0], al