Added memrand function to VVS stdlib.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 13 Jul 2019 20:40:19 +0000 (13:40 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 13 Jul 2019 20:40:19 +0000 (13:40 -0700)
examples/random-heap-dump/Makefile [new file with mode: 0644]
examples/random-heap-dump/randomheap.pvvs [new file with mode: 0644]
stdlib/README.md
stdlib/heap.pvvs

diff --git a/examples/random-heap-dump/Makefile b/examples/random-heap-dump/Makefile
new file mode 100644 (file)
index 0000000..9d0ab07
--- /dev/null
@@ -0,0 +1,17 @@
+# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# All rights reserved.
+
+include ../config.mk
+
+all: randomheap
+
+randomheap:
+       $(CPP) $(CPP_FLAGS) -o temp.pvvs randomheap.pvvs
+       $(VVS_COMPILER) -i temp.pvvs -o randomheap.vvs
+       @rm -f temp.pvvs
+
+run: randomheap
+       $(VVS_INTERPRETER) -i randomheap.vvs
+
+clean:
+       @rm -f randomheap.vvs temp.pvvs
diff --git a/examples/random-heap-dump/randomheap.pvvs b/examples/random-heap-dump/randomheap.pvvs
new file mode 100644 (file)
index 0000000..2cd3532
--- /dev/null
@@ -0,0 +1,13 @@
+@@ Populate heap[18]-heap[29] with random values
+SSSTSTTN   | PUSH 11
+SSSTSSTSN  | PUSH 18
+NSTTTSTSN  | JSR > 11010 (memrand)
+
+@@ Print heap[16]-heap[31]
+SSSTTTTTN  | PUSH 31
+SSSTSSSSN  | PUSH 16
+NSTTTTSSSN | JSR > 111000 (dump heap)
+NNN        | DIE
+
+#include "debug.pvvs"
+#include "heap.pvvs"
index 91fa714..348cc76 100644 (file)
@@ -36,6 +36,7 @@ header comment for each function to learn the call and return stack.
          011xxx - heap functions
           11000 ----- memset                        (heap.pvvs)
           11001 ----- memcpy                        (heap.pvvs)
          011xxx - heap functions
           11000 ----- memset                        (heap.pvvs)
           11001 ----- memcpy                        (heap.pvvs)
+          11010 ----- memrand                       (heap.pvvs)
          100xxx - unassigned
          101xxx - unassigned
          110xxx - conversion functions
          100xxx - unassigned
          101xxx - unassigned
          110xxx - conversion functions
index d633447..131b141 100644 (file)
@@ -118,4 +118,43 @@ NSSVSSSTTSSTSSSSSSSTN   | Mark: 00011001 00000001
 SNN                     | DROP
 NTN                     | RTS
 
 SNN                     | DROP
 NTN                     | RTS
 
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@ Description:
+@   This function writes random words into the memory locations:
+@     startaddr -> startaddr+count
+@ Call Stack:
+@   count
+@   startaddr  <-- TOS
+@ Return Stack:
+@   <empty>
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+NSSVTTSTSN              | Mark: 11010 (memrand)
+SSSSN                   | PUSH 0 (ptr)
+SNT                     | SWAP
+TTS                     | STORE
+
+@ Store random word into one memory location on each pass through this loop.
+NSSVSSSTTSTSSSSSSSSSN   | Mark: 00011010 00000000
+SNS                     | DUP
+SSSSN                   | PUSH 0 (ptr)
+TTT                     | LOAD
+TSSS                    | ADD
+NSTTSSSSN               | JSR > 10000 (random)
+TTS                     | STORE
+
+@ Decrement and check loop end conditions
+SNS                     | DUP
+NTSSSSTTSTSSSSSSSSTN    | BRZ > 00011010 00000001
+SSSTN                   | PUSH 1
+TSST                    | SUBTRACT
+NSNSSSTTSTSSSSSSSSSN    | JMP > 00011010 00000000
+
+NNN
+@ Clean up and return
+NSSVSSSTTSTSSSSSSSSTN   | Mark: 00011010 00000001
+SNN                     | DROP
+NTN                     | RTS
+
+#include <math.pvvs>
+
 #endif
 #endif