2
私はアセンブリコードに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 "'と比較したいと思うでしょう。もしそれが等しくなければ、それをfloatに変換してください。 – Jester
@jesterコードを微調整してinput2を追加し、nと入力の比較を設定しようとしましたが、まだまだ短くなっています。 – Unleaver
''n''は数字ではありません、それは分かりますよね?フロートとして読むことはできません。 – Jester