Xihcute

From Esolang
Jump to navigation Jump to search

Xihcute is an esoteric programming language created by user:ds84182, and inspired by Enema. It is self modifying, stack based, and most likely Turing complete.

Instructions

Name Usage Description
push pc p [pc] Pushes the program counter to the stack
jump [pc] j Jumps to the position on the stack
jumprel [relative pc] r Does a relative jump from the value on the stack
branchrel [cond] [relative pc] b Does a relative jump from the value on the stack if t != 0
skip k Skips the next instruction
memset [addr] [val] s Sets the memory location addr to val
memget [addr] g [val] Pushes the value at memory location addr to the stack
add [a] [b] + [c] Adds a and b together and pushes the result onto the stack
sub [a] [b] - [c] Subtracts a and b and pushes the result onto the stack
mul [a] [b] * [c] Multiplies a and b and pushes the result onto the stack
div [a] [b] / [c] Divides a and b and pushes the result onto the stack
mod [a] [b] % [c] Modulos a and b and pushes the result onto the stack
and [a] [b] & [c] Computes the bitwise and of a and b and pushes the result onto stack
or [c] Computes the bitwise or of a and b and pushes the result onto stack
breakpoint ` Issues a breakpoint in the program (makes the program drop to a debug console, if available)
dump $ Dumps the current execution state into the console
output [v] o Outputs the ascii value of o to stdout
output number [v] n Outputs the numeric value of v to stdout
comment { [comment] } Puts a comment in the code, comments are not stripped.
dup [v] m [v] [v] Duplicates the first value on stack
swap [a] [b] h [b] [a] Swaps the first two values on the stack
pop [v] l Pops the first value off the stack and discards it
push sp u [sp] Puts the value of the stack pointer onto stack
pop sp [sp] q Sets the stack pointer to sp
read dp t [v] Reads a value from the memory location pointed by the data pointer. Then the data pointer is incremented.
write dp [v] v Writes the value into the memory location pointed by the data pointer. Then the data pointer is incremented.
pop dp [dp] y Sets the value of the data pointer
push dp c [dp] Puts the value of the data pointer onto stack
equals [a] [b] = [c] If a and b are equal, 1 is pushed, else 0
not equals [a] [b] ! [b] If a does not equal b, 1 is pushed, else 0
greaterthan [a] [b] > [c] If a is greater than b, 1 is pushed, else 0
lessthan [a] [b] = [c] If a is less than b, 1 is pushed, else 0
end e Ends the program. NUL (\0) does the same thing
nop (whitespace) The instruction does nothing
0,1,2,3,4,5,6,7,8,9 Pushes a single digit
char [any byte] \[any byte] Pushes the ascii representation of the character on stack. (UTF8 characters may or may not push multiple stack values... Happy emoji constants day!)

Preprocessor Instructions

org [n]

This is currently the only preprocessor instruction. This will relocate code at another location specified by [n].

Examples

Hello, World!

92*1+ytotm0!52*~bleHello, World!

The hello world program above reads a zero terminated string starting at the end of the program. You can replace the message with whatever you desire.

It works by first setting the data pointer to address 19. Then, in a loop, it reads the data at the data pointer, outputs it, and jumps back to the top of the loop if the next character is not null. If the next character is null, the program exits.

Cheating Quine

0ytm2b1k03bo2je

Completely length independent quine. It reads characters until it hits a null byte.

It starts by setting the data pointer to 0 then entering a loop. In the loop it reads the value at the data pointer, exits the loop if the value is zero, else outputs it and jumps back to the top of the loop.

99 Bottles of Beer

[ TODO: Rewrite this for Xihcute Hard Mode ]

99*99++0f
mmn55*4*ywtmmiloe
mn55*4*84*+ywtmmiloe
55*6*2+ywtmmiloe
m1-n55*7*91++ywtmmiloell
;e
[org 100] bottles of beer on the wall,
[org 132] bottles of beer.
[org 152]Take one down, pass it around,
[org 185] bottles of beer on the wall.


I could not make a full one because of Xihcute's limited space. I only had 256 bytes of ram to work with, so I could only do so much. I could rewrite my implementation and spec again to be 16 bit, but that may come in the near future.

ROT13

[ TODO: Rewrite this for Xihcute Hard Mode ]

dAmmm\A1->h\Z1+<&2bC;BedB\A-94++94+2*%\A+edC\a-94++94+2*%\a+e55*8*yw tmi;Ammi oe[org 200]UryybJbeyq!

It works, but if non ROT13 characters are in the stream, they get garbled.

Implementation

Currently the author has an implementation of Xihcute in Lua, running on his IRC bot. It will be released on Github as soon as I test all the operations.