Ich erstelle ein Assembly-Programm, um eine quadratische Gleichung zu lösen. Unser Professor hat uns einen Teil des Codes gegeben, aber jedes Mal, wenn ich mit dem was ich hinzugefügt habe, bekomme ich einen Fehler mit 'scanf'. es sagt undefinierten Verweis auf printf und auch undefinierten Verweis auf scanf. Ich bin nicht sicher, wie man nur unterschiedlichen Code schafft, der scanf und printf gleichwertig ist, anstatt sie zu nennen, ich denke, dass das einfacher wäre und Arbeit.Quadratische Gleichung- Assembly- mit scanf
section .text
global start
extern printf, scanf
print:
mov eax,4
mov ebx,1
int 0x80
ret
start:
mov ecx, a1
mov edx, la1
call print
push a
push scan
call scanf
mov ecx,b1
mov edx,lb1
call print
push b
push scan
call scanf
mov ecx,c1
mov edx,lc1
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
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 db "%lf",0
oneroot db "Root = %f",10,0
realroot db "Root 1 = %f & Root 2 = %f",10,0
imagroot db "Root 1 = %fi & Root 2 = %fi",10,0
dis db "Discriminant = %f",10,0
a1 db 3
la1 equ $-a1
b1 db 3
lb1 equ $-b1
c1 db 3
lc1 equ $-c1
Sie es gegen die Standard-Bibliothek verknüpfen? Außerdem sehe ich auf keinen Fall die Masse des Assembler-Codes, die keine Einrückung und keine Kommentare enthält. –
-Ich bin super neu bei der Montage. Was bedeutet es, es mit der Standardbibliothek zu verknüpfen? An der Spitze des Codes stelle ich extern scanf ... meinst du das? – Elizabeth
Welche Befehle verwenden Sie zum Assemblieren und Verknüpfen? Und auf welcher Plattform? –