View unanswered posts | View active topics It is currently Tue Mar 19, 2024 2:02 am



Reply to topic  [ 1 post ] 
 STABLE - a fast and small VM interpreter 
Author Message

Joined: Mon Aug 14, 2017 8:23 am
Posts: 157
This project drew some attention on my Facebook Forth Programming Group.

https://w3group.de/stable.html

Written in C by Hungarian Sandor Schneider, its a VM interpreter for a stack machine that uses single character ascii codes as its instruction set.

Although highly influenced by Forth, it is not Forth as most people here would recognise. Best to call it "Forth-like" or Forth Lite, as it shares a similar status to Forth, that tiny BASIC has to full BASIC.

It could be said that STABLE has some similarities to Peter Grogono's MOUSE programming language, first developed for the PDP-8 for electronic music generation on early synthesisers.
They are both stack based and use single characters to represent instructions, though MOUSE does not have the familiar stack manipulation operations - a feature of Forth.

Although the instructions are single characters, most of the usual Forth primitives are there

Arithmetic/Logic ADD, SUB, INC, DEC, NEGate, MUL, DIV, MOD, AND, OR, NOT (notably no XOR)
Comparisons GT >, LT <, EQ = for conditional execution of code
Stack Manipulation DUP, DROP, SWAP, OVER
Memory FETCH, STORE
Input/Output DOT (print stack), EMIT, KEY
Looping BEGIN....END LOOP

There is also a means to create your own (26) definitions, using A-Z much the same as colon definitions in Forth.

One notable feature is that there are up to 26 variables using a-z. These can be used for indirect pointers to memory and the INC, DEC commands allow them to easily index into an array in memory.

The interpreter is very compact, one version is only 47 lines of C code, but later versions are about 200 lines.

The interesting thing is that the choice of instructions is virtually identical to those that you would find on a Minimum Instruction Set Computer or MISC - such as some of the designs by Charles Moore.

So if you are interested in simulating MISC devices, designing a stack machine core for an FPGA or taking on the OPC challenge, then STABLE is a good starting place for ideas.

STABLE has been reverse engineered by Chris Curl and appears in his S4 Github repository.

https://github.com/CCurl/S4

Although the STABLE instruction set and the use of single characters can appear very terse, a small utility program could be used to expand the single character instructions out to the more familiar Forth words shown above.

For those used to working with microcontrollers at an assembly level, the use of a concise symbolic language might prove to be a useful alternative. The source code will certainly be more concise.

Referring back to MISC designs, the STABLE instruction set could be reduced to 5-bit tokens and use one of the token packing schemes proposed by the likes of Moore's F21 or Green Arrays F18 cpu.

STABLE is not only a very compact VM interpreter, but it is quite fast - even when written in C.

I am currently testing one version on a Teensy 4.0 - which is an ARM Cortex M7 core clocked at 600MHz. This version allows 32-bit arithmetic and up to 1Mbyte of memory.

Time for 1 billion empty loops: 20 seconds (50 million loops per second)
Time for 32-bit ADD or SUB 108nS (9.26 million additions per second)


Thu Apr 01, 2021 12:21 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software