im a newbie in Assembly language. I came across an Assembly code that computes a quadratic equation and is run on Ubuntu 64 bit.I'm trying to use printf to print out the integers but it's not working. The code is ;
global _main
section .text
extern printf,scanf
print:
mov eax,4
mov ebx,1
int 0x80
ret
main:
mov ecx,inputa
mov edx,linputa
call print
push a
push scan
call scanf
mov ecx,inputb
mov edx,linputb
call print
push b
push scan
call scanf
mov ecx,inputc
mov edx,linputc
call print
push c
push scan
call scanf
fld qword[b]
fmul st0
fld qword[a]
fmul qword[c]
mov word[const],4
fimul word[const]
fchs
fadd st1
fst qword[disc]
push dword[disc+4]
push dword[disc]
push dis
call printf
ftst
fstsw ax
sahf
ja real_roots
sahf
je one_root
imag_roots:
fchs
fsqrt
fld qword[b]
fchs
fadd st1
fld qword[a]
mov word[const],2
fimul word[const]
fxch st1
fdiv st1
fstp qword[x1]
fld qword[disc]
fchs
fsqrt
fld qword[b]
fadd st1
fchs
fld qword[a]
mov word[const],2
fimul word[const]
fxch st1
fdiv st1
fstp qword[x2]
push dword[x2+4]
push dword[x2]
push dword[x1+4]
push dword[x1]
push imagroot
call printf
jmp over
real_roots:
fsqrt
fld qword[b]
fchs
fadd st1
fld qword[a]
mov word[const],2
fimul word[const]
fxch st1
fdiv st1
fstp qword[x1]
fld qword[disc]
fsqrt
fld qword[b]
fadd st1
fchs
fld qword[a]
mov word[const],2
fimul word[const]
fxch st1
fdiv st1
fstp qword[x2]
push dword[x2+4]
push dword[x2]
push dword[x1+4]
push dword[x1]
push realroot
call printf
jmp over
one_root:
fsqrt
fld qword[b]
fchs
fadd st1
fld qword[a]
mov word[const],2
fimul word[const]
fxch st1
fdiv st1
fstp qword[x1]
push dword[x1+4]
push dword[x1]
push oneroot
call printf
over:
mov eax,1
mov ebx,0
int 0x80
section .bss
x1 resq 1
x2 resq 1
const resw 1
a resq 1
b resq 1
c resq 1
disc resq 1
section .data
scan dd "%lf",0
oneroot dd "Root = %f",10,0
realroot dd "Root 1 = %f & Root 2 = %f ",10,0
imagroot dd "Root 1 = %fi & Root 2 = %fi ",10,0
inputa dd "INPUT THE CO-EFFICIENT a ( a(x^2) + bx + c ) ",10
linputa equ $-inputa
inputb dd "INPUT THE CO-EFFICIENT b ( a(x^2) + bx + c ) ",10
linputb equ $-inputb
inputc dd "INPUT THE CO-EFFICIENT c ( a(x^2) + bx + c ) ",10
linputc equ $-inputc
dis dd "DISCRIMINANT = %f ",10,0
I assembled it using nasm -f elf qua.asm
and tried linking it with ld -m elf_i386 -s -o qua qua.o
It gives me the following error
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048080 qua.o: In function
main': qua.asm:(.text+0x27): undefined reference to
scanf' qua.asm:(.text+0x45): undefined reference toscanf' qua.asm:(.text+0x63): undefined reference to
scanf' qua.asm:(.text+0xa6): undefined reference toprintf' qua.o: In function
imag_roots': qua.asm:(.text+0x13b): undefined reference toprintf' qua.o: In function
real_roots': qua.asm:(.text+0x1be): undefined reference toprintf' qua.o: In function
one_root': qua.asm:(.text+0x201): undefined reference to `printf'
i tried linking it with gcc gcc -m32 -o qua qua.o
and i got an error
/usr/bin/ld: cannot find crt1.o: No such file or directory /usr/bin/ld: cannot find crti.o: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a when searching for -lgcc /usr/bin/ld: cannot find -lgcc /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so when searching for -lgcc_s /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find -lc /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a when searching for -lgcc /usr/bin/ld: cannot find -lgcc /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so when searching for -lgcc_s /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find crtn.o: No such file or directory collect2: error: ld returned 1 exit status
How do you go about this?