Added VVS stdlib function to dump heap in human readable form.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 13 Jul 2019 05:08:51 +0000 (22:08 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 13 Jul 2019 05:08:51 +0000 (22:08 -0700)
stdlib/README.md
stdlib/debug.pvvs [new file with mode: 0644]

index ee4670b..2bba7d5 100644 (file)
@@ -36,8 +36,9 @@ header comment for each function to learn the call and return stack.
          011xxx - unassigned
          100xxx - unassigned
          101xxx - unassigned
          011xxx - unassigned
          100xxx - unassigned
          101xxx - unassigned
-         110xxx - unassigned
-         111xxx - conversion functions
+         110xxx - conversion functions
+         111xxx - debug functions
+         111000 ----- dump heap                     (debug.pvvs)
         1xxxxxx - reserved for less common entry points
         1000000 ----- print sign of number          (stdio.pvvs)
         1000001 ----- print magnitude of number     (stdio.pvvs)
         1xxxxxx - reserved for less common entry points
         1000000 ----- print sign of number          (stdio.pvvs)
         1000001 ----- print magnitude of number     (stdio.pvvs)
diff --git a/stdlib/debug.pvvs b/stdlib/debug.pvvs
new file mode 100644 (file)
index 0000000..db61a96
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef VVS_STDLIB_DEBUG
+#define VVS_STDLIB_DEBUG
+
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@ Description:
+@   This function dumps the heap from startaddr to endaddr.
+@ Call Stack:
+@   endaddr
+@   startaddr  <-- TOS
+@ Return Stack:
+@   <empty>
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+NSSVTTTSSSN              | Mark: 111000 (dump heap)
+
+@ Prepare a numeric address and value on the stack
+SNS                      | DUP
+SNS                      | DUP
+TTT                      | LOAD
+SNT                      | SWAP
+
+@ Print output line for this memory location
+NSTTSSSSSTN              | JSR>1000001 (print absolute value of number)
+SSSTTTSTSN               | PUSH ASCII ':'
+SSSTSSTN                 | PUSH ASCII '\t'
+TNSS                     | PUTC
+TNSS                     | PUTC
+NSTTSTSN                 | JSR>1010 (print number from stack)
+SSSTSTSN                 | PUSH ASCII '\n'
+TNSS                     | PUTC
+
+@ Figure out if the loop is complete.
+SSSSN                    | PUSH 0 (ptr)
+SNT                      | SWAP
+TTS                      | STORE
+SNS                      | DUP
+SSSSN                    | PUSH 0 (ptr)
+TTT                      | LOAD
+TSST                     | SUBTRACT
+NTSSSTTTSSSSSSSSSSSN     | BRZ > 00111000 00000000
+SSSSN                    | PUSH 0 (ptr)
+TTT                      | LOAD
+SSSTN                    | PUSH 1
+TSSS                     | ADD
+NSNTTTSSSN               | JMP>111000 (dump heap)
+
+@ Clean up and return
+NSSVSSTTTSSSSSSSSSSSN    | Mark: 00111000 00000000
+SNN                      | DROP
+NTN                      | RTS
+
+#include <stdio.pvvs>
+
+#endif