about summary refs log tree commit diff stats
path: root/311parse-decimal-int.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-19 21:44:48 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-19 21:44:48 -0700
commit8e4b4f2013b3f347e84398c70eabab60f6edd625 (patch)
treebf0e5f947ea43dbca51998bd4a27a05ffd8d161b /311parse-decimal-int.subx
parent72e8240a23da7b82893d6b4e7ed3337ca0827049 (diff)
downloadmu-8e4b4f2013b3f347e84398c70eabab60f6edd625.tar.gz
6807 - tile: render intermediate stack state
Diffstat (limited to '311parse-decimal-int.subx')
-rw-r--r--311parse-decimal-int.subx54
1 files changed, 53 insertions, 1 deletions
diff --git a/311parse-decimal-int.subx b/311parse-decimal-int.subx
index 538f3e87..fe08b932 100644
--- a/311parse-decimal-int.subx
+++ b/311parse-decimal-int.subx
@@ -1,6 +1,7 @@
 # Helpers for parsing decimal ints.
 
-parse-decimal-int-from-slice:  # in: (addr slice) -> out/eax: int    # . prologue
+parse-decimal-int-from-slice:  # in: (addr slice) -> out/eax: int
+    # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
@@ -17,6 +18,57 @@ $parse-decimal-int-from-slice:end:
     5d/pop-to-ebp
     c3/return
 
+parse-decimal-int:  # in: (addr array byte) -> result/eax: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    52/push-edx
+    # eax = in
+    8b/-> *(ebp+8) 0/r32/eax
+    # var start/ecx: (addr byte) = &in->data
+    8d/copy-address *(eax+4) 1/r32/ecx
+    # var end/edx: (addr byte) = &in->data[in->size]
+    8b/-> *eax 2/r32/edx
+    8d/copy-address *(eax+edx+4) 2/r32/edx
+    #
+    (parse-decimal-int-helper %ecx %edx)  # => eax
+$parse-decimal-int:end:
+    # . restore registers
+    5a/pop-to-edx
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+parse-decimal-int-from-stream:  # in: (addr stream byte) -> result/eax: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    52/push-edx
+    # eax = in
+    8b/-> *(ebp+8) 0/r32/eax
+    # var start/ecx: (addr byte) = &in->data[in->read]
+    8b/-> *(eax+4) 1/r32/ecx
+    8d/copy-address *(eax+ecx+0xc) 1/r32/ecx
+    # var end/edx: (addr byte) = &in->data[in->write]
+    8b/-> *eax 2/r32/edx
+    8d/copy-address *(eax+edx+0xc) 2/r32/edx
+    #
+    (parse-decimal-int-helper %ecx %edx)  # => eax
+$parse-decimal-int-from-stream:end:
+    # . restore registers
+    5a/pop-to-edx
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 parse-decimal-int-helper:  # start: (addr byte), end: (addr byte) -> result/eax: int
     # . prologue
     55/push-ebp