From d63de3fa849451796c2381723d042f254d434670 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sat, 13 Jul 2019 13:40:19 -0700 Subject: [PATCH] Added memrand function to VVS stdlib. --- examples/random-heap-dump/Makefile | 17 ++++++++++ examples/random-heap-dump/randomheap.pvvs | 13 ++++++++ stdlib/README.md | 1 + stdlib/heap.pvvs | 39 +++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 examples/random-heap-dump/Makefile create mode 100644 examples/random-heap-dump/randomheap.pvvs diff --git a/examples/random-heap-dump/Makefile b/examples/random-heap-dump/Makefile new file mode 100644 index 0000000..9d0ab07 --- /dev/null +++ b/examples/random-heap-dump/Makefile @@ -0,0 +1,17 @@ +# (c) 2019 Aaron Taylor +# 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 index 0000000..2cd3532 --- /dev/null +++ b/examples/random-heap-dump/randomheap.pvvs @@ -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" diff --git a/stdlib/README.md b/stdlib/README.md index 91fa714..348cc76 100644 --- a/stdlib/README.md +++ b/stdlib/README.md @@ -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) + 11010 ----- memrand (heap.pvvs) 100xxx - unassigned 101xxx - unassigned 110xxx - conversion functions diff --git a/stdlib/heap.pvvs b/stdlib/heap.pvvs index d633447..131b141 100644 --- a/stdlib/heap.pvvs +++ b/stdlib/heap.pvvs @@ -118,4 +118,43 @@ NSSVSSSTTSSTSSSSSSSTN | Mark: 00011001 00000001 SNN | DROP NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Description: +@ This function writes random words into the memory locations: +@ startaddr -> startaddr+count +@ Call Stack: +@ count +@ startaddr <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +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 + #endif -- 2.20.1