Subleq and other OISC languages

Subleq, like many of the esoteric languages is not the fastest language, nor is it easiest to program in.

(Two glaringly obvious massive understatements of the Century).

However, a Subleq interpreter can be written in a few lines of C, or, at most a couple of hundred bytes of assembly language.

Once you have your interpreter in place, you have created a very minimal VM, regardless of what CPU you are coding for.

So provided you have coded your interpreter, a Subleq program for a Z80, will run exactly the same on a 6502, 6809, RCA 1802, PIC, MSP 430, x86 or whatever you might have available.

My friend Richard J. Howe, has coded up eForth into a Subleq image. It’s about 6500 16-bit words.*

I have adapted his interpreter code so that it can be hosted on any of the larger memory dev-boards supported by the Arduino IDE,

So far candidates have been a Pi Pico (RP2040), an STM32H743 Nucleo and a Teensy 4.1.

I am currently writing a subleq interpreter in Z80 assembly for my RC2014 and my Agon Light 2.

With a Subleq interpreter installed, plus the subleq image, which defines eForth, you will have a self-hosting Forth system.

No other tools required.

So, despite it’s minimalism, Subleq can get you up and running in Forth, regardless of your CPU.

  • With the slightly modified Muxleq instruction, eForth will compile down to approximately 5K words of Muxleq code - and be significantly faster than Subleq.

It will even run on a CPU composed of fewer than 180 transistors and some parallel memory.

My interest in this was stimulated by this article in Nature, (Sept 2013) which describes an experimental CPU made from carbon nanotube FETs (CN-FETs), at Stanford University.

Remarkably they made a functional cpu from just 178 CN-FETs, plus conventional external RAM devices.

They used a variant of subleq, called subneg, which has the advantage of not requiring a program counter. This is a major saving in transistors.

They also proved that the MIPS instruction set could be compliled from the subneg instruction, so the experimental cpu could execute MIPS code - albeit extremely slowly.

1 Like

There is the Dawn operating system for 64 bit Subleq.

The MCPU has four instructions (NOR, ADD, STA, JCC) which allows its programs to be more compact than Subleq (but still about 10 times larger than “normal” processors) but their hardware implementations are roughly the same size. The original MCPU is only 8 bits with 6 bit addresses, but it is trivial to expand that to 16 bits with 14 bit addresses or even larger.

It would be interesting to plot a graph with the number of instructions in the x axis and code size and performance in the y axis to see what the sweet spot is. These simple processors can run at far higher clock speeds that most processors (if memory can keep up), which partly compensates their higher instruction count.

1 Like

Is this the same Dawn-OS from the same guy who runs the Collapse-OS project.

He is in Canada, but the subleq guy is Hungarian.

I wonder whether I am confusing 2 different projects?

I was amazed at how easy it was to get subleq, and muxleq running eForth on an RP2040, using an interpreter in a few lines of C.

I would be happy with it in FORTRAN II. A few lines of C today is not the same as it was in the 70’s. The PDP-8 instruction set is the best example a practical small instruction set, ignoring the small word length.That might be good cpu to plot as reference model.

While good in theory, bit shifting and no self modifying code also is important,
Ben,
PS. Everything today is in C++, and I cannot make heads or tails of the code,