浮点数不输出正确答案

Floating point not outputting right answer

我的汇编代码有两个问题。根据指南,我必须使用浮点运算来完成所有这些操作。话虽如此,我似乎没有从中得到正确答案,而且我不知道哪里出了问题。函数如下: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
 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 returns 时,您将在 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