From 535fe9ac96dba0950efd1bfe6788801f6197971f Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 13 Feb 2021 18:18:05 -0800 Subject: 7737 --- html/baremetal/311decimal-int.subx.html | 209 ++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) (limited to 'html/baremetal/311decimal-int.subx.html') diff --git a/html/baremetal/311decimal-int.subx.html b/html/baremetal/311decimal-int.subx.html index 86304b6b..9c57479e 100644 --- a/html/baremetal/311decimal-int.subx.html +++ b/html/baremetal/311decimal-int.subx.html @@ -14,9 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #000000; background- body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } a { color:inherit; } * { font-size:12pt; font-size: 1em; } +.SpecialChar { color: #d70000; } .subxComment { color: #005faf; } .subxS1Comment { color: #0000af; } .LineNr { } +.subxH1Comment { color: #005faf; text-decoration: underline; } +.subxMinorFunction { color: #875f5f; } .subxTest { color: #5f8700; } .subxFunction { color: #af5f00; text-decoration: underline; } .Constant { color: #008787; } @@ -482,6 +485,212 @@ if ('onhashchange' in window) { 425 89/<- %esp 5/r32/ebp 426 5d/pop-to-ebp 427 c3/return +428 +429 _parse-array-of-decimal-ints: # ad: (addr allocation-descriptor), s: (addr array byte), out: (addr handle array int) +430 # pseudocode +431 # end = &s->data[s->size] +432 # curr = s->data +433 # size = 0 +434 # while true +435 # if (curr >= end) break +436 # curr = skip-chars-matching-in-slice(curr, end, ' ') +437 # if (curr >= end) break +438 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') +439 # ++size +440 # allocate-array(ad, size*4, out) +441 # var slice: slice = {s->data, 0} +442 # curr = lookup(out)->data +443 # while true +444 # if (slice->start >= end) break +445 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') +446 # if (slice->start >= end) break +447 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') +448 # *curr = parse-hex-int-from-slice(slice) +449 # curr += 4 +450 # slice->start = slice->end +451 # return result +452 # +453 # . prologue +454 55/push-ebp +455 89/<- %ebp 4/r32/esp +456 # . save registers +457 50/push-eax +458 51/push-ecx +459 52/push-edx +460 53/push-ebx +461 56/push-esi +462 57/push-edi +463 # esi = s +464 8b/-> *(ebp+0xc) 6/r32/esi +465 # var curr/ecx: (addr byte) = s->data +466 8d/copy-address *(esi+4) 1/r32/ecx +467 # var end/edx: (addr byte) = &s->data[s->size] +468 # . edx = s->size +469 8b/-> *esi 2/r32/edx +470 # . edx += curr +471 01/add-to %edx 1/r32/ecx +472 # var size/ebx: int = 0 +473 31/xor-with %ebx 3/r32/ebx +474 $_parse-array-of-decimal-ints:loop1: +475 # if (curr >= end) break +476 39/compare %ecx 2/r32/edx +477 73/jump-if-addr>= $_parse-array-of-decimal-ints:break1/disp8 +478 # curr = skip-chars-matching-in-slice(curr, end, ' ') +479 (skip-chars-matching-in-slice %ecx %edx 0x20) # => eax +480 89/<- %ecx 0/r32/eax +481 # if (curr >= end) break +482 39/compare %ecx 2/r32/edx +483 73/jump-if-addr>= $_parse-array-of-decimal-ints:break1/disp8 +484 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') +485 (skip-chars-not-matching-in-slice %ecx %edx 0x20) # => eax +486 89/<- %ecx 0/r32/eax +487 # size += 4 +488 81 0/subop/add %ebx 4/imm32 +489 eb/jump $_parse-array-of-decimal-ints:loop1/disp8 +490 $_parse-array-of-decimal-ints:break1: +491 (allocate-array *(ebp+8) %ebx *(ebp+0x10)) +492 $_parse-array-of-decimal-ints:pass2: +493 # var slice/edi: slice = {s->data, 0} +494 68/push 0/imm32/end +495 8d/copy-address *(esi+4) 7/r32/edi +496 57/push-edi +497 89/<- %edi 4/r32/esp +498 # curr = lookup(out)->data +499 8b/-> *(ebp+0x10) 0/r32/eax +500 (lookup *eax *(eax+4)) # => eax +501 8d/copy-address *(eax+4) 1/r32/ecx +502 $_parse-array-of-decimal-ints:loop2: +503 # if (slice->start >= end) break +504 39/compare *edi 2/r32/edx +505 73/jump-if-addr>= $_parse-array-of-decimal-ints:end/disp8 +506 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') +507 (skip-chars-matching-in-slice *edi %edx 0x20) # => eax +508 89/<- *edi 0/r32/eax +509 # if (slice->start >= end) break +510 39/compare *edi 2/r32/edx +511 73/jump-if-addr>= $_parse-array-of-decimal-ints:end/disp8 +512 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') +513 (skip-chars-not-matching-in-slice *edi %edx 0x20) # => eax +514 89/<- *(edi+4) 0/r32/eax +515 # *curr = parse-hex-int-from-slice(slice) +516 (parse-decimal-int-from-slice %edi) +517 89/<- *ecx 0/r32/eax +518 # curr += 4 +519 81 0/subop/add %ecx 4/imm32 +520 # slice->start = slice->end +521 8b/-> *(edi+4) 0/r32/eax +522 89/<- *edi 0/r32/eax +523 eb/jump $_parse-array-of-decimal-ints:loop2/disp8 +524 $_parse-array-of-decimal-ints:end: +525 # . reclaim locals +526 81 0/subop/add %esp 8/imm32 +527 # . restore registers +528 5f/pop-to-edi +529 5e/pop-to-esi +530 5b/pop-to-ebx +531 5a/pop-to-edx +532 59/pop-to-ecx +533 58/pop-to-eax +534 # . epilogue +535 89/<- %esp 5/r32/ebp +536 5d/pop-to-ebp +537 c3/return +538 +539 test-parse-array-of-decimal-ints: +540 # . prologue +541 55/push-ebp +542 89/<- %ebp 4/r32/esp +543 # var h/esi: (handle array int) +544 68/push 0/imm32 +545 68/push 0/imm32 +546 89/<- %esi 4/r32/esp +547 # var ecx: (array int) = [1, 2, 3] +548 68/push 3/imm32 +549 68/push 2/imm32 +550 68/push 1/imm32 +551 68/push 0xc/imm32/size +552 89/<- %ecx 4/r32/esp +553 # +554 (_parse-array-of-decimal-ints Heap "1 2 3" %esi) +555 (lookup *esi *(esi+4)) # => eax +556 (array-equal? %ecx %eax) # => eax +557 (check-ints-equal %eax 1 "F - test-parse-array-of-decimal-ints") +558 # . epilogue +559 89/<- %esp 5/r32/ebp +560 5d/pop-to-ebp +561 c3/return +562 +563 test-parse-array-of-decimal-ints-empty: +564 # - empty string = empty array +565 # . prologue +566 55/push-ebp +567 89/<- %ebp 4/r32/esp +568 # var h/esi: handle +569 68/push 0/imm32 +570 68/push 0/imm32 +571 89/<- %esi 4/r32/esp +572 # +573 (_parse-array-of-decimal-ints Heap "" %esi) +574 (lookup *esi *(esi+4)) # => eax +575 (check-ints-equal *eax 0 "F - test-parse-array-of-decimal-ints-empty") +576 # . epilogue +577 89/<- %esp 5/r32/ebp +578 5d/pop-to-ebp +579 c3/return +580 +581 test-parse-array-of-decimal-ints-just-whitespace: +582 # - just whitespace = empty array +583 # . prologue +584 55/push-ebp +585 89/<- %ebp 4/r32/esp +586 # var h/esi: handle +587 68/push 0/imm32 +588 68/push 0/imm32 +589 89/<- %esi 4/r32/esp +590 # +591 (_parse-array-of-decimal-ints Heap Space %esi) +592 (lookup *esi *(esi+4)) # => eax +593 (check-ints-equal *eax 0 "F - test-parse-array-of-decimal-ints-just-whitespace") +594 # . epilogue +595 89/<- %esp 5/r32/ebp +596 5d/pop-to-ebp +597 c3/return +598 +599 test-parse-array-of-decimal-ints-extra-whitespace: +600 # . prologue +601 55/push-ebp +602 89/<- %ebp 4/r32/esp +603 # var h/esi: handle +604 68/push 0/imm32 +605 68/push 0/imm32 +606 89/<- %esi 4/r32/esp +607 # var ecx: (array int) = [1, 2, 3] +608 68/push 3/imm32 +609 68/push 2/imm32 +610 68/push 1/imm32 +611 68/push 0xc/imm32/size +612 89/<- %ecx 4/r32/esp +613 # +614 (_parse-array-of-decimal-ints Heap " 1 2 3 " %esi) +615 (lookup *esi *(esi+4)) # => eax +616 (array-equal? %ecx %eax) # => eax +617 (check-ints-equal %eax 1 "F - test-parse-array-of-decimal-ints-extra-whitespace") +618 # . epilogue +619 89/<- %esp 5/r32/ebp +620 5d/pop-to-ebp +621 c3/return +622 +623 parse-array-of-decimal-ints: # s: (addr array byte), out: (addr handle array int) +624 # . prologue +625 55/push-ebp +626 89/<- %ebp 4/r32/esp +627 # +628 (_parse-array-of-decimal-ints Heap *(ebp+8) *(ebp+0xc)) +629 $parse-array-of-decimal-ints:end: +630 # . epilogue +631 89/<- %esp 5/r32/ebp +632 5d/pop-to-ebp +633 c3/return -- cgit 1.4.1-2-gfad0