about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-01-19 10:46:35 -0500
committerelioat <elioat@tilde.institute>2025-01-19 10:46:35 -0500
commit2ae79a0cf9d0f7439fac454d65e2cb8f962b7ca9 (patch)
tree44c1206564b3e3934ba12137626dcbbc0c5cb75a
parent966e29f871e9bf91390346ac982fc0fe41cc4197 (diff)
downloadtour-2ae79a0cf9d0f7439fac454d65e2cb8f962b7ca9.tar.gz
*
-rw-r--r--awk/vm/README.md48
1 files changed, 48 insertions, 0 deletions
diff --git a/awk/vm/README.md b/awk/vm/README.md
new file mode 100644
index 0000000..e6bd7a1
--- /dev/null
+++ b/awk/vm/README.md
@@ -0,0 +1,48 @@
+# Simple Stack-Based Virtual Machine
+
+This is an implementation of a minimal stack-based virtual machine in AWK, inspired by Forth. The VM provides basic stack manipulation, arithmetic operations, register access, and memory operations.
+
+## Architecture
+
+The VM consists of:
+- A data stack (100 elements)
+- Main memory (1000 cells)
+- Three registers:
+  - A: General purpose register
+  - B: Often used as memory pointer
+  - P: Program pointer, used for sequential memory operations
+
+## Instruction Set
+
+### Stack Operations
+- `DROP` - Remove top item from stack
+- `DUP` - Duplicate top stack item
+- `OVER` - Copy second item to top of stack
+- Numbers are automatically pushed onto the stack
+
+### Arithmetic Operations
+- `+` - Add top two stack items (a b -- a+b)
+- `AND` - Bitwise AND of top two items
+- `XOR` - Bitwise XOR of top two items
+- `NOT` - Bitwise NOT of top item
+- `2*` - Multiply top item by 2 (shift left)
+- `2/` - Divide top item by 2 (shift right)
+
+### Register Operations
+- `A` - Push value of A register onto stack
+- `A!` - Store top stack value into A register
+- `B!` - Store top stack value into B register
+
+### Memory Operations
+- `@` - Fetch from memory address on stack
+- `!` - Store to memory address on stack
+- `@+` - Fetch from memory at P, then increment P
+- `!+` - Store to memory at P, then increment P
+- `@B` - Fetch from memory address in B register
+- `!B` - Store to memory address in B register
+- `@P` - Fetch from memory address in P register
+- `!P` - Store to memory address in P register
+
+### Utility
+- `.` - NO-OP (does nothing)
+- `BYE` - Exit program
\ No newline at end of file