2017-10-19 125 views
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”'进行比较,如果不相等,则将其转换为浮点数。 – 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 
相关问题