-
Notifications
You must be signed in to change notification settings - Fork 1
/
sub4095.asm
248 lines (194 loc) · 2.63 KB
/
sub4095.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
;IF FIRST NUMBER IS MUCH LESS THAN THE SECOND ADD ZEROS IN THE BEGINNING OF
;FIRST NUMBER TO AVOID ERRORS
section .text
input:
mov eax,3
mov ebx,1
int 0x80
ret
output:
mov eax,4
mov ebx,1
int 0x80
ret
global _start
_start:
mov ecx,inpmsg
mov edx,linp
call output
mov esi,0
_input1:
mov ecx,data
mov edx,1
call input
mov cl,byte[data]
sub cl,30h
mov byte[digit1+esi],cl
add esi,1
cmp cl,-38
je stop1
jmp _input1
stop1:
sub esi,1
mov byte[digit1+esi],10
sub esi,1
mov dword[n1],esi
mov esi,0
mov ecx,inpmsg
mov edx,linp
call output
mov esi,0
_input:
mov ecx,data
mov edx,1
call input
mov cl,byte[data]
sub cl,30h
mov byte[digit2+esi],cl
add esi,1
cmp cl,-38
je proceed
jmp _input
proceed:
sub esi,1
mov byte[digit2+esi],10
sub esi,1
mov dword[n2],esi
mov ebp,dword[n1]
cmp ebp,esi
jg dig
mov dword[n3],esi
jmp checked
dig:
mov dword[n3],ebp
checked:
mov ecx,dword[n3]
add ecx,1
mov byte[digit3+ecx+1],10
_sub:
cmp ebp,0
jnle zeroal
mov byte[digit1+ebp-1],0
zeroal:
mov al,[digit1+ebp]
cmp esi,0
jnle zerobl
mov byte[digit2+esi-1],0
zerobl:
mov bl,[digit2+esi]
mov dl,byte[borrow]
sub al,bl
sub al,dl
mov byte[borrow],0
cmp al,-1
jnle _storing
mov byte[borrow],1
add al,10
_storing:
mov byte[digit3+ecx],al
sub esi,1
sub ebp,1
sub ecx,1
cmp ecx,0
jne _sub
mov dl,byte[borrow]
cmp dl,0
je _printing
mov byte[borrow],0
mov esi,dword[n3]
mov byte[digit3+esi+2],10
mov byte[digit1+0],1
mov ebp,0
compliment:
mov byte[digit1+ebp+1],0
add ebp,1
cmp ebp,esi
jle compliment
mov byte[digit1+ebp+1],10
add esi,1
_subc:
mov al,[digit1+ebp]
mov bl,[digit3+esi]
mov dl,byte[borrow]
sub al,bl
sub al,dl
mov byte[borrow],0
cmp al,-1
jnle _storingc
mov byte[borrow],1
add al,10
_storingc:
mov byte[digit3+ebp],al
sub ebp,1
sub esi,1
cmp ebp,-1
jne _subc
mov byte[digit3],-3
mov esi,0
mov ebp,0
_printing:
mov esi,dword[n3]
cmp esi,50
jle _underlining
mov esi,50
_underlining:
mov ecx,underscore
mov edx,1
call output
sub esi,1
cmp esi,-1
jne _underlining
mov ecx,newline
mov edx,1
call output
mov ecx,newline
mov edx,1
call output
mov ecx,omsg
mov edx,lomsg
call output
mov esi,0
mov ebp,3
spacing:
mov ecx,space
mov edx,1
call output
sub ebp,1
cmp ebp,-1
jne spacing
_output:
mov eax,0
mov al,byte[digit3+esi]
cmp al,10
je stopoutput
add al,30h
mov byte[data],al
mov ecx,data
mov edx,1
call output
add esi,1
jmp _output
stopoutput:
mov ecx,newline
mov edx,1
call output
mov eax,1
mov ebx,0
int 0x80
section .data
omsg db "RESULT = ",10
lomsg equ $-omsg
borrow db 0
n1 dd 0
n2 dd 0
n3 dd 0
newline db 10
data db 30h
underscore db 95
space db 32
inpmsg db "enter the digit",10
linp equ $-inpmsg
section .bss
digit1 resb 4097
digit2 resb 4097
digit3 resb 4098