The original SUBLEQ system, and images, came from another project of mine available at https://github.com/howerj/subleq. You can find and load newer images there, specifically here, which you should be able to load from the "image" tab. The system is self-hosting, it can be used to generate new eForth images if fed the right source code, although that is best done from the command line version and not on this web-site.
This system contains a 16-bit SUBLEQ virtual machine, that will automatically boot an eForth image, which is a variant of Forth, a stack based programming language suitable for constrained systems. What makes this system special is that SUBLEQ is a Turing complete single instruction machine, the instruction is short for "Subtract and Branch If Less Than Or Equal To Zero", it does a little more than that, but it means we do not have access to multiplication, division, addition, or even the basic bitwise operators such as AND or XOR in the base instruction set, nor calls, returns, or indirect load/stores. They all have to be synthesized.
If you feel like supporting the project you can buy a book from Amazon, available here that describes how the project works and how to port a Forth to a new platform.
Each SUBLEQ instruction consists of three arguments; 'a', 'b', 'c'. 'a' and 'b' are addresses from which arguments are loaded from, the contents of the address of 'a' are subtracted from the contents at 'b' and stored back into 'b', if the result is less than or equal to zero, then 'c' is directly jumped to, otherwise the program counter is incremented by three, moving to the next instruction.
There are two minor special cases, one for input, and one for output, if 'a' is the address -1, then a byte is loaded from input and stored into the location pointed to by 'b', if 'b' is -1 then a byte is loaded from the location pointed to by 'a' and stored to output. Input is taken from the keyboard and output is the terminal screen in the case of this emulator.
The following program, written in C, is capable of executing the same images that are used within this program, which you can click on to download:
#include <stdio.h> int main(int x,char**v){FILE*f=fopen(v[1],"r");short p=0,m[1<<16],*i=m; while(fscanf(f,"%hd",i++)>0);for(;p>=0;){int a=m[p++],b=m[p++],c=m[p++]; a<0?m[b]=getchar():b<0?putchar(m[a]):(m[b]-=m[a])<=0?p=c:0;}}
A Forth tutorial is beyond this help section. However, here are a few commands you can type into the system to get started:
words
This will print out a list of all of the built in functions defined in Forth.
2 2 + . cr
Add two numbers together, both 2, and print the result, 4 along with a newline.
: ahoy cr ." Hello, World!" ;
Define a new word (functions are called "words" in Forth) named "ahoy", which when called like so:
ahoy
Will print the standard greeting. If the Forth interpreter is happy, "ok" will be printed out after entering each line. Be careful, white-space matters a lot in Forth.
You can hit ESC to clear the screen and restart the system.
The following file contains a program that can be loaded that prints "Hi", hi.dec.
Happy hacking!
Author | Richard James Howe |
---|---|
Project | eForth running on SUBLEQ |
howe.r.j.89@gmail.com | |
Repo | https://github.com/howerj/subleq-js |
License | The Unlicense / Public Domain |