Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.misc > #27378

SUBLEQ and Eforth

From anthk <anthk@openbsd.home>
Newsgroups comp.misc
Subject SUBLEQ and Eforth
Followup-To comp.lang.forth
Date 2025-05-14 07:49 +0000
Organization A noiseless patient Spider
Message-ID <slrn1028in7.2c2c.anthk@openbsd.home.localhost> (permalink)

Followups directed to: comp.lang.forth

Show all headers | View raw


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


Back to comp.misc | Previous | Next | Find similar


Thread

SUBLEQ and Eforth anthk <anthk@openbsd.home> - 2025-05-14 07:49 +0000

csiph-web