esolang

SAS

Simple Assembly. Add, jump and look up, starting from nothing but powers of two and their negatives.

None1, 2024 · Turing complete: with unbounded memory · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hi

The idea

None1 made SAS, Simple Assembly, in 2024, to be easy to implement and to compile to another language. The specification says a compiler from C to it is possible. SAS is a family of dialects. In SAS-8 a word has 8 bits and there are 256 words, in SAS-16 there are 65,536 words of 16 bits, and so on. The examples and its original implementation use SAS-8, and so does this implementation. Memory is always finite, so no dialect is Turing complete.

Read the story

There are no constants. The only numbers a program has are the ones memory holds at the start. Words 0 to 7 hold 1, 2, 4 up to 128, and words 255 down to 248 hold their negatives, so word 255 is -1 and word 251 is -16. Every other word is 0. To make a character, a program adds powers of two into an empty word.

The machine

CommandDoes
ADD x yAdd word y to word x, wrapping at 256
JMP x yGo to line y if word x is not 0
REF x ySet word x to the word that word y names
OUT xPrint word x as a byte
INP xRead a byte into word x, 0 at the end of input

Lines are numbered from 0, and commands can be written in any case. The run ends when it passes the last line. A line the implementation cannot read does nothing.

Example

ADD 8 6 and ADD 8 3 add 64 and 8 to the empty word 8, which makes an H.

ADD 8 6 and ADD 8 3 add 64 and 8 to the empty word 8, which makes an H. Adding 32 and 1 turns it into an i.

A loop counts word 9 down from 3 by adding word 255, which holds -1.

Expected: !!!

The truth machine reads the input into word 8 and copies it to word 9. Then it adds -16 and -32 to word 8. A 0 is 48, so word 8 becomes 0, the digit is printed once and the run ends. A 1 leaves 1 in word 8, and the jump on the last line goes back to line 4 to print it again, forever.

Expected: 0

The Hello, World! builds each character in its own word, from word 8 to word 20. Its cat reads 0 at the end of the input, prints that 0 too, and then stops.

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from SAS

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: sas.

Command line

shib run sas -e 'INP 0
OUT 0
JMP 0 0' --input 'cat'
shib manual sas

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/sas.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org