2016-04-23 101 views
0

基本上,我想將用戶輸入值乘以設定值。乘以當用戶輸入在一起,但是,如果我預設「號」的值(例如:6)該代碼的作品,它不會做乘法並返回0在x86彙編中需要使用FPU進行乘法運算

_start: 
finit       ; init. the float stack 

output inprompt     ; get radius number 
input number, 12    ; get (ascii) value of this number 
pushd NEAR32 PTR number  ; push address of number 
call atofproc     ; convert ASCII to float in ST 

fld st      ; value1 in ST and ST(1) 

mov number, 6 

; If I substitute the line above by the two lines below, it works: 
; output inprompt, 0 
; input number, 12 

pushd NEAR32 PTR number  ; push address of number 
call atofproc     ; convert ASCII to float in ST 

fmul       ; value1*value2 in ST 
fst prod_real     ; store result 


push prod_real     ; convert the results for printing 

lea eax, sum_out    ; get the ASCII string address 
push eax 
call ftoaproc 

output outprompt 
+1

您確定這是64位MASM代碼?看起來像32位。我問,因爲你添加的標籤。 –

+0

完成後,您不會彈出FP堆棧。你應該使用'fmulp'和'fstp'。我也不明白你爲什麼用'fld st'複製第一個值。另外,除非您需要使用LEA來使用RIP相對尋址來生成與位置無關的代碼,否則可以使用'push offset sum_out'設置arg to'ftoaproc'。而且,不是將其存儲到'prod_real'然後推送它,您可以在堆棧上創建空間並存儲到該空間中。 –

回答

1

你試圖轉換6從ASCII到浮點數,6是ASCII中的不可打印字符,因此它不能轉換爲浮點數。您需要更改6到54,這是字符'6'的ASCII表示。或者,如果您願意,您可以將浮點數傳遞給常量6.0並刪除對atofproc的調用。

+0

+1 哈哈謝謝。這種簡單的小小疏忽。 – Rijn