From 32c440bf6f1f2199c3e925f32bd3b621039605e6 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 11 Jul 2019 04:31:10 -0700 Subject: [PATCH] Added first two functions to stdlib. stdio:1000 - print string from stack stdio:1001 - print string from heap --- stdlib/README.md | 29 +++++++++++++++++++++++++++++ stdlib/stdio.pvvs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 stdlib/README.md create mode 100644 stdlib/stdio.pvvs diff --git a/stdlib/README.md b/stdlib/README.md new file mode 100644 index 0000000..2639a41 --- /dev/null +++ b/stdlib/README.md @@ -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 index 0000000..d9184ad --- /dev/null +++ b/stdlib/stdio.pvvs @@ -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: +# +################################################################################ +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: +# +################################################################################ +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 -- 2.20.1