about summary refs log tree commit diff stats
path: root/linux/407right-justify.mu
diff options
context:
space:
mode:
Diffstat (limited to 'linux/407right-justify.mu')
-rw-r--r--linux/407right-justify.mu14
1 files changed, 14 insertions, 0 deletions
diff --git a/linux/407right-justify.mu b/linux/407right-justify.mu
new file mode 100644
index 00000000..b7322ae5
--- /dev/null
+++ b/linux/407right-justify.mu
@@ -0,0 +1,14 @@
+# print 'n' with enough leading spaces to be right-justified in 'width'
+fn print-int32-decimal-right-justified screen: (addr screen), n: int, _width: int {
+  # tweak things for negative numbers
+  var n-width/eax: int <- decimal-size n
+  var width/ecx: int <- copy _width
+  {
+    compare n-width, width
+    break-if->=
+    print-grapheme screen, 0x20/space
+    width <- decrement
+    loop
+  }
+  print-int32-decimal screen, n
+}