-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
164 lines (146 loc) · 2.11 KB
/
main.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
%macro EXIT 1
mov eax, 1
mov ebx, %1
int 0x80
%endmacro
%macro putchar 1
pushd
jmp %%work
%%char db %1
%%work:
mov eax, 4
mov ebx, 1
mov ecx, %%char
mov edx, 1
int 0x80
popd
%endmacro
%macro const_print 1
pushd
jmp %%print
%%str db %1, 0xA
%%len equ $ - %%str
%%print:
mov eax, 4
mov ebx, 1
mov ecx, %%str
mov edx, %%len
int 0x80
popd
%endmacro
%macro print 2
pushd
mov edx, %1
mov ecx, %2
mov ebx, 1
mov eax, 4
int 0x80
popd
%endmacro
%macro printd 0
pushd
mov bx, 0
mov ecx, 10
%%_divide:
mov edx, 0
div ecx
push dx
inc bx
test eax, eax
jnz %%_divide
%%_digit:
pop ax
add ax, '0'
mov [result], ax
print 1, result
dec bx
cmp bx, 0
jg %%_digit
popd
%endmacro
%macro pushd 0
push eax
push ebx
push ecx
push edx
%endmacro
%macro popd 0
pop edx
pop ecx
pop ebx
pop eax
%endmacro
%macro new_line 0
putchar 0xA
putchar 0xD
%endmacro
%macro decimal 2
pushd
mov eax, %1
mov ebx, 10
mul ebx
mov ecx, %2
div ecx
pop edx
pop ecx
pop ebx
%endmacro
%macro someshit 0
;num / x1
pushd
mov eax, [number]
mov ebx, [x1]
mov edx, 0
div ebx
add eax, ebx
mov ebx, 2
mov edx, 0
div ebx
mov [x2], eax
popd
%endmacro
section .text
global _start
_start:
mov eax, [number]
mov ecx, 2
div ecx
mov [x1], eax
mov eax, edx
mov eax, [x1]
mov eax, [x1]
add eax, 2
mov ebx, 2
mov edx, 0
div ebx
mov [x2], eax
_condition:
xor eax, eax
xor ebx, ebx
mov eax, [x1]
mov ebx, [x2]
sub eax, ebx
mov ebx, 1
cmp eax, ebx
jg _loop
je _result
jl _result
_loop:
mov eax, [x2]
mov [x1], eax
someshit
jmp _condition
_result:
mov eax, [x2]
const_print "Корень равен: "
printd
new_line
EXIT 0
section .data
number dd 144
section .bss
result resb 1
x1 resb 10
x1_decimal resb 1
x2 resb 10
;x2_decimal resb 1