【问题标题】:NASM 80387 coprocessor printf printing -nanNASM 80387 协处理器 printf 打印 -nan
【发布时间】:2018-04-14 14:40:38
【问题描述】:

这是我试图计算二次方程的根的 nasm 程序。我正在使用 printf 和 scanf。在所有计算之后,当我打印存储在变量 root1 和 root2 中的两个根时,正在打印的两个根的值都是 -nan。程序中可能有什么问题。 'write' 和 'exit' 宏被包含在其他文件中。

extern printf
extern scanf

section .data
msg1 db "enter a: "
len1 equ $-msg1
msg2 db "enter b: "
len2 equ $-msg2
msg3 db "enter c: "
len3 equ $-msg3

frmt1 db "%lf",0
frmt2 db "the numbers are :- ",10,"a = %lf",10,"b = %lf",10,"c = %lf",10,0
frmt3 db "root1 = %lf",10,0
frmt4 db "root2 = %lf",10,0

num4 dq 4
num2 dq 2

section .bss
a resq 1
b resq 1
c resq 1
del resq 1
sdel resq 1
root1 resq 1
root2 resq 1

section .code
global main
main:
;create stack frame
push rbp
mov rbp,rsp

write msg1,len1
mov rdi,frmt1
mov rsi,a
call scanf

write msg2,len2
mov rdi,frmt1
mov rsi,b
call scanf

write msg3,len3
mov rdi,frmt1
mov rsi,c
call scanf

mov rdi,frmt2
movq xmm0,[a]
movq xmm1,[b]
movq xmm2,[c]
mov rax,3
call printf

finit   ;initilaize coprocessor
fld qword[b]
fmul qword[b]
fld qword[a]
fmul qword[c]
fimul word[num4]
fsub
fst qword[del]
fsqrt
fstp qword[sdel]
fld qword[b]
fchs
fadd qword[sdel]
fild word[num2]
fmul qword[a]
fdiv 
fstp qword[root1]
fld qword[b]
fchs
fsub qword[sdel]
fld qword[a]
fimul word[num2]
fdiv
fstp qword[root2]

mov rdi,frmt3
movq xmm0,[root1]
mov rax,1
call printf

mov rdi,frmt4
movq xmm0,[root2]
mov rax,1
call printf



;destroy stack frame
mov rsp,rbp
pop rsp
exit

【问题讨论】:

    标签: assembly nasm x86-64


    【解决方案1】:

    在这种情况下,我没有处理虚根的条件。因此,我将 root1 和 root2 的值作为 -nan。如果我输入 a,b,c 的值,使得 b^2-4ac >= 0,答案就出来了。

    【讨论】:

      猜你喜欢
      • 2013-12-14
      • 2015-06-25
      • 2020-06-07
      • 2016-01-25
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      相关资源
      最近更新 更多