Added first two functions to stdlib.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Thu, 11 Jul 2019 11:31:10 +0000 (04:31 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Thu, 11 Jul 2019 11:31:10 +0000 (04:31 -0700)
stdio:1000 - print string from stack
stdio:1001 - print string from heap

stdlib/README.md [new file with mode: 0644]
stdlib/stdio.pvvs [new file with mode: 0644]

diff --git a/stdlib/README.md b/stdlib/README.md
new file mode 100644 (file)
index 0000000..2639a41
--- /dev/null
@@ -0,0 +1,29 @@
+# Reservations #
+
+## Label ##
+
+    00000000 0xxxxxxx - reserved for stdlib function entry points
+    00000000 1xxxxxxx - unassigned
+    0xxxxxxx xxxxxxxx - reserved for private use by stdlib
+    1xxxxxxx xxxxxxxx - available for use in user programs
+
+## Heap ##
+
+    The first 256 heap addresses are reserved when using the stdlib.
+
+# Entry Points #
+
+The following labels are entry points to stdlib functions. Read the
+header comment for each function to learn the call and return stack.
+
+    stdio.pvvs:
+           1000 - print string from stack
+           1001 - print string from heap
+
+# Misc #
+
+By convention, each public stdlib label will have 8 bits of
+private label space associated with it, formed as follows:
+
+    00001000 xxxxxxxx - for use by 1000
+    00001001 xxxxxxxx - for use by 1001
diff --git a/stdlib/stdio.pvvs b/stdlib/stdio.pvvs
new file mode 100644 (file)
index 0000000..d9184ad
--- /dev/null
@@ -0,0 +1,42 @@
+################################################################################
+# Description:
+#   This function prints a null-terminated string from the stack.
+# Call Stack:
+#   null-terminator (ASCII '\0')
+#   char n
+#   ...
+#   char 2
+#   char 1 <-- TOS
+# Return Stack:
+#   <empty>
+################################################################################
+NSSVTSSSN               | Mark: 1000 (print string from stack)
+SNS                     | DUP
+NTSSSSSTSSSSSSSSSSTN    | BRZ > 00001000 00000001
+TNSS                    | Print character
+NSNTSSSN                | JMP > 1000
+NSSVSSSSTSSSSSSSSSSTN   | Mark: 00001000 00000001
+SNN                     | DROP
+NTN                     | RTS
+
+################################################################################
+# Description:
+#   This function prints a null-terminated string from the heap.
+# Call Stack:
+#   pointer to first character  <-- TOS
+# Return Stack:
+#   <empty>
+################################################################################
+NSSVTSSTN               | Mark: 1001 (print string from heap)
+SNS                     | DUP
+TTT                     | LOAD
+SNS                     | DUP
+NTSSSSSTSSTSSSSSSSTN    | BRZ > 00001001 00000001
+TNSS                    | Print character
+SSSTN                   | Push +1
+TSSS                    | ADD
+NSNTSSTN                | JMP > 1001
+NSSVSSSSTSSTSSSSSSSTN   | Mark: 00001001 00000001
+SNN                     | DROP
+SNN                     | DROP
+NTN                     | RTS