TODO: instruction set has changed
This is a minimal version of the register-based virtual machine with just the core components needed to start fresh development.
machine.c- The C implementation of the 16-bit register-based virtual machinemachine.fs- The Forth implementation of the virtual machine (for development/testing)memory.fs- VM memory system and block I/O (used by machine.fs)assembler.fs- Assembly tools and compiler (depends on memory.fs)machine- Pre-compiled executable (ready to use)build.sh- Build scriptreadme.md- This documentation
Build from source:
./build.shThis compiles machine.c to machine executable. Any gcc errors will be displayed.
The machine loads and executes bytecode from block0.bin:
./machineIf no block0.bin exists, it will show an error or halt immediately.
For development and testing:
gforth machine.fsThis loads the VM in Forth where you can:
- Single-step through instructions with
step - Examine registers and memory
- Test VM operations interactively
This is a 16-bit register-based virtual machine with:
- 16 registers (R0-R15, with R0 as program counter)
- 64KB memory space (addresses 0x0000 to 0xFFFF)
- 16 instruction opcodes (complete but minimal instruction set)
- Little-endian byte order
- Block-based storage system (block0.bin, block1.bin, etc.)
HALT- Halt executionLDC- Load constantLD+- Load with incrementST+- Store with incrementCP?- Conditional copyADD- AdditionSUB- SubtractionMUL- MultiplicationDIV- DivisionNAND- Bitwise NANDSHL- Shift leftSHR- Shift rightIN- Input characterOUT- Output characterREAD- Read blockWRITE- Write block
This minimal system provides just the virtual machine foundation. From here you can build:
- Assemblers for generating bytecode
- Compilers for high-level languages
- Operating systems and kernels
- Applications and games
- Development tools and debuggers
See the complete system in ../register_v2/ for:
- Full Forth kernel and compiler
- Assembler tools
- Graphics libraries (pixels, turtle graphics)
- Example programs and tests
- Bootstrap process documentation
The book.md in the repository root contains the complete tutorial for building from this minimal VM up to a full Forth system with graphics capabilities.
- Seem to need to press Enter before interacting
- Forth-based machine doesn't echo as keys entered and doesn't allow editing
- Mitigated by
cat - | gforth ...
- Mitigated by
- d. and u. don't work with negative numbers
- Some words (e.g.
+foonot flagged as unable to find)
\ poor man's . ( n -- ) print decimal number
: . dup 10000 / dup 48 + emit 10000 * -
dup 1000 / dup 48 + emit 1000 * -
dup 100 / dup 48 + emit 100 * -
dup 10 / dup 48 + emit 10 * -
48 + emit ;