/Stacky

Primary LanguageC#

Stacky

Stacky is a stack based interpreted language that I made in a few hours as a stepping stone in my journey to interpreters. Stacky is a simple language, only compromising of 21 instructions with 18 of them requiring no operands at all and the stack being 64 kilobytes in size.

The instructions are as follows

Instruction Description
PUSH Pushes the byte value provided into the stack
POP Pops the last value pushed from the stack
POPP Pops the last value pushed from the stack and prints out the integer
POPPC Pops the last value pushed from the stack and prints out the ASCII character
INC Pops the last value pushed from the stack, increments it, and pushes it back into the stack
DEC Pops the last value pushed from the stack, decrements it, and pushes it back into the stack
ADD Pops the last two values from the stack, adds them, and pushes the result into the stack
SUB Pops the last two values from the stack, subtracts them, and pushes the result into the stack
MUL Pops the last two values from the stack, multiplies them, and pushes the result into the stack
DIV Pops the last two values from the stack, divides them, and pushes the quotient into the stack
MOD Pops the last two values from the stack, divides them, and pushes the remainder into the stack
COPY Pops the last value from the stack and pushes it two times into the stack
CCF Clears the conditional flag
CMPE Pops the last two values from the stack and compares them, if they are equal the conditional flag is set to true
CMPL Pops the last two values from the stack and compares them, if the first value is smaller than the second the conditional flag is set to true
CMPG Pops the last two values from the stack and compares them, if the first value is bigger than the second the conditional flag is set to true
JC Jumps to the specified line if the conditional flag is set to true
JMP Jumps to the specified line
RPUSH Read a key character from the keyboard as input and pushes the value into the stack
NEWL Prints a new line character
HAULT Stops the program and sets the exit code equal to the value provided