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
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
| Instruction | Does |
|---|---|
0 to 9, \x | Push a digit, push the byte x |
+ - * / % & | Arithmetic on the top two values |
= ! > < | Compare the top two, push 1 or 0 |
m h l | Duplicate, swap, pop |
u q | Push the stack height, set it |
p j | Push the address after it, jump to an address |
r b | Jump by a distance, always or when a condition is not 0 |
k | Skip the next instruction |
g s | Load from memory, store into memory |
y c | Set the data pointer, push it |
t v | Read or write at the data pointer, then move it on by one |
o n | Print a byte, print a number |
e | End, 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.
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
See also
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 xihcuteSource
- 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