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