about summary refs log tree commit diff stats
path: root/075print-int-decimal.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-12-31 21:58:52 -0800
committerKartik Agaram <vc@akkartik.com>2019-12-31 21:58:52 -0800
commita9baaac00b4bacfbee2986482ac0c37a7461927c (patch)
tree3f083db163d153b9d0356b0b5e77fc2ed0b74cae /075print-int-decimal.subx
parentf1344589daa99bfc247367280be3ea3588166c8a (diff)
downloadmu-a9baaac00b4bacfbee2986482ac0c37a7461927c.tar.gz
5847 - literal inputs
Diffstat (limited to '075print-int-decimal.subx')
-rw-r--r--075print-int-decimal.subx101
1 files changed, 101 insertions, 0 deletions
diff --git a/075print-int-decimal.subx b/075print-int-decimal.subx
index 8e8c7da4..6eba81a1 100644
--- a/075print-int-decimal.subx
+++ b/075print-int-decimal.subx
@@ -304,4 +304,105 @@ test-print-int32-decimal-negative-multiple-digits:
     # . end
     c3/return
 
+is-decimal-digit?:  # c : byte -> eax : boolean
+    # . prologue
+    55/push-ebp
+    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+    # . save registers
+    51/push-ecx
+    # ecx = c
+    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   8/disp8         .                 # copy *(ebp+8) to ecx
+    # return false if c < '0'
+    81          7/subop/compare     3/mod/direct    1/rm32/ecx    .           .             .           .           .               0x30/imm32        # compare ecx
+    7c/jump-if-lesser  $is-decimal-digit?:false/disp8
+    # return true if c <= '9'
+    81          7/subop/compare     3/mod/direct    1/rm32/ecx    .           .             .           .           .               0x39/imm32        # compare ecx
+    7e/jump-if-lesser-or-equal  $is-decimal-digit?:true/disp8
+    # otherwise return false
+$is-decimal-digit?:false:
+    b8/copy-to-eax  0/imm32/false
+    eb/jump $is-decimal-digit?:end/disp8
+$is-decimal-digit?:true:
+    b8/copy-to-eax  1/imm32/true
+$is-decimal-digit?:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+    5d/pop-to-ebp
+    c3/return
+
+test-is-decimal-digit-below-0:
+    # eax = is-decimal-digit?(0x2f)
+    # . . push args
+    68/push  0x2f/imm32
+    # . . call
+    e8/call  is-decimal-digit?/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+    # check-ints-equal(eax, 0, msg)
+    # . . push args
+    68/push  "F - test-is-decimal-digit-below-0"/imm32
+    68/push  0/imm32/false
+    50/push-eax
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    c3/return
+
+test-is-decimal-digit-0-to-9:
+    # eax = is-decimal-digit?(0x30)
+    # . . push args
+    68/push  0x30/imm32
+    # . . call
+    e8/call  is-decimal-digit?/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+    # check-ints-equal(eax, 1, msg)
+    # . . push args
+    68/push  "F - test-is-decimal-digit-at-0"/imm32
+    68/push  1/imm32/true
+    50/push-eax
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    # eax = is-decimal-digit?(0x39)
+    # . . push args
+    68/push  0x39/imm32
+    # . . call
+    e8/call  is-decimal-digit?/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+    # check-ints-equal(eax, 1, msg)
+    # . . push args
+    68/push  "F - test-is-decimal-digit-at-9"/imm32
+    68/push  1/imm32/true
+    50/push-eax
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    c3/return
+
+test-is-decimal-digit-above-9:
+    # eax = is-decimal-digit?(0x3a)
+    # . . push args
+    68/push  0x3a/imm32
+    # . . call
+    e8/call  is-decimal-digit?/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+    # check-ints-equal(eax, 0, msg)
+    # . . push args
+    68/push  "F - test-is-decimal-digit-above-9"/imm32
+    68/push  0/imm32/false
+    50/push-eax
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    c3/return
+
 # . . vim:nowrap:textwidth=0