esolang

Xihcute

A stack machine in 256 bytes, where the program reads its own text as data.

ds84182, 2014 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello, World!

The idea

ds84182 made Xihcute in 2014, inspired by Enema. The program is loaded into 256 bytes of memory, and the machine runs it from there one byte at a time. Code and data share that memory, so a program can read its own bytes, print them and write over them. Every value is a byte.

Read the story

The Hello World keeps its message right after its last instruction and prints memory until it meets a zero byte. Its quine does the same from address 0, so it prints itself whatever it says.

The machine

InstructionDoes
0 to 9, \xPush a digit, push the byte x
+ - * / % &Arithmetic on the top two values
= ! > <Compare the top two, push 1 or 0
m h lDuplicate, swap, pop
u qPush the stack height, set it
p jPush the address after it, jump to an address
r bJump by a distance, always or when a condition is not 0
kSkip the next instruction
g sLoad from memory, store into memory
y cSet the data pointer, push it
t vRead or write at the data pointer, then move it on by one
o nPrint a byte, print a number
eEnd, as a zero byte does

A pipe is bitwise or, and { starts a comment that stays in memory and is jumped over. The table on the specification leaves out ~, which its Hello World needs; this implementation makes it negate. Values wrap at 256, so a distance of 246 is a jump of 10 back.

Example

92*1+y points the data pointer at address 19, where the message starts.
Expected: 0ytm2b1k03bo2je

92*1+y points the data pointer at address 19, where the message starts. t reads a byte and o prints it. Then tm0! reads the next byte and tests it against 0, and 52*~b jumps 10 back to the o while it is not 0. At the zero byte after the message l drops it and e ends the run.

The 99 bottles and ROT13 use letters it never defines, such as f, w and d, and stop with an error.

Further

Ideas it shows

Self-modifying

Stack-based

Write your own in Run Convert a program from Xihcute

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run xihcute -e '0ytm2b1k03bo2je'
shib manual xihcute

Source

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

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

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