Dequeasm

From Esolang
Jump to navigation Jump to search

Dequeasm (Pronounced "The Chasm" because it will suck you into a pit of despair) is a deque based programming language with syntax similar to assembly. It is recommended to have some familiarity with deque, dueue or stack data structures as well as basic to intermediate understanding of assembly.

Syntax Concepts

Dequeasm is very similar to assembly in syntax and tries to mirror it as closely as possible. One major change however is that All commands are assumed to operate on the RIGHT of the stack unless they are proceeded by a ~ to indicate operation on the right end of the queue. An intuitive way to understand this is the following example:

~PSH 1 ; pushes 1 onto the left of the stack
PSH~ 1 ; pushes 1 onto the right of the stack

Dequasm also supports parameters for pushing

PSH 2, 5    ; expected -> [2, 5]    Uses PSH to push two values by separating them with ','
~SUB        ; expected -> [3]       SUB with the '~' marker operates on the back of the stack.

This code will push both 2 and 5 at the same time
Another similarity to assembly is Dequeasm's label system:
LabelName: is used like in assembly to define the start of a label. The address can then pushed back onto the queue with ~PSH LabelName and then jumped to with any jump operation such as ~JMP NOTE: All arithmetic instructions will be executed as suchSUB will execute in the following order: POP a; POP b; PUSH b - a;

Commands

Queue Manipulation Operations
Command Name Action
POP Pop Remove element from the dequeue at the specified end of the stack.
PSH Push Insert element to the deque at the specified end of the stack.
DUP Duplicate Duplicate the value on the specified end of the stack.
SWP Swap Swap the positions of the top two values on the stack.
OVR Over Put the second item on the specified end stack on the end of the stack WITHOUT removing it from its original location.
RCW Rotate Clockwise Rotate the top three items on the stack clockwise on.
RCC Rotate Counter Clockwise Rotate the top three items on the stack counter clockwise.
ROL Roll Move the value from the specified end of the queue to the other end.
SHL Shift left Shifts the entire queue left
SHR Shift Right Shifts the entire queue right
Arithmetic Operations
Command Name Action
ADD Addition Pushes the sum of the top two values from the end of the stack to the same end.
SUB Subtraction Pushes the difference of the top two values from the end of the stack to the same end.
MUL Multiplication Pushes the product of the top two values from the end of the stack to the same end.
DIV Integer Division Pushes the quotient the top two values from the end of the stack to the same end.
MOD Modulation Pushes the remainder the top two values from the end of the stack to the same end.
Logical Operations (0 as False, Non 0 as True)
Command Name Action
AND Logical And Pushes the result of a logical AND of the first two values from the end of the stack to the same end.
OR Logical Or Pushes the result of a logical OR of the first two values from the end of the stack to the same end.
XOR Logical Exclusive Or Pushes the result of a logical XOR of the first two values from the end of the stack to the same end.
Flow Control
Command Name Action
JNZ Jump if non-zero Sets the instruction pointer to the address on the end of the stack if the second value before it is non-zero
JMP Unconditional Jump Sets the instruction pointer to the address on the end of the stack.
JE Jump if equal Sets the instruction pointer to the address on the end of the stack if the two values before it are equal
JG Jump if greater than Sets the instruction pointer to the address on the end of the stack if the second value is greater than the third.
JL Jump if less than Sets the instruction pointer to the address on the end of the stack if the second value is less than the third.
JGE Jump if greater than or equal to Sets the instruction pointer to the address on the end of the stack if the second value is greater than or equal to the third.
JLE Jump if less than or equal to Sets the instruction pointer to the address on the end of the stack if the second value is less than or equal to the third.
Input / Output
Command Name Action
OUT Output Pops a value from an end of the stack and prints it's ascii code as a character.
INP Input Takes a singular character as input and pushes it's ascii value to the specified end of the stack.
HLT Halt Breaks the program

Implementations