2017-10-19 7 views
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 
+0

'FCOMI入力は、「n''は全く意味がありません。おそらく文字列を読み込み、それを '' n "'と比較したいと思うでしょう。もしそれが等しくなければ、それをfloatに変換してください。 – Jester

+0

@jesterコードを微調整してinput2を追加し、nと入力の比較を設定しようとしましたが、まだまだ短くなっています。 – Unleaver

+0

''n''は数字ではありません、それは分かりますよね?フロートとして読むことはできません。 – Jester

答えて

1
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 

ReadStringは、あなたはそれがうまくいくと思うように動作しません。

EDXに入力を格納できるバッファへのポインタを渡す必要があります。 ECXには、このバッファに含めることができる文字数を示す必要があります。

ReadStringが返されると、有効に入力された文字数がEAXになります。

バッファを定義し、パラメータを設定します。

は、次に、あなたのコードは次のようになります。

mov edx, offset InBuffer 
mov ecx, 1 
Call ReadString 
test eax, eax 
jz result_loop  ; Jump back if no input given! 
mov al, [edx]  ; Get the only character 
or al, 32   ; Make LCase to accept 'n' as well as 'N' 
cmp al, 'n'   ; compares the input to n 
jne result_loop  ; jumps back if its not equal to n 
end_if:    ; end statment 
関連する問題