在x86_64(NASM)中使用Printf

时间:2018-02-07 08:50:28

标签: assembly

我是汇编语言的新手。我遇到了一个计算二次方程的Assembly code并在Ubuntu 64位上运行。我正在尝试使用printf打印出整数,但它不起作用。代码是;

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

我使用nasm -f elf qua.asm汇总了它,并尝试将其与ld -m elf_i386 -s -o qua qua.o

相关联

它给我以下错误

  

ld:警告:找不到条目符号_start;默认为   0000000008048080 qua.o:在函数main': qua.asm:(.text+0x27): undefined reference to scanf'qua.asm :(。text + 0x45)中:undefined   引用scanf' qua.asm:(.text+0x63): undefined reference to scanf'qua.asm :(。text + 0xa6):未定义引用printf' qua.o: In function imag_roots':qua.asm :(。text + 0x13b):undefined reference   到printf' qua.o: In function real_roots':qua.asm :(。text + 0x1be):   对printf' qua.o: In function one_root'的未定义引用:   qua.asm :(。text + 0x201):未定义的引用`printf'

我尝试将其与gcc gcc -m32 -o qua qua.o

相关联

我收到了错误

  

/ usr / bin / ld:找不到crt1.o:没有这样的文件或目录   / usr / bin / ld:找不到crti.o:没有这样的文件或目录   / usr / bin / ld:跳过不兼容   /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a搜索-lgcc时   / usr / bin / ld:找不到-lgcc / usr / bin / ld:跳过不兼容   /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so搜索-lgcc_s时   / usr / bin / ld:找不到-lgcc_s / usr / bin / ld:找不到-lc   / usr / bin / ld:跳过不兼容   /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a搜索-lgcc时   / usr / bin / ld:找不到-lgcc / usr / bin / ld:跳过不兼容   /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so搜索-lgcc_s时   / usr / bin / ld:找不到-lgcc_s / usr / bin / ld:找不到crtn.o:否   这样的文件或目录collect2:error:ld返回1退出状态

你是怎么做到的?

0 个答案:

没有答案