我的汇编代码存在两个问题。根据指南,我必须使用浮点运算来完成所有这些操作。话虽如此,似乎我没有从中得到正确的答案,我也不知道出了什么问题。功能如下: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 :(得分: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