Sujet : SUBLEQ and Eforth
De : anthk (at) *nospam* openbsd.home (anthk)
Groupes : comp.miscSuivi-à : comp.lang.forthDate : 14. May 2025, 08:49:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <slrn1028in7.2c2c.anthk@openbsd.home.localhost>
User-Agent : slrn/1.0.3 (OpenBSD)
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/muxleq