-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat.asm
More file actions
331 lines (319 loc) · 4.57 KB
/
Copy pathfloat.asm
File metadata and controls
331 lines (319 loc) · 4.57 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
.model tiny
.code
.386
org 100h
begin:
mov ebx, x
signNum:
shl ebx, 1
jnc expon
mov sNumber, 1
expon:
push ebx
and ebx, 0FF000000h
shr ebx, 24
sub bx, 127
mov exp, bx
pop ebx
push ebx
mant:
and ebx, 00FFFFFEh
shr ebx, 1
push ebx
pop mantissa
output:
push 0
mov ah, 2
mov cl, sNumber
add cl, '0'
mov dx, cx
int 21h
mov ah, 9
mov dx, offset tab
int 21h
movsx eax, exp
push eax
call outnumber
mov ah, 9
mov dx, offset tab
int 21h
mov ah, 2
push mantissa
call outnumber
mov ah, 2
mov dl, 0ah
int 21h
outputSecond:
mov ah, 9
mov dx, offset one
int 21h
mov ah, 2
mov cl, sNumber
add cl, '0'
mov dx, cx
int 21h
mov ah, 9
mov dx, offset two
int 21h
movsx eax, exp
push eax
call outnumber
mov ah, 9
mov dx, offset three
int 21h
mov cx, 0
call outfract
mov ah, 2
mov dl, 0ah
int 21h
outputThird:
call outint
mov ah, 2
mov dl, ','
int 21h
mov cx, exp
call outfract
int 20h
ReadFirstBits proc
mov di, cx
pop dx
pop cx
push dx
push di
xor dx, dx
cmp cx, 0
je OutRet
loopOrder:
shl ebx, 1
jnc BitIsNull
sub cx, 1
push ebx
mov bx, offset T
mov al, cl
xlat
pop ebx
or dl, al
add cx, 1
BitIsNull:
loop loopOrder
OutRet:
xor al, al
mov al, dl
pop cx
ret
ReadFirstBits endp
ReadLastBits proc
mov di, cx
pop dx
pop cx
push dx
push di
xor dx, dx
mov di, 7
sub di, cx
test di, di
js OutRt
lRLB:
shr ebx, 1
jnc BitNull
push ebx
mov bx, offset T
mov al, cl
xlat
pop ebx
or dl, al
BitNull:
add cx, 1
cmp cx, 8
jne lRLB
OutRt:
xor al, al
mov al, dl
pop cx
ret
ReadLastBits endp
outnumber proc
pop si
pop eax
push si
push ecx
test eax, eax
jns work
mov ecx, eax
mov ah, 02h
mov dl, '-'
int 21h
mov eax, ecx
neg eax
work:
push di
mov ecx, 10
mov di, offset len_str - 1
rpt:
mov dx, 0
div ecx
xchg eax,edx
add al, '0'
mov [di], al
dec di
xchg eax,edx
cmp eax,0
jne rpt
inc di
mov ah,9
mov dx, di ; Çàíîñèì â DX àäðåñ íà÷àëà ñòðîêè
int 21h
pop di
pop ecx
ret
String db 1000 dup (?)
len_str db '$'
outnumber endp
outint proc
mov ebx, mantissa
or ebx, 00800000h ;âîçâðàò åäèíèöû
shl ebx, 8
mov ax, exp
test ax, ax ;ïðîâåðêà íà îòðèö. ýêñïîíåíòû
js makeint
xor ax, ax ;ïåðåíîñ ìàíòèññû â ìàññèâ áàéò
xor dx, dx
mov ax, exp
add ax, 1
mov cx, 8
div cx
add ax, 1
mov SizeMst, ax
push dx
call ReadFirstBits
mov Mst[0], al
mov cx, SizeMst
sub cx, 1
cmp cx, 0
je makeint
loopoutint:
xor dx, dx
push 8
call ReadFirstBits
mov dx, SizeMst
sub dx, cx
mov di, dx
mov Mst[di], al
loop loopoutint
makeint:
xor eax, eax ;íà÷èíàåì äåëåíèå íà 10, ñòðåìèìñÿ ê äåñÿòè÷íîé ñèñòåìå
xor cx, cx
mov bl, 10
xor dx, dx
GetDecNum:
mov di, 0
DivTen:
mov al, Mst[di]
div bl
mov Mst[di], al
add di, 1
cmp di, SizeMst
jne DivTen
mov al, ah
xor ah, ah
push ax
inc dx
mov di, 0
CheckOnNull:
cmp Mst[di], 0 ;ïðîâåðêà íà îáíóëåííûå áàéòû
jne GetDecNum
add di, 1
cmp di, SizeMst
jne CheckOnNull
mov cx, dx
loop1:
pop dx
push 0
push dx
call outnumber
loop loop1
mov SizeMst, 1
ret
outint endp
outfract proc
mov ebx, mantissa
or ebx, 00800000h
xor ax, ax
xor dx, dx
;mov cx, 0;Exponenta
mov SizeMst, 1
add cx, 1
mov ax, 24
sub ax, cx
test ax, ax
js makefract
mov cx, 8
div cx
cmp dx, 0
mov SizeMst, ax
add ax, 1
mov SizeMst, ax
mov ax, 8
sub ax, dx
push ax
call ReadLastBits
mov Mst[0], al
mov cx, SizeMst
sub cx, 1
cmp cx, 0
je makefract
loopoutfract:
xor dx, dx
push 0
call ReadLastBits
mov dx, SizeMst
sub dx, cx
mov di, dx
mov Mst[di], al
loop loopoutfract
makefract:
xor eax, eax
xor cx, cx
mov bl, 10
xor eax, eax
xor dx, dx
mov di, 0
MulTen:
mov al, Mst[di]
mov cl, ah
mul bl
add ax, cx
mov Mst[di], al
add di, 1
cmp di, SizeMst
jne MulTen
mov al, ah
xor ah, ah
push 0
push ax
call outnumber
mov di, 0
xor ax, ax
CheckOnNull1:
cmp Mst[di], 0
jne MulTen
add di, 1
cmp di, SizeMst
jne CheckOnNull1
ret
outfract endp
mantissa equ dword ptr [bp-2]
exp dw 0
T db 00000001b, 00000010b, 00000100b, 00001000b, 00010000b, 00100000b, 01000000b, 10000000b
Mst db 20 dup (0)
ten db 10
SizeMst dw 0
sNumber db 0
x dd 0.625
tab db ' $'
one db '(-1)^$'
two db '*2^$'
three db '*1,$'
ttt dd 8388608
tenten dd 10
end Begin