You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-11Lines changed: 33 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -7,22 +7,43 @@ simple.vm
7
7
8
8
This repository contains the implementation for a simple virtual-machine, along with a driver which will read a program from a file and execute it via that virtual machine.
9
9
10
-
In addition to the virtual machine itself you'll also find:
10
+
There are actually two intepreters, one written in C, and another written
11
+
in golang.
11
12
12
-
*[A simple compiler](compiler).
13
+
In addition to the virtual machine interpreter you'll also find:
14
+
15
+
*[A simple compiler](compiler), written in perl.
13
16
* This will translate from assembly-source into binary-opcodes.
14
-
*[A simple decompiler](decompiler).
17
+
*[A simple decompiler](decompiler), written in perl.
15
18
* This will translate in the other direction.
16
-
* Several [example programs](examples/).
17
-
* An example of [embedding](embedded.c) the virtual machine in a C host program.
19
+
* Several [example programs](examples/) written in our custom assembly-language.
20
+
* An example of [embedding](src/embedded.c) the virtual machine in a C host program.
18
21
* Along with the definition of a custom-opcode handler.
19
-
* A golang-interpreter for our bytecode.
20
-
* Which is 100% complete and identical the C-based interpreter.
21
22
22
23
This particular virtual machine is intentionally simple, but despite that it is hopefully implemented in a readable fashion. ("Simplicity" here means that we support only a small number of instructions, and the registers the virtual CPU possesses can store strings and integers, but not floating-point values.)
23
24
This particular virtual machine is register-based, having ten registers which can be used to store strings or integer values.
24
25
25
26
27
+
Compilation
28
+
-----------
29
+
30
+
Because the compiler and decompiler are written in Perl they need no special
31
+
treatment.
32
+
33
+
There are two interpretters, one written in C and one in Golang. To build the
34
+
C intepreter:
35
+
36
+
$ make
37
+
38
+
This will generate `simple-vm` and `embedded` from the contents of [src/](src/).
39
+
40
+
To build the golang interpreter:
41
+
42
+
$ go build .
43
+
44
+
This will generate `simple.vm` from the file [main.go](main.go/)
45
+
46
+
26
47
Implementation Notes
27
48
--------------------
28
49
@@ -64,11 +85,11 @@ Embedding
64
85
65
86
This virtual machine is designed primarily as a learning experience, but it is built with the idea of embedding in mind.
66
87
67
-
The standard `simple-vm` binary, which will read opcodes from a file and interpret them, is less than 25k in size.
88
+
The standard `simple-vm` binary, which will read opcodes from a file and interpret them, is less than 40k in size.
68
89
69
90
Because the processing of binary opcodes is handled via a dispatch-table it is trivially possible for you to add your own application-specific opcodes to the system which would allow you to execute tiny compiled, and efficient, programs which can call back into your application when they wish.
70
91
71
-
There is an example of defining a custom opcode in the file `embedded.c`. This example defines a custom opcode `0xCD`, and executes a small program which uses that opcode for demonstration purposes:
92
+
There is an example of defining a custom opcode in the file `src/embedded.c`. This example defines a custom opcode `0xCD`, and executes a small program which uses that opcode for demonstration purposes:
72
93
73
94
$ ./embedded
74
95
[stdout] Register R01 => 16962 [Hex:4242]
@@ -190,7 +211,8 @@ The result is `main.go` which executes all of the [included example programs](ex
0 commit comments