2
我有我的彙編代碼的兩個問題。根據指導原則,我必須使用浮點運算完成所有這些。就這樣說,似乎我沒有從中得到正確的答案,我不知道什麼是錯的。函數如下:y = 3x^3 + 2.7x^2-74x + 6.3。我必須給X,它是假設進入這個函數,並輸出Y.浮點不輸出正確的答案
該代碼也假設結束時,我鍵入N,但它不斷給我一個浮點錯誤。
編輯:我想出了我的問題與功能,但是每當我鍵入N它不會跳下來,並結束我的代碼。
input REAL8 ? ; user input
result REAL8 ? ; result of calculation
three REAL8 3.0 ; constant
twoSeven REAL8 2.7 ; constant
seventyFour REAL8 74.0 ; constant
sixThree REAL8 6.3 ; constant
prompt BYTE "Enter an Integer or n to quit",0dh,0ah,0
again BYTE "Would you like to go again? Y/N?", 0dh, 0ah, 0
no BYTE "N",0dh,0ah,0
rprompt BYTE "The result of the calculation is ",0
.code
main PROC
result_loop:
finit ; initialize the floating point stack
mov edx,OFFSET prompt ; address of message
call WriteString ; write prompt
call ReadFloat ; read the input value
fst input ; save input of user
fmul three ; multiplies by three
fadd twoSeven ; Adds by 2.7
fmul input ; multiplies by the input
fsub seventyFour ; subtracts 74
fmul input ; multiplies by input
fadd sixThree ; adds by three
fst result ; puts value in area
mov edx,OFFSET rprompt ; address of message
call WriteString ; write prompt
call WriteFloat ; writes the result
call CrLf ; prints new line
mov edx, OFFSET again
call WriteString
Call ReadString
cmp edx, 'n' ; compares the input to n
je end_if ; jumps if its equal to n
jmp result_loop ; jumps back to the top
end_if: ; end statment
call WaitMsg ;
exit ;
main ENDP
END main
'FCOMI輸入,「n''是沒有任何意義。你可能想讀取一個字符串,將它與'「n」'進行比較,如果不相等,則將其轉換爲浮點數。 – Jester
@jester我對代碼進行了小小的調整,增加了input2,並嘗試設置n和輸入之間的比較,但是我仍然很短。 – Unleaver
''n''不是一個數字,你意識到,對吧?你不能把它看作是一個浮點數。 – Jester