SUBLEQ and Eforth

Liste des GroupesRevenir à c misc 
Sujet : SUBLEQ and Eforth
De : anthk (at) *nospam* openbsd.home (anthk)
Groupes : comp.misc
Suivi-à : comp.lang.forth
Date : 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/sublec

subtract '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_computer

The 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.dec

Run 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




Date Sujet#  Auteur
14 May 25 o SUBLEQ and Eforth1anthk

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal