https://github.com/akkartik/mu/blob/master/311decimal-int.subx
1
2
3
4 parse-decimal-int-from-slice:
5
6 55/push-ebp
7 89/<- %ebp 4/r32/esp
8
9 51/push-ecx
10
11 8b/-> *(ebp+8) 1/r32/ecx
12
13 (parse-decimal-int-helper *ecx *(ecx+4))
14 $parse-decimal-int-from-slice:end:
15
16 59/pop-to-ecx
17
18 89/<- %esp 5/r32/ebp
19 5d/pop-to-ebp
20 c3/return
21
22
23 parse-decimal-int:
24
25 55/push-ebp
26 89/<- %ebp 4/r32/esp
27
28 51/push-ecx
29 52/push-edx
30
31 8b/-> *(ebp+8) 0/r32/eax
32
33 8d/copy-address *(eax+4) 1/r32/ecx
34
35 8b/-> *eax 2/r32/edx
36 8d/copy-address *(eax+edx+4) 2/r32/edx
37
38 (parse-decimal-int-helper %ecx %edx)
39 $parse-decimal-int:end:
40
41 5a/pop-to-edx
42 59/pop-to-ecx
43
44 89/<- %esp 5/r32/ebp
45 5d/pop-to-ebp
46 c3/return
47
48 parse-decimal-int-from-stream:
49
50 55/push-ebp
51 89/<- %ebp 4/r32/esp
52
53 51/push-ecx
54 52/push-edx
55
56 8b/-> *(ebp+8) 0/r32/eax
57
58 8b/-> *(eax+4) 1/r32/ecx
59 8d/copy-address *(eax+ecx+0xc) 1/r32/ecx
60
61 8b/-> *eax 2/r32/edx
62 8d/copy-address *(eax+edx+0xc) 2/r32/edx
63
64 (parse-decimal-int-helper %ecx %edx)
65 $parse-decimal-int-from-stream:end:
66
67 5a/pop-to-edx
68 59/pop-to-ecx
69
70 89/<- %esp 5/r32/ebp
71 5d/pop-to-ebp
72 c3/return
73
74 parse-decimal-int-helper:
75
76 55/push-ebp
77 89/<- %ebp 4/r32/esp
78
79 51/push-ecx
80 52/push-edx
81 53/push-ebx
82 56/push-esi
83 57/push-edi
84
85 8b/-> *(ebp+8) 6/r32/esi
86
87 8b/-> *(ebp+0xc) 7/r32/edi
88
89 ba/copy-to-edx 0/imm32/false
90
91 {
92 $parse-decimal-int-helper:negative:
93 b8/copy-to-eax 0/imm32
94 8a/copy-byte *esi 0/r32/AL
95 3d/compare-eax-and 0x2d/imm32/-
96 75/jump-if-!= break/disp8
97
98 46/increment-esi
99
100 ba/copy-to-edx 1/imm32/true
101 }
102
103 52/push-edx
104
105 b8/copy-to-eax 0/imm32
106
107 b9/copy-to-ecx 0/imm32
108
109 bb/copy-to-ebx 0xa/imm32
110 {
111 $parse-decimal-int-helper:loop:
112
113 39/compare %esi 7/r32/edi
114 73/jump-if-addr>= break/disp8
115
116 8a/copy-byte *esi 1/r32/CL
117 50/push-eax
118 (is-decimal-digit? %ecx)
119 {
120 3d/compare-eax-and 0/imm32/false
121 75/jump-if-!= break/disp8
122 58/pop-to-eax
123 b8/copy-to-eax 0/imm32
124 eb/jump $parse-decimal-int-helper:negate/disp8
125 }
126 58/pop-to-eax
127
128 81 5/subop/subtract %ecx 0x30/imm32/zero
129
130
131 ba/copy-to-edx 0/imm32
132 f7 4/subop/multiply-into-edx-eax %ebx
133
134 01/add %eax 1/r32/ecx
135
136 46/increment-esi
137
138 eb/jump loop/disp8
139 }
140 $parse-decimal-int-helper:negate:
141
142 5a/pop-to-edx
143 {
144 81 7/subop/compare %edx 0/imm32/false
145 74/jump-if-= break/disp8
146 f7 3/subop/negate %eax
147 }
148 $parse-decimal-int-helper:end:
149
150 5f/pop-to-edi
151 5e/pop-to-esi
152 5b/pop-to-ebx
153 5a/pop-to-edx
154 59/pop-to-ecx
155
156 89/<- %esp 5/r32/ebp
157 5d/pop-to-ebp
158 c3/return
159
160 test-parse-decimal-int-from-slice-single-digit:
161
162 55/push-ebp
163 89/<- %ebp 4/r32/esp
164
165 50/push-eax
166 51/push-ecx
167
168 b8/copy-to-eax "3"/imm32
169 8b/-> *eax 1/r32/ecx
170 8d/copy-address *(eax+ecx+4) 1/r32/ecx
171 05/add-to-eax 4/imm32
172
173 51/push-ecx
174 50/push-eax
175 89/<- %ecx 4/r32/esp
176
177 (parse-decimal-int-from-slice %ecx)
178 (check-ints-equal %eax 3 "F - test-parse-decimal-int-from-slice-single-digit")
179 $test-parse-decimal-int-helper-single-digit:end:
180
181 59/pop-to-ecx
182 58/pop-to-eax
183
184 89/<- %esp 5/r32/ebp
185 5d/pop-to-ebp
186 c3/return
187
188 test-parse-decimal-int-from-slice-multi-digit:
189
190 55/push-ebp
191 89/<- %ebp 4/r32/esp
192
193 50/push-eax
194 51/push-ecx
195
196 b8/copy-to-eax "34"/imm32
197 8b/-> *eax 1/r32/ecx
198 8d/copy-address *(eax+ecx+4) 1/r32/ecx
199 05/add-to-eax 4/imm32
200
201 51/push-ecx
202 50/push-eax
203 89/<- %ecx 4/r32/esp
204
205 (parse-decimal-int-from-slice %ecx)
206 (check-ints-equal %eax 0x22 "F - test-parse-decimal-int-from-slice-multi-digit")
207 $test-parse-decimal-int-helper-multi-digit:end:
208
209 59/pop-to-ecx
210 58/pop-to-eax
211
212 89/<- %esp 5/r32/ebp
213 5d/pop-to-ebp
214 c3/return
215
216 test-parse-decimal-int-from-slice-zero:
217
218 55/push-ebp
219 89/<- %ebp 4/r32/esp
220
221 50/push-eax
222 51/push-ecx
223
224 b8/copy-to-eax "00"/imm32
225 8b/-> *eax 1/r32/ecx
226 8d/copy-address *(eax+ecx+4) 1/r32/ecx
227 05/add-to-eax 4/imm32
228
229 51/push-ecx
230 50/push-eax
231 89/<- %ecx 4/r32/esp
232
233 (parse-decimal-int-from-slice %ecx)
234 (check-ints-equal %eax 0 "F - test-parse-decimal-int-from-slice-zero")
235 $test-parse-decimal-int-helper-zero:end:
236
237 59/pop-to-ecx
238 58/pop-to-eax
239
240 89/<- %esp 5/r32/ebp
241 5d/pop-to-ebp
242 c3/return
243
244 test-parse-decimal-int-from-slice-negative:
245
246 55/push-ebp
247 89/<- %ebp 4/r32/esp
248
249 50/push-eax
250 51/push-ecx
251
252 b8/copy-to-eax "-3"/imm32
253 8b/-> *eax 1/r32/ecx
254 8d/copy-address *(eax+ecx+4) 1/r32/ecx
255 05/add-to-eax 4/imm32
256
257 51/push-ecx
258 50/push-eax
259 89/<- %ecx 4/r32/esp
260
261 (parse-decimal-int-from-slice %ecx)
262 (check-ints-equal %eax -3 "F - test-parse-decimal-int-from-slice-negative")
263 $test-parse-decimal-int-helper-negative:end:
264
265 59/pop-to-ecx
266 58/pop-to-eax
267
268 89/<- %esp 5/r32/ebp
269 5d/pop-to-ebp
270 c3/return
271
272 test-parse-decimal-int-from-slice-multi-digit-negative:
273
274 55/push-ebp
275 89/<- %ebp 4/r32/esp
276
277 50/push-eax
278 51/push-ecx
279
280 b8/copy-to-eax "-32"/imm32
281 8b/-> *eax 1/r32/ecx
282 8d/copy-address *(eax+ecx+4) 1/r32/ecx
283 05/add-to-eax 4/imm32
284
285 51/push-ecx
286 50/push-eax
287 89/<- %ecx 4/r32/esp
288
289 (parse-decimal-int-from-slice %ecx)
290 (check-ints-equal %eax -0x20 "F - test-parse-decimal-int-from-slice-multi-digit-negative")
291 $test-parse-decimal-int-helper-multi-digit-negative:end:
292
293 59/pop-to-ecx
294 58/pop-to-eax
295
296 89/<- %esp 5/r32/ebp
297 5d/pop-to-ebp
298 c3/return
299
300 decimal-size:
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 55/push-ebp
316 89/<- %ebp 4/r32/esp
317
318 51/push-ecx
319 52/push-edx
320 57/push-edi
321
322 bf/copy-to-edi 0/imm32
323
324 8b/-> *(ebp+8) 0/r32/eax
325
326 {
327 3d/compare-eax-with 0/imm32
328 7d/jump-if->= break/disp8
329 f7 3/subop/negate %eax
330 47/increment-edi
331 }
332
333 b9/copy-to-ecx 0xa/imm32
334 {
335 ba/copy-to-edx 0/imm32
336 f7 7/subop/idiv-edx-eax-by %ecx
337 47/increment-edi
338 3d/compare-eax-and 0/imm32
339 75/jump-if-!= loop/disp8
340 }
341 $decimal-size:end:
342 89/<- %eax 7/r32/edi
343
344 5f/pop-to-edi
345 5a/pop-to-edx
346 59/pop-to-ecx
347
348 89/<- %esp 5/r32/ebp
349 5d/pop-to-ebp
350 c3/return
351
352 test-decimal-size-of-zero:
353
354 55/push-ebp
355 89/<- %ebp 4/r32/esp
356
357 (decimal-size 0)
358 (check-ints-equal %eax 1 "F - test-decimal-size-of-zero")
359 $test-decimal-size-of-zero:end:
360
361 89/<- %esp 5/r32/ebp
362 5d/pop-to-ebp
363 c3/return
364
365 test-decimal-size-single-digit:
366
367 55/push-ebp
368 89/<- %ebp 4/r32/esp
369
370 (decimal-size 4)
371 (check-ints-equal %eax 1 "F - test-decimal-size-single-digit")
372 $test-decimal-size-single-digit:end:
373
374 89/<- %esp 5/r32/ebp
375 5d/pop-to-ebp
376 c3/return
377
378 test-decimal-size-multi-digit:
379
380 55/push-ebp
381 89/<- %ebp 4/r32/esp
382
383 (decimal-size 0xa)
384 (check-ints-equal %eax 2 "F - test-decimal-size-multi-digit")
385 $test-decimal-size-multi-digit:end:
386
387 89/<- %esp 5/r32/ebp
388 5d/pop-to-ebp
389 c3/return
390
391 test-decimal-size-single-digit-negative:
392
393 55/push-ebp
394 89/<- %ebp 4/r32/esp
395
396 (decimal-size -4)
397 (check-ints-equal %eax 2 "F - test-decimal-size-single-digit-negative")
398 $test-decimal-size-single-digit-negative:end:
399
400 89/<- %esp 5/r32/ebp
401 5d/pop-to-ebp
402 c3/return
403
404 test-decimal-size-multi-digit-negative:
405
406 55/push-ebp
407 89/<- %ebp 4/r32/esp
408
409 (decimal-size -0xa)
410 (check-ints-equal %eax 3 "F - test-decimal-size-multi-digit-negative")
411 $test-decimal-size-multi-digit-negative:end:
412
413 89/<- %esp 5/r32/ebp
414 5d/pop-to-ebp
415 c3/return
416
417 _parse-array-of-decimal-ints:
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442 55/push-ebp
443 89/<- %ebp 4/r32/esp
444
445 50/push-eax
446 51/push-ecx
447 52/push-edx
448 53/push-ebx
449 56/push-esi
450 57/push-edi
451
452 8b/-> *(ebp+0xc) 6/r32/esi
453
454 8d/copy-address *(esi+4) 1/r32/ecx
455
456
457 8b/-> *esi 2/r32/edx
458
459 01/add-to %edx 1/r32/ecx
460
461 31/xor-with %ebx 3/r32/ebx
462 $_parse-array-of-decimal-ints:loop1:
463
464 39/compare %ecx 2/r32/edx
465 73/jump-if-addr>= $_parse-array-of-decimal-ints:break1/disp8
466
467 (skip-chars-matching-in-slice %ecx %edx 0x20)
468 89/<- %ecx 0/r32/eax
469
470 39/compare %ecx 2/r32/edx
471 73/jump-if-addr>= $_parse-array-of-decimal-ints:break1/disp8
472
473 (skip-chars-not-matching-in-slice %ecx %edx 0x20)
474 89/<- %ecx 0/r32/eax
475
476 81 0/subop/add %ebx 4/imm32
477 eb/jump $_parse-array-of-decimal-ints:loop1/disp8
478 $_parse-array-of-decimal-ints:break1:
479 (allocate-array *(ebp+8) %ebx *(ebp+0x10))
480 $_parse-array-of-decimal-ints:pass2:
481
482 68/push 0/imm32/end
483 8d/copy-address *(esi+4) 7/r32/edi
484 57/push-edi
485 89/<- %edi 4/r32/esp
486
487 8b/-> *(ebp+0x10) 0/r32/eax
488 (lookup *eax *(eax+4))
489 8d/copy-address *(eax+4) 1/r32/ecx
490 $_parse-array-of-decimal-ints:loop2:
491
492 39/compare *edi 2/r32/edx
493 73/jump-if-addr>= $_parse-array-of-decimal-ints:end/disp8
494
495 (skip-chars-matching-in-slice *edi %edx 0x20)
496 89/<- *edi 0/r32/eax
497
498 39/compare *edi 2/r32/edx
499 73/jump-if-addr>= $_parse-array-of-decimal-ints:end/disp8
500
501 (skip-chars-not-matching-in-slice *edi %edx 0x20)
502 89/<- *(edi+4) 0/r32/eax
503
504 (parse-decimal-int-from-slice %edi)
505 89/<- *ecx 0/r32/eax
506
507 81 0/subop/add %ecx 4/imm32
508
509 8b/-> *(edi+4) 0/r32/eax
510 89/<- *edi 0/r32/eax
511 eb/jump $_parse-array-of-decimal-ints:loop2/disp8
512 $_parse-array-of-decimal-ints:end:
513
514 81 0/subop/add %esp 8/imm32
515
516 5f/pop-to-edi
517 5e/pop-to-esi
518 5b/pop-to-ebx
519 5a/pop-to-edx
520 59/pop-to-ecx
521 58/pop-to-eax
522
523 89/<- %esp 5/r32/ebp
524 5d/pop-to-ebp
525 c3/return
526
527 test-parse-array-of-decimal-ints:
528
529 55/push-ebp
530 89/<- %ebp 4/r32/esp
531
532 68/push 0/imm32
533 68/push 0/imm32
534 89/<- %esi 4/r32/esp
535
536 68/push 3/imm32
537 68/push 2/imm32
538 68/push 1/imm32
539 68/push 0xc/imm32/size
540 89/<- %ecx 4/r32/esp
541
542 (_parse-array-of-decimal-ints Heap "1 2 3" %esi)
543 (lookup *esi *(esi+4))
544 (array-equal? %ecx %eax)
545 (check-ints-equal %eax 1 "F - test-parse-array-of-decimal-ints")
546
547 89/<- %esp 5/r32/ebp
548 5d/pop-to-ebp
549 c3/return
550
551 test-parse-array-of-decimal-ints-empty:
552
553
554 55/push-ebp
555 89/<- %ebp 4/r32/esp
556
557 68/push 0/imm32
558 68/push 0/imm32
559 89/<- %esi 4/r32/esp
560
561 (_parse-array-of-decimal-ints Heap "" %esi)
562 (lookup *esi *(esi+4))
563 (check-ints-equal *eax 0 "F - test-parse-array-of-decimal-ints-empty")
564
565 89/<- %esp 5/r32/ebp
566 5d/pop-to-ebp
567 c3/return
568
569 test-parse-array-of-decimal-ints-just-whitespace:
570
571
572 55/push-ebp
573 89/<- %ebp 4/r32/esp
574
575 68/push 0/imm32
576 68/push 0/imm32
577 89/<- %esi 4/r32/esp
578
579 (_parse-array-of-decimal-ints Heap Space %esi)
580 (lookup *esi *(esi+4))
581 (check-ints-equal *eax 0 "F - test-parse-array-of-decimal-ints-just-whitespace")
582
583 89/<- %esp 5/r32/ebp
584 5d/pop-to-ebp
585 c3/return
586
587 test-parse-array-of-decimal-ints-extra-whitespace:
588
589 55/push-ebp
590 89/<- %ebp 4/r32/esp
591
592 68/push 0/imm32
593 68/push 0/imm32
594 89/<- %esi 4/r32/esp
595
596 68/push 3/imm32
597 68/push 2/imm32
598 68/push 1/imm32
599 68/push 0xc/imm32/size
600 89/<- %ecx 4/r32/esp
601
602 (_parse-array-of-decimal-ints Heap " 1 2 3 " %esi)
603 (lookup *esi *(esi+4))
604 (array-equal? %ecx %eax)
605 (check-ints-equal %eax 1 "F - test-parse-array-of-decimal-ints-extra-whitespace")
606
607 89/<- %esp 5/r32/ebp
608 5d/pop-to-ebp
609 c3/return
610
611 parse-array-of-decimal-ints:
612
613 55/push-ebp
614 89/<- %ebp 4/r32/esp
615
616 (_parse-array-of-decimal-ints Heap *(ebp+8) *(ebp+0xc))
617 $parse-array-of-decimal-ints:end:
618
619 89/<- %esp 5/r32/ebp
620 5d/pop-to-ebp
621 c3/return
622