Website Summary Files Commits Branches @commit @diff @stats
path: root / vm / README.md
blob: e488993c0a0d0cbf03c199e9b23b21e4d709aa4c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# tonkobali virtual machine

This is a virtual machine which executes SUBLEQ instructions.
The idea is we have a vector of words (i64) which represents our entire memory.
We use a certain amount of addresses in the beginning of this memory for our purposes.

Since we have only one instruction we only store data, no opcodes.
When the virtual machine program counter is at a certain location, the next three values from memory are read and SUBLEQ is executed with those values as arguments.
This continues until the program jumps to address 0, when we reach a "HALTED" state.

## TUI

Once started, you may enter commands for the VM, and to the left of your cursor you'll see vertical bars.
If the contents of these bars is empty, it means the machine is executing instructions.
If the contents are "HALTED", the machine has stopped executing.
If the contents are "STEP", the VM is in single-step mode.

All commands and their meaning can be found by issuing `help`:

```
<ADDRESS> is a usize constant
<VALUE> is a Word (i64) constant

Multiple 'Memory IO' commands may be put on a single line, when
separated by spaces

General commands:
  h, ?, help          This menu
  q, e, quit, exit    Stop and exit the virtual machine

Normal execution:
  r, run <ADDRESS>    Start normal execution at ADDRESS
                      Only applicable when 'HALTED'

Single-step execution:
  s, single <ADDRESS>    Start single-step execution at ADDRESS
  c, continue            Resume normal execution
                         Only applicable when in 'STEP' mode
  n, next                Execute next instruction
                         Only applicable when in 'STEP' mode

Memory IO:
  <ADDRESS>              Print the value at the location
  <ADDRESS>.<ADDRESS>    Print the values between the locations
                         (inclusive range)
  <ADDRESS>:<VALUE>      Set value at ADDRESS to VALUE
```

Single-step mode allows you to execute only a single instruction at a time.
After each execution the arguments to SUBLEQ are printed.
At any point you may manipulate the memory.
Then you can execute the next single instruction (with `next`) or resume normal execution (with `continue`).

The memory io commands are inspired from Steve Wozniak's wozmon.