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
+34-23Lines changed: 34 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
+
*[simple.vm](#simplevm)
2
+
*[Compilation](#compilation)
3
+
*[Implementation Notes](#implementation-notes)
4
+
*[Embedding](#embedding)
5
+
*[Instructions](#instructions)
6
+
*[Simple Example](#simple-example)
7
+
*[Fuzz Testing](#fuzz-testing)
8
+
*[See Also](#see-also)
1
9
2
-
* Git Repository:
3
-
*http://github.com/skx/simple.vm
4
10
5
-
**NOTE**: A golang port of the virtual-machine compiler and interpreter is available from the following repository:
11
+
#simple.vm
6
12
7
-
*https://github.com/skx/go.vm
8
-
9
-
10
-
simple.vm
11
-
---------
12
-
13
-
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.
13
+
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.
14
14
15
15
In addition to the virtual machine interpreter you'll also find:
16
16
@@ -26,22 +26,19 @@ This particular virtual machine is intentionally simple, but despite that it is
26
26
This particular virtual machine is register-based, having ten registers which can be used to store strings or integer values.
27
27
28
28
29
-
Compilation
30
-
-----------
29
+
#Compilation
31
30
32
31
Because the compiler and decompiler are written in Perl they need no special
33
32
treatment.
34
33
35
34
The interpretter, written in C, can be built like so:
36
-
C intepreter:
37
35
38
36
$ make
39
37
40
38
This will generate`simple-vm` and`embedded` from the contents of[src/](src/).
41
39
42
40
43
-
Implementation Notes
44
-
--------------------
41
+
#Implementation Notes
45
42
46
43
Implementing a basic virtual machine, like this one, is a pretty well-understood problem:
47
44
@@ -76,8 +73,7 @@ After compilation is complete all the targets should have been discovered and th
76
73
>**NOTE**: The same thing applies for other instructions which handle labels, such as storing the address of a label, making a call, etc.
77
74
78
75
79
-
Embedding
80
-
---------
76
+
#Embedding
81
77
82
78
This virtual machine is designed primarily as a learning experience, but it is built with the idea of embedding in mind.
83
79
@@ -95,8 +91,7 @@ There is an example of defining a custom opcode in the file `src/embedded.c`. T
95
91
96
92
97
93
98
-
Instructions
99
-
------------
94
+
#Instructions
100
95
101
96
There are several instruction-types implemented:
102
97
@@ -163,8 +158,7 @@ The following are examples of all instructions:
163
158
ret # Return from a called-routine.
164
159
165
160
166
-
Simple Example
167
-
--------------
161
+
##Simple Example
168
162
169
163
The following program will just endlessly output a string:
170
164
@@ -196,8 +190,7 @@ If you wish to debug the execution then run:
196
190
There are more examples stored beneath the`examples/` subdirectory in this repository. The file[examples/quine.in](examples/quine.in) provides a good example of various features - it outputs its own opcodes.
197
191
198
192
199
-
Fuzz Testing
200
-
------------
193
+
#Fuzz Testing
201
194
202
195
If you wish to fuzz-test with[afl](http://lcamtuf.coredump.cx/afl/) you should find that pretty straight-forward:
203
196
@@ -225,6 +218,24 @@ Now you have `./samples/` containing only compiled programs. You can then mutat
225
218
226
219
We set the environmental variable`FUZZ` to contain`1` solely to disable the use of the`system()` function. Which might accidentally remove your home-directory, format your drive, or[send me a donation](https://steve.fi/donate/)!
227
220
221
+
#See Also
222
+
223
+
A golang port of the virtual-machine compiler and interpreter is available from the following repository:
224
+
225
+
*https://github.com/skx/go.vm
226
+
227
+
In addition to that you can find a_real_ virtual-machine inside the embedded scripting engine I wrote, also for golang. In that case a scripting language is parsed and converted into a series of bytecode instructions, which are executed by a virtual machine. Similar to this project, but the bytecode operations are more complex and high-level:
228
+
229
+
*https://github.com/skx/evalfilter
230
+
231
+
If you're interested in compilers, and interpreters, generally you might enjoy these other projects too: