-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare_eq.txt
210 lines (137 loc) · 2.01 KB
/
square_eq.txt
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//____SQUARE_EQUATION_SOLVER_ASM______//
in // input of coefficients
in // ax^2 + bx + c = 0
in //
pop cx //
pop bx //
pop ax //
push 0
pop R12 // number of roots
push 0 //R10 = R11 = 0
pop R10 //
push 0 //
pop R11 //
push ax // if ax == 0
push 0 // then solve a linear
je linear_eq:
// ax != 0
push bx //
push bx // bx^2
mul //
push 4 // 4*ax*cx
push ax //
push cx //
mul //
mul //
sub // bx^2 - 4*ax*cx
pop R4
push 0 //
push R4 // if R4 < 0
jb END: // end
push R4 //
sqrt //
pop R4 // R4^2 - discriminant
push -1 // -R4
push R4 //
mul //
pop R4 //
call square_eq: //
//push dx //
pop R10 // x0 = R10
push -1 //+R4
push R4 //
mul //
pop R4 //
call square_eq: //
//push dx //
pop R11 // x1 = R11
push R10 //
push R11 //
push 1 //
pop R12 // nroots = 1
je END: // if x0==x1 goto 4
push 2 // x0 != x1
pop R12 // nroots = 2
END: // END
push R12 // if nroots != 0
push 0 //
jne 8: //
// if nroots == 0
push 0
out
end
8:
push R12 // if nroots != 1
push 1 //
jne 9: //
// nroots == 1
push R10
push R12
out
out
end
9:
push R12
push 2
jne 0:
// if nroots == 2
push R11
push R10
push R12
out
out
out
end
0:
// nroots == 3
push 8
push 8
push 8
out
out
out
end
//___count roots___//
square_eq:
push bx // -bx
push -1 //
mul //
push R4 //
add // -bx +/- R4
push 2 //
push ax //
mul //
div // (-bx +/- R4) / (2 * ax)
//pop dx // x = dx
ret
//___linear_equation___//
linear_eq:
push cx // jmp = 1
push 0
je 5: // if cx == 0
push 0
push bx
je 7:
push 1
pop R12
push cx
push -1
mul
push bx
div
pop R10
7:
jmp END:
5:
push bx
push 0
jne 6: // if bx!=0
push 3 // nroots = inf
pop R12 //
jmp END:
6:
push 1
pop R12 // one root = 0
push 0
pop R10
jmp END: