diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-12 11:39:28 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-12 11:39:28 -0700 |
commit | 6c21568f03cc50462eb5fc7c10b4aabe204f4cc0 (patch) | |
tree | 81f31f420be5686c38b36753369ccc2e470bef95 /311decimal-int.subx | |
parent | 598f942624cb162132b7f7c2b7858516d95e73c4 (diff) | |
download | mu-6c21568f03cc50462eb5fc7c10b4aabe204f4cc0.tar.gz |
7011 - tile: keep garbage out of the stack
Diffstat (limited to '311decimal-int.subx')
-rw-r--r-- | 311decimal-int.subx | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/311decimal-int.subx b/311decimal-int.subx index 2b69872e..c7c2b03c 100644 --- a/311decimal-int.subx +++ b/311decimal-int.subx @@ -1,5 +1,6 @@ # Helpers for decimal ints. +# if slice doesn't contain a decimal number, return 0 parse-decimal-int-from-slice: # in: (addr slice) -> out/eax: int # . prologue 55/push-ebp @@ -18,6 +19,7 @@ $parse-decimal-int-from-slice:end: 5d/pop-to-ebp c3/return +# if slice doesn't contain a decimal number, return 0 parse-decimal-int: # in: (addr array byte) -> result/eax: int # . prologue 55/push-ebp @@ -110,8 +112,19 @@ $parse-decimal-int-helper:loop: # if (curr >= in->end) break 39/compare %esi 7/r32/edi 73/jump-if-addr>= break/disp8 - # digit = from-decimal-char(*curr) + # if !is-decimal-digit?(*curr) return 0 8a/copy-byte *esi 1/r32/CL + 50/push-eax + (is-decimal-digit? %ecx) # => eax + { + 3d/compare-eax-and 0/imm32/false + 75/jump-if-!= break/disp8 + 58/pop-to-eax + b8/copy-to-eax 0/imm32 + eb/jump $parse-decimal-int-helper:negate/disp8 + } + 58/pop-to-eax + # digit = from-decimal-char(*curr) 81 5/subop/subtract %ecx 0x30/imm32/zero # TODO: error checking # result = result * 10 + digit |