-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_1.Asm
134 lines (123 loc) · 2.17 KB
/
3_1.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
.686
.model flat, stdcall
option casemap :none
include windows.inc ; always first
include masm32.inc
include gdi32.inc
include user32.inc
include kernel32.inc
includelib masm32.lib
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
.data
szRoot db "Root: ", 0
szEndl db 13, 10, 0
szEnterA db "a: ", 0
szEnterB db "b: ", 0
szEnterC db "c: ", 0
buf db 300 dup(' ')
fa dq ?
fb dq ?
fc dq ?
cura dq ?
curb dq ?
mid dq ?
val dq ?
vala dq ?
valb dq ?
part1 dq ?
dva dw 2
step dq 0.001
szGoodBye db "Press ENTER to continue...", 13, 10, 0
.code
MainProc proc
invoke StdOut, addr szEnterA
invoke StdIn, addr buf, 300
invoke StrToFloat, addr buf, addr fa
invoke StdOut, addr szEnterB
invoke StdIn, addr buf, 300
invoke StrToFloat, addr buf, addr fb
invoke StdOut, addr szEnterC
invoke StdIn, addr buf, 300
invoke StrToFloat, addr buf, addr fc
fld fb
fld fa
fchs
cycle:
fst cura
fadd step
fst curb
fcomi st(0), st(1)
jae cycle_end
fld cura
call func
fstp vala
fld curb
call func
fmul vala
fldz
fcomip st(0), st(1)
fstp vala
jb cycle
fld curb
fld cura
call findRootOnSegment
jmp cycle
cycle_end:
fstp cura
fstp curb
invoke StdOut, addr szGoodBye
invoke StdIn, addr buf, 300
invoke ExitProcess, 0
MainProc endp
findRootOnSegment proc
mov ecx, 1000
binary_cycle:
fstp cura
fstp curb
fld cura
fadd curb
fidiv dva
fst mid
call func
fld cura
call func
fstp vala
fmul vala
fldz
fcomip st(0), st(1)
fstp vala
fld mid
jb right
fstp curb
jmp binary_cycle_end
right:
fstp cura
binary_cycle_end:
fld curb
fld cura
loop binary_cycle
fstp cura
fstp curb
invoke FloatToStr, cura, addr buf
invoke StdOut, addr szRoot
invoke StdOut, addr buf
invoke StdOut, addr szEndl
ret
findRootOnSegment endp
func proc
fst val
fmul val
fmul fa
fstp part1
fld val
fsub fb
fstp val
fld fb
fdiv val
fadd part1
fadd fc
ret
func endp
end MainProc