-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sqrt8086.com.list
414 lines (404 loc) · 26.6 KB
/
Sqrt8086.com.list
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
EMU8086 GENERATED LISTING. MACHINE CODE <- SOURCE.
Sqrt8086.com -- emu8086 assembler version: 4.08
[ 06-Dec-18 -- 12:19:49 AM ]
===================================================================================================
[LINE] LOC: MACHINE CODE SOURCE
===================================================================================================
[ 1] : Name "Sqrt8086"
[ 2] :
[ 3] : org 100h
[ 4] :
[ 5] : .MODEL small
[ 6] :
[ 7] : .STACK 512d
[ 8] :
[ 9] 0100: E9 C2 00 .DATA
[ 10] :
[ 11] 0103: 54 79 70 65 20 61 20 6E 75 6D 62 65 readMsg db "Type a number to calculate the SquareRoot of it (Max: 65534):$"
72 20 74 6F 20 63 61 6C 63 75 6C 61
74 65 20 74 68 65 20 53 71 75 61 72
65 52 6F 6F 74 20 6F 66 20 69 74 20
28 4D 61 78 3A 20 36 35 35 33 34 29
3A 24
[ 12] 0141: 54 68 65 20 6E 75 6D 62 65 72 20 6D overflowMsg db "The number must be lower than 65534!$"
75 73 74 20 62 65 20 6C 6F 77 65 72
20 74 68 61 6E 20 36 35 35 33 34 21
24
[ 13] 0166: 43 61 6C 63 75 6C 61 74 69 6E 67 2E loadingMsg db "Calculating...$"
2E 2E 24
[ 14] 0175: 41 76 65 72 61 67 65 20 53 71 75 61 resultMsg db "Average SquareRoot: $"
72 65 52 6F 6F 74 3A 20 24
[ 15] 018A: 50 72 65 73 73 20 61 6E 79 20 6B 65 finishMsg db "Press any key to continue | Press ESC to exit:$"
79 20 74 6F 20 63 6F 6E 74 69 6E 75
65 20 7C 20 50 72 65 73 73 20 45 53
43 20 74 6F 20 65 78 69 74 3A 24
[ 16] 01B9: 00 00 stackCacheLevel1 dw 0
[ 17] 01BB: 00 00 stackCacheLevel2 dw 0
[ 18] 01BD: 00 00 00 00 00 00 inputArray db 6 DUP(?)
[ 19] 01C3: 64 00 precisionFactor dw 100
[ 20] :
[ 21] :
[ 22] 01C5: .CODE
[ 23] :
[ 24] 01C5: start:
[ 25] 01C5: E8 91 01 call clearScreen
[ 26] :
[ 27] 01C8: E8 3E 00 call read
[ 28] :
[ 29] 01CB: 8B C8 mov cx, ax
[ 30] :
[ 31] 01CD: E8 69 01 call verifyNumber
[ 32] :
[ 33] 01D0: BA 66 01 lea dx, loadingMsg
[ 34] 01D3: E8 F2 00 call printString
[ 35] :
[ 36] 01D6: 8B C1 mov ax, cx
[ 37] :
[ 38] 01D8: E8 79 00 call calcSqrt
[ 39] :
[ 40] 01DB: 8B C8 mov cx, ax
[ 41] :
[ 42] 01DD: E8 68 01 call printCRLF
[ 43] 01E0: BA 75 01 lea dx, resultMsg
[ 44] 01E3: E8 E2 00 call printString
[ 45] :
[ 46] 01E6: 8B C1 mov ax, cx
[ 47] 01E8: E8 E8 00 call printFloat
[ 48] :
[ 49] 01EB: E8 72 01 call finish
[ 50] :
[ 51] 01EE: C3 ret
[ 52] : ;call exit
[ 53] :
[ 54] : ; Saves registers state
[ 55] 01EF: saveState:
[ 56] 01EF: 8F 06 BB 01 pop stackCacheLevel2
[ 57] 01F3: 50 push ax
[ 58] 01F4: 53 push bx
[ 59] 01F5: 51 push cx
[ 60] 01F6: 52 push dx
[ 61] 01F7: FF 36 BB 01 push stackCacheLevel2
[ 62] 01FB: C3 ret
[ 63] :
[ 64] :
[ 65] : ; Loads registers state
[ 66] 01FC: loadState:
[ 67] 01FC: 8F 06 BB 01 pop stackCacheLevel2
[ 68] 0200: 5A pop dx
[ 69] 0201: 59 pop cx
[ 70] 0202: 5B pop bx
[ 71] 0203: 58 pop ax
[ 72] 0204: FF 36 BB 01 push stackCacheLevel2
[ 73] 0208: C3 ret
[ 74] :
[ 75] :
[ 76] : ; Reads a number from Cin with 5 characters max.
[ 77] : ;@returns: Number -> AX
[ 78] 0209: read:
[ 79] 0209: 8F 06 B9 01 pop stackCacheLevel1
[ 80] :
[ 81] 020D: BA 03 01 lea dx, readMsg
[ 82] 0210: E8 B5 00 call printString
[ 83] :
[ 84] 0213: E8 32 01 call printCRLF
[ 85] :
[ 86] 0216: B4 02 mov ah, 02
[ 87] 0218: B2 29 mov dl, 41
[ 88] 021A: CD 21 int 21h
[ 89] :
[ 90] :
[ 91] 021C: 33 DB xor bx, bx
[ 92] 021E: BE BD 01 lea si, inputArray
[ 93] 0221: B9 06 00 mov cx, 6
[ 94] 0224: readLoop:
[ 95] :
[ 96] 0224: B4 01 mov ah, 01
[ 97] 0226: CD 21 int 21h
[ 98] :
[ 99] 0228: 3C 0D cmp al, 13
[ 100] 022A: 74 0A je fnshRead
[ 101] :
[ 102] 022C: 32 E4 xor ah, ah
[ 103] 022E: 2C 30 sub al, 48
[ 104] 0230: 89 04 mov [si], ax
[ 105] 0232: 46 inc si
[ 106] 0233: 43 inc bx ; BX = char length
[ 107] :
[ 108] 0234: E2 EE Loop readLoop:
[ 109] 0236: fnshRead:
[ 110] :
[ 111] 0236: BE BD 01 lea si, inputArray
[ 112] 0239: 8B CB mov cx, bx
[ 113] 023B: 33 D2 xor dx, dx
[ 114] 023D: convertLoop:
[ 115] :
[ 116] 023D: B8 0A 00 mov ax, 10
[ 117] 0240: F7 E2 mul dx ; AX = DX * 10
[ 118] :
[ 119] 0242: 8B 1C mov bx, [si]
[ 120] 0244: 32 FF xor bh, bh
[ 121] 0246: 46 inc si
[ 122] 0247: 03 C3 add ax, bx ; AX = (DX * 10) + BX
[ 123] :
[ 124] 0249: 8B D0 mov dx, ax
[ 125] :
[ 126] 024B: E2 F0 Loop convertLoop
[ 127] 024D: fnshConvert:
[ 128] 024D: 8B C2 mov ax, dx
[ 129] :
[ 130] 024F: FF 36 B9 01 push stackCacheLevel1
[ 131] 0253: C3 ret
[ 132] :
[ 133] :
[ 134] : ; Calculates the Sqrt of a 16 bit integer
[ 135] : ; @args: source -> AX
[ 136] : ; @returns: integer result -> AX, decimal result -> BX
[ 137] 0254: calcSqrt:
[ 138] :
[ 139] 0254: 8F 06 B9 01 pop stackCacheLevel1
[ 140] 0258: 6A 00 push 0
[ 141] 025A: 6A 00 push 0
[ 142] 025C: 50 push ax ; Stack = source
[ 143] :
[ 144] : ; aprox = (source / 200) + 2
[ 145] 025D: 33 D2 xor dx, dx
[ 146] 025F: BB C8 00 mov bx, 200
[ 147] 0262: F7 F3 div bx
[ 148] 0264: 05 02 00 add ax, 2
[ 149] 0267: 8B D8 mov bx, ax
[ 150] :
[ 151] 0269: 50 push ax ; Stack = aprx
[ 152] :
[ 153] :
[ 154] : ; BX -> aprx
[ 155] : ; CX -> source
[ 156] 026A: calcLoop:
[ 157] :
[ 158] 026A: 5B pop bx ; Stack = aprox(current)
[ 159] 026B: 59 pop cx ; Stack = source
[ 160] :
[ 161] : ; If aprx == aprx(cache) it means that the squareroot of source
[ 162] : ; is a floating point number, which is not supported by the 8068
[ 163] : ; and thus, can't be calculated precisely.
[ 164] 026C: 58 pop ax
[ 165] 026D: 3B D8 cmp bx, ax
[ 166] 026F: 74 4F je fnshAvrgSqrt
[ 167] :
[ 168] : ; checking if aprx² == source
[ 169] 0271: 8B C3 mov ax, bx ; AX = aprx
[ 170] 0273: 33 D2 xor dx, dx
[ 171] 0275: F7 E3 mul bx
[ 172] 0277: 3B C1 cmp ax, cx
[ 173] 0279: 74 3B je fnshSqrt
[ 174] :
[ 175] 027B: 5A pop dx ; Clearing aprx(decimal) as result was not achieved
[ 176] 027C: 53 push bx ; Store cache of aprx to be compared in the next loop iteration
[ 177] :
[ 178] : ; aprx(BX) = ((source(CX) / aprx) + aprx) / 2
[ 179] 027D: 8B C1 mov ax, cx ; AX = source
[ 180] 027F: 33 D2 xor dx, dx
[ 181] 0281: F7 F3 div bx
[ 182] 0283: 03 C3 add ax, bx
[ 183] 0285: D1 E8 shr ax, 1
[ 184] 0287: 8B D8 mov bx, ax
[ 185] :
[ 186] 0289: 51 push cx ; Stack = source
[ 187] 028A: 53 push bx ; Stack = aprx(current)
[ 188] :
[ 189] : ; Stack = aprx * 100
[ 190] 028B: 8B 16 C3 01 mov dx, precisionFactor
[ 191] 028F: F7 E2 mul dx
[ 192] 0291: 50 push ax
[ 193] :
[ 194] : ; aprox = ((source * 100 / aprx) + aprx * 100) / 2
[ 195] 0292: A1 C3 01 mov ax, precisionFactor
[ 196] 0295: F7 E1 mul cx ; source * 100
[ 197] :
[ 198] 0297: F7 F3 div bx ; (source * 100 / aprx)
[ 199] 0299: 8B C8 mov cx, ax
[ 200] :
[ 201] 029B: A1 C3 01 mov ax, precisionFactor
[ 202] 029E: F7 E3 mul bx
[ 203] :
[ 204] 02A0: 03 C1 add ax, cx ; (source * 100 / aprx) + aprx * 100)
[ 205] 02A2: 83 D2 00 adc dx, 0 ; (source * 100 / aprx) + aprx * 100) + Carry
[ 206] :
[ 207] 02A5: B9 02 00 mov cx, 2
[ 208] 02A8: F7 F1 div cx ; AX = ((source * 100 / aprx) + aprx * 100) / 2
[ 209] :
[ 210] 02AA: 5B pop bx ; BX = aprx * 100 lower
[ 211] :
[ 212] 02AB: 2B C3 sub ax, bx ; AX = (((source * 100 / aprx) + aprx * 100) / 2) - aprx * 100
[ 213] :
[ 214] 02AD: 5B pop bx ; BX = aprx
[ 215] 02AE: 59 pop cx ; CX = source
[ 216] 02AF: 5A pop dx ; DX = aprx(cache)
[ 217] :
[ 218] 02B0: 50 push ax ; Stack = aprx(decimal)
[ 219] 02B1: 52 push dx
[ 220] 02B2: 51 push cx
[ 221] 02B3: 53 push bx
[ 222] :
[ 223] 02B4: EB B4 JMP calcLoop
[ 224] :
[ 225] : ; The result is an integer number
[ 226] 02B6: fnshSqrt:
[ 227] 02B6: 8B C3 mov ax, bx ; AX = aprox(Sqrt)
[ 228] 02B8: 5B pop bx
[ 229] 02B9: 33 DB xor bx, bx ; BX = Sqrt(decimal)
[ 230] 02BB: FF 36 B9 01 push stackCacheLevel1
[ 231] 02BF: C3 ret
[ 232] :
[ 233] : ; The result is a floating point number
[ 234] 02C0: fnshAvrgSqrt:
[ 235] 02C0: 8B C3 mov ax, bx ; AX = aprox(Sqrt)
[ 236] 02C2: 5B pop bx ; BX = Sqrt(decimal)
[ 237] 02C3: FF 36 B9 01 push stackCacheLevel1
[ 238] 02C7: C3 ret
[ 239] :
[ 240] : ; printString a String in Cout.
[ 241] : ; @args: String pointer -> DX
[ 242] 02C8: printString:
[ 243] :
[ 244] 02C8: E8 7D 00 call printCRLF
[ 245] 02CB: B4 09 mov ah, 09
[ 246] 02CD: CD 21 int 21h
[ 247] 02CF: BA 00 00 mov dx, 0
[ 248] 02D2: C3 ret
[ 249] :
[ 250] : ; printString a 16Bit-Integer + 8Bit-Precision(decimal) Number
[ 251] : ;@args: Number -> AX, Precision -> BX
[ 252] 02D3: printFloat:
[ 253] :
[ 254] 02D3: E8 0C 00 call printNumber
[ 255] :
[ 256] 02D6: B4 02 mov ah, 02
[ 257] 02D8: B2 2E mov dl, 46
[ 258] 02DA: CD 21 int 21h
[ 259] :
[ 260] 02DC: 8B C3 mov ax, bx
[ 261] 02DE: E8 01 00 call printNumber
[ 262] :
[ 263] 02E1: fnshprintFloat:
[ 264] 02E1: C3 ret
[ 265] :
[ 266] : ; printString an Integer number.
[ 267] : ;@args: Number -> AX
[ 268] 02E2: printNumber:
[ 269] :
[ 270] 02E2: E8 0A FF call saveState
[ 271] :
[ 272] 02E5: 3D 64 00 cmp ax, 100
[ 273] 02E8: 73 29 jae printThreeDigits
[ 274] 02EA: 3D 0A 00 cmp ax, 10
[ 275] 02ED: 73 0D jae printTwoDigits
[ 276] :
[ 277] : ; 1 digit:
[ 278] 02EF: printOneDigit:
[ 279] :
[ 280] 02EF: B4 02 mov ah, 02
[ 281] 02F1: 8A D0 mov dl, al
[ 282] 02F3: 80 C2 30 add dl, 48
[ 283] 02F6: CD 21 int 21h
[ 284] :
[ 285] 02F8: E8 01 FF call loadState
[ 286] 02FB: C3 ret
[ 287] :
[ 288] : ; 2 digits:
[ 289] 02FC: printTwoDigits:
[ 290] 02FC: D4 0A aam
[ 291] 02FE: 80 C4 30 add ah, 48
[ 292] 0301: 04 30 add al, 48
[ 293] :
[ 294] 0303: 8B C8 mov cx, ax
[ 295] 0305: B4 02 mov ah, 02
[ 296] :
[ 297] 0307: 8A D5 mov dl, ch
[ 298] 0309: CD 21 int 21h
[ 299] :
[ 300] 030B: 8A D1 mov dl, cl
[ 301] 030D: CD 21 int 21h
[ 302] :
[ 303] 030F: E8 EA FE call loadState
[ 304] 0312: C3 ret
[ 305] :
[ 306] : ; 3 digits:
[ 307] 0313: printThreeDigits:
[ 308] :
[ 309] 0313: D4 0A aam
[ 310] 0315: 8A F0 mov dh, al
[ 311] 0317: 8A C4 mov al, ah
[ 312] 0319: B4 00 mov ah, 0
[ 313] 031B: D4 0A aam
[ 314] :
[ 315] 031D: 80 C4 30 add ah, 48
[ 316] 0320: 04 30 add al, 48
[ 317] 0322: 80 C6 30 add dh, 48
[ 318] :
[ 319] 0325: 8B C8 mov cx, ax
[ 320] 0327: B4 02 mov ah, 02
[ 321] :
[ 322] 0329: 8A D5 mov dl, ch
[ 323] 032B: CD 21 int 21h
[ 324] :
[ 325] 032D: 8A D1 mov dl, cl
[ 326] 032F: CD 21 int 21h
[ 327] :
[ 328] 0331: 8A D6 mov dl, dh
[ 329] 0333: CD 21 int 21h
[ 330] :
[ 331] 0335: E8 C4 FE call loadState
[ 332] 0338: C3 ret
[ 333] :
[ 334] 0339: verifyNumber:
[ 335] :
[ 336] 0339: 3D FE FF cmp ax, 65534
[ 337] 033C: 76 09 jbe continue
[ 338] :
[ 339] : ; Overflow:
[ 340] 033E: BA 41 01 lea dx, overflowMsg
[ 341] 0341: E8 84 FF call printString
[ 342] 0344: E8 19 00 call finish
[ 343] :
[ 344] : ; Continue:
[ 345] 0347: continue:
[ 346] 0347: C3 ret
[ 347] :
[ 348] : ; Printing CRLF (carriage return + line feed)
[ 349] 0348: printCRLF:
[ 350] :
[ 351] 0348: E8 A4 FE call saveState
[ 352] :
[ 353] 034B: B4 02 mov ah, 02
[ 354] 034D: B2 0D mov dl, 13
[ 355] 034F: CD 21 int 21h
[ 356] 0351: B2 0A mov dl, 10
[ 357] 0353: CD 21 int 21h
[ 358] :
[ 359] 0355: E8 A4 FE call loadState
[ 360] :
[ 361] 0358: C3 ret
[ 362] :
[ 363] 0359: clearScreen:
[ 364] 0359: 32 E4 xor ah, ah
[ 365] 035B: B0 03 mov al, 03h
[ 366] 035D: CD 10 int 10h
[ 367] 035F: C3 ret
[ 368] :
[ 369] 0360: finish:
[ 370] 0360: BA 8A 01 lea dx, finishMsg
[ 371] 0363: E8 62 FF call printString
[ 372] :
[ 373] 0366: B4 01 mov ah, 01
[ 374] 0368: CD 21 int 21h
[ 375] 036A: 3C 1B cmp al, 27
[ 376] 036C: 74 03 E9 54 FE jne start
[ 377] 0371: C3 ret
[ 378] :
[ 379] 0372: exit:
[ 380] 0372: B4 4C mov ah, 4Ch
[ 381] 0374: CD 21 int 21h
[ 382] 0376: C3 ret
[ 383] :
===================================================================================================
===================================================================================================