2017-02-10 79 views
0

當我在我的2個變量上輸入數字時,我認爲它沒有讀取它,所以mov有0值。爲什麼打印num始終爲零emu8086

沒問題編譯。

這裏是我的代碼:

include 'emu8086.inc' 
org 100h 

define_print_string 
define_scan_num    
define_print_num    
define_print_num_uns 
define_clear_screen 

.model small 
.data 

;data 
a db "oops",0 
b db 0dh,0ah,"enter first number: ",0 
c db 0dh,0ah,"the sum is :",0 
d db 0dh,0ah,"Press 1 if adiition",0 
e db 0dh,0ah,"Press 2 if subtraction",0 
f db 0dh,0ah,"the diffirence is: ",0 
g db 0dh,0ah,"enter second number: ",0 
h db 0dh,0ah,"",0 
num1 dw 0 
num2 dw 0 
result dw 0 

;code 
.code 

start: 
lea si,a 
call print_string 
lea si,d 
call print_string 
lea si,e 
call print_string 
mov ah,1 
int 21h 
cmp al,'1' 
je addi 
cmp al,'2' 
je subt 
cmp al,'?' 
je start 

;input number 1 
proc enter1 
lea si,b 
call print_string 
call scan_num 
mov ax,num1 
ret 
endp enter1 

;input number 2 
proc enter2 
lea si,g 
call print_string 
call scan_num 
mov bx,num2 
ret 
endp enter2  

addi: 
call enter1 
call enter2 
add ax,bx 
lea si,h 
call print_string 
lea si,c 
call print_string 
call print_num 

subt: 

end1: 

end 

screenshot

+0

請正確格式化您的代碼。在每一行前面放四個空格。 – fuz

+0

在你的'enterX'程序中,你從'num1'和'num2'設置'ax'和'bx'。你用零初始化的變量,永遠不會再寫入。瞭解如何[scan_num(https://github.com/AhmadNaserTurnkeySolutions/emu8086/blob/master/inc/emu8086.inc)的作品。跳過與格式的問題,而不是製造[MCVE]你應該處理更大的問題*現在*是你的代碼是不可讀(壞的格式和程序都在中間)和嚴重的結構('enter1'和'enter2'是*相同*程序)如果我是你的老師,我會立即失敗,看到它,當然,修復它。 –

+0

謝謝,它只是可能我們的教授不能解釋宏(定義)一個和那個斧頭,BX的東西。我的老師認爲我們可以做到這一點,僅僅是因爲我們的一位同學是先進的(他重複了8086個科目)做到了。我無法理解他的代碼如何工作。 – wendellex

回答

1
call scan_num 
mov ax,num1 

scan_num宏觀離開其結果在AX寄存器。因此,您需要使用mov num1, axAX存儲在num1變量中。
這同樣適用於輸入第二個數字。


cmp al,'?' 
je start 
;input number 1 
proc enter1 

考慮當輸入既不是 「1」 會發生什麼,也不是 「2」,也不是 「?」。
代碼將通過enter1程序!
最好寫:

jmp start 
;input number 1 
proc enter1 

您應該計算你的總和儘可能晚的,如果你僅僅把它放在一個寄存器中。你沒有使用結果變量。

lea si,c 
call print_string 
mov ax, num1 
add ax, num2 
call print_num 
+0

謝謝主席先生,我找到了解決辦法,問題是在呼叫scan_num和MOV CX,NUM1 – wendellex

+0

我剛換NUM1,CX – wendellex

+0

和是世界上沒有必要變量的結果,我可以叫print_num消息下方 – wendellex