about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-05-04 14:58:13 -0700
committerKartik Agaram <vc@akkartik.com>2019-05-04 14:58:13 -0700
commitd36c42fa3ff4d6f2f4282bde3c586c67fdacda46 (patch)
treea1d8a6ff4befa4a6592f5de20fdc5c94527e1da4 /subx
parent8591331a7f674d71c50ea0f560e1412d56001801 (diff)
downloadmu-d36c42fa3ff4d6f2f4282bde3c586c67fdacda46.tar.gz
5144
Pull in some final stylistic and debugging-friendly tweaks from my old
version of commit 5132 and earlier.
Diffstat (limited to 'subx')
-rw-r--r--subx/074print-int-decimal.subx8
1 files changed, 7 insertions, 1 deletions
diff --git a/subx/074print-int-decimal.subx b/subx/074print-int-decimal.subx
index c6f4951c..04385795 100644
--- a/subx/074print-int-decimal.subx
+++ b/subx/074print-int-decimal.subx
@@ -14,6 +14,9 @@
 #?     cd/syscall  0x80/imm8
 
 print-int32-decimal:  # out : (address stream), n : int32
+    # works by generating characters from lowest to highest and pushing them
+    # to the stack, before popping them one by one into the stream
+    #
     # pseudocode:
     #   push sentinel
     #   EAX = abs(n)
@@ -57,7 +60,8 @@ print-int32-decimal:  # out : (address stream), n : int32
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           0/r32/EAX   0xc/disp8       .                 # copy *(EBP+12) to EAX
     3d/compare-EAX-with  0/imm32
     7d/jump-if-greater-or-equal  $print-int32-decimal:read-loop/disp8
-    f7  3/subop/negate              3/mod/direct    0/rm32/EAX    .           .             .           .           .               .                 # negate EAX
+$print-int32-decimal:negative:
+    f7          3/subop/negate      3/mod/direct    0/rm32/EAX    .           .             .           .           .               .                 # negate EAX
 $print-int32-decimal:read-loop:
     # EAX, EDX = EAX / 10, EAX % 10
     99/sign-extend-EAX-into-EDX
@@ -73,6 +77,7 @@ $print-int32-decimal:read-break:
     # if (n < 0) push('-')
     81          7/subop/compare     1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       0/imm32           # compare *(EBP+12)
     7d/jump-if-greater-or-equal  $print-int32-decimal:write/disp8
+$print-int32-decimal:push-negative:
     68/push  0x2d/imm32/-
 $print-int32-decimal:write:
     # EDI = out
@@ -93,6 +98,7 @@ $print-int32-decimal:write-loop:
     # if (curr >= max) abort
     39/compare                      3/mod/direct    1/rm32/ECX    .           .             .           3/r32/EBX   .               .                 # compare ECX with EBX
     7d/jump-if-greater-or-equal  $print-int32-decimal:abort/disp8
+$print-int32-decimal:write-char:
     # *curr = AL
     88/copy-byte                    0/mod/indirect  1/rm32/ECX    .           .             .           0/r32/AL    .               .                 # copy AL to byte at *ECX
     # ++curr