-
Notifications
You must be signed in to change notification settings - Fork 1
/
roots.asm
172 lines (145 loc) · 1.97 KB
/
roots.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
section .text
global main
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 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
inputa db "INPUT THE CO-EFFICIENT a ( a(x^2) + bx + c ) ",10
linputa equ $-inputa
inputb db "INPUT THE CO-EFFICIENT b ( a(x^2) + bx + c ) ",10
linputb equ $-inputb
inputc db "INPUT THE CO-EFFICIENT c ( a(x^2) + bx + c ) ",10
linputc equ $-inputc
dis db "DISCRIMINANT = %f ",10,0