SUBLEQ from this author it's a 16 bit virtual machine with just one instruction:
https://github.com/howerj/sublecsubtract 'a' from 'b', store it under 'b' and if it's equal or less
than 0, jump to whatever address it's being pointed at 'c'.
https://en.wikipedia.org/wiki/One-instruction_set_computerThe programmer wrote an Eforth image runnable under Subleq.
This is a whole subleq program in C:
#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;
}
}
Here's the subleq image:
https://raw.githubusercontent.com/howerj/subleq/master/subleq.decRun it as ./subleq ./subleq.dec
It you want speed, there's muxleq, which runs a lot faster than subleq.
Muxleq multiplexes instructions. Again:
https://github.com/howerj/muxleqHe created a book too, but I didn't get it yet, altough
subleq.fth and muxleq.fth are highly documented.
If you want float numbers support among other nice addons,
edit the fth files (the opt.* parts at the beginning)
and redo the image. For instance:
1 constant opt.control
will add do...loop support instead of just the eforth words
with for...next (which can be added to pforth too).
Regenerate it:
./subleq ./sublec.dec < sublec.fth > new.fth
It will last for LONG on older machines; so you maybe
ask someone to recreate the SUBLEQ image for you.
Under muxleq the generation speed will be a bit faster.
The overall speed with Muxleq under an ATOM can be taken
as a machine between a Altair 8800/S100 BUS machine with CP/M
and a boosted up Jupiter ACE. Not bad at all.
Subleq (even muxleq) emulators are very slow under Perl and
Python implementations, and the Forth one it's even slower
under PForth, but it might run fast enough under GForth or
some optimized ANS Forth for Windows:
https://github.com/howerj/subleq-forthAs a hint, I compiled C muxleq like this:
cc -o muxleq muxleq.c -ffast-math -O3 -march=atom
because the float numbers are not done with
the system math library at all.
Finally, there's an EForth+Subleq port as an OS,
from a bootable X86 image. I'd guess a PentiumIII
would be needed to get usable speeds (if not more):
https://github.com/pbrochard/subleq-eForthOSObviously it can't compare to a bare X86 bootable Forth
or CiForth under SVARDOS, but maybe running SUBLEQ
natively gets somehow to 386 or low end 486 speeds
under a Pentium III.
It's an interesting concept to get a mega-portable
Forth, because a Subleq interpreter can run everywhere
with very few lines, even AWK.
But forget about performance under pre SSE2 machines
or non C/ASM SUBLEQ virtual machines and any other
SUBLEQ implementation than MUXLEQ. SUBLEQ it's usable
but MUXLEQ with just two lines more gets a big boost.