我开始使用nasm作为汇编代码 我正在处理二次代码 此代码在fedora bt上运行 不在ubuntu上 所以帮帮我。
extern printf,scanf
%macro print 2
mov rax,0
mov rdi,%1
mov rsi,%2
call printf
%endmacro
%macro scan 2
mov rax,0
mov rdi,%1
mov rsi,%2
call scanf
%endmacro
%macro printfloat 2
push rbp
mov rax,1
mov rdi,%1
movsd xmm0,%2
call printf
pop rbp
%endmacro
section .data
msg1 db "Enter a,b,c",0
msg2 db "Roots are",0
m1 db "%s",0
m2 db "%lf",0
m3 db "%d",0
m4 db "+i",0
m5 db "-i",0
nl db 10,0
section .bss
a resb 8
b resb 8
c resb 8
t1 resb 8
t2 resb 8
t3 resb 8
t4 resb 8
temp resd 1
r1 resb 8
r2 resb 8
section .text
global main
main:
print m1,msg1
scan m2,a
scan m2,b
scan m2,c
finit
fld qword[b] ;b
fmul st0,st0 ;b^2
fstp qword[t1] ;t1=b^2
fld qword[a] ;a
fmul qword[c] ;ac
mov dword[temp],04
fimul dword[temp] ;4ac
fstp qword[t2] ;t2=4ac
fld qword[t1] ;b-
fsub qword[t2] ;b^2-4ac
fstp qword[t1] ;t1=b^2-4ac
fld qword[t1]
fabs ;absolute
fsqrt
fstp qword[t2] ;t2=underroot(b^2-4ac)
fld qword[b]
fchs ;-b
fstp qword[t3] ;t3=b
fld qword[a]
mov dword[temp],2
fimul dword[temp] ;2a
fstp qword[t4] ;t4 ans
print m1,msg2
cmp qword[t1],0
jl noreal
fld qword[t3] ;t3
fadd qword[t2] ;t3+t2
fdiv qword[t4]
fstp qword[r1]
printfloat m2,[r1]
cmp qword[t1],0
je exit
fld qword[t3]
fsub qword[t2]
fdiv qword[t4]
fstp qword[r2]
printfloat m2,[r2]
jmp exit
noreal:
fld qword[t3]
fdiv qword[t4]
fstp qword[r1]
fld qword[t2]
fdiv qword[t4]
fstp qword[r2]
printfloat m2,[r1]
print m1,m4
printfloat m2,[r2]
print m1,nl
printfloat m2,[r1]
print m1,m5
printfloat m2,[r2]
exit:
print m1,nl
当我在ubuntu上运行此代码时,出现以下错误
/ usr / bin / ld:root.o:相对于.bss的重定位R_X86_64_32S在创建PIE对象时不能使用;用-fPIC
重新编译 / usr / bin / ld:最终链接失败:输出中的不可代表部分 collect2:错误:ld返回1退出状态