\cat software
Since May 2, 2003 by Huidae Cho
Stacki is a stack-based interpreter that borrows all opcodes from Whitespace. It's not another assembler for Whitespace but has an analogous syntax to that of it; each opcode and operand can be directly translated into a corresponding one of Whitespace.
Opcode | Operand | Description | Symbol | |
Stack Manupulation | push | signed-number | Push a number onto the stack | ( |
dup | Push top of stack into the stack again | = | ||
swap | Swap two topmost numbers on stack | @ | ||
discard | Pop & discard number on top of stack | ) | ||
Arithmetic | add | Pop two numbers, add, push result | + | |
sub | Pop two numbers, subtract, push result | - | ||
mul | Pop two numbers, multiply, push result | * | ||
div | Pop two numbers, integer divide, push result | / | ||
mod | Pop two numbers, modulo, push result | % | ||
Heap Access | store | Pop value and address; store value on heap at that address | [ | |
retrieve | Pop address; push onto stack the heap value at that address | ] | ||
Flow Control | label | unsigned-number | Target for other flow-control ops | : |
call | unsigned-number | Call subroutine | & | |
jump | unsigned-number | Unconditional jump | ^ | |
jz | unsigned-number | Pop top of stack; jump if it's zero | ! | |
jn | unsigned-number | Pop top of stack; jump if it's negative | ~ | |
ret | Return from subroutine | | | ||
exit | Exit interpreter | . | ||
I/O | outchar | Pop top of stack; print it as ascii character | $ | |
outnum | Pop top of stack; print it as decimal number | # | ||
readchar | Read character from stdin & push it onto stack | " | ||
readnum | Read integer from stdin & push it onto stack | ' |
(65:1=$(1+=(91-~1&123(69$.:123(65(66(67(68$$$$|Output: Input:
(65 :1 = $ (1 + = (91 - ~1 ; comment ; comment &123 (69 $ . ; comment :123 (65(66(67(68 $$$$ |Output:
(100=(0@[:1(1-=(0]+(0@[=(-1*~1(0]#Output:
(10&1#. :1=!10=(1-&1*|:10)(1|Output: