I tried recreating the assembly language; here is the documentation. The language works on an output stack. Create a 'code.txt' in the same folder or change the file path in the code to another txt file to use and run the language. Watch this video for a complete explanation
- Python compiler
- Subscribed to my channel ;)
Keyword [variable name] [value]
The language is Space-Sensitive and Case-Sensitive, so use only one space for each token and also capital letters for Keywords
Keywords are mnemonics used to perform certain operations
Following are the keywords with the definitions
PUSH [variable/value]
Appends the given data value to the stack
SET [variable] [value]
Updates the value of the given variable with the given new value
JUMP [line index]
Jumps the code execution to the given line index
The line index starts with 0
JUMPIF [line index]
Jumps the code execution to the given line index if the last inputted value of the stack is 1
The line index starts with 0
PRN
Prints the last inputted value of the stack
VAR [var name] [initialization value]
Creates a new variable with the given name
INPUT [var name]
Takes user input and stores it in the given variable
ADD
Adds the last two inputted values of the stack and pushes the result back into the stack
SUB
Substracts the last two inputted values of the stack and pushes the result back into the stack
MULTI
Multiply the last two inputted values of the stack and pushes the result back into the stack
DIV
Divides the last two inputted values of the stack and pushes the result back into the stack
MOD
Gets the modulus of the last two inputted values of the stack and pushes the result back into the stack
INC [var name]
Increases the value of var by 1
DEC [var name]
Decreases the value of var by 1
LT
Gets the last two inputted values of the stack and if last < second last value, pushes 1 to the stack else pushes 0
LTE
Gets the last two inputted values of the stack and if last <= second last value, pushes 1 to the stack else pushes 0
GT
Gets the last two inputted values of the stack and if last > second last value, pushes 1 to the stack else pushes 0
GTE
Gets the last two inputted values of the stack and if last >= second last value, pushes 1 to the stack else pushes 0
STOP
Ends the code execution
PUSH PULL
Not a keyword but used to return the last inputted value of the stack and used as a variable
Loops can be coded using LOOP keyword and the premade CTR variable
SET CTR [Number of iterations -1]
[codelines]
...
LOOP [line index to loop to each time]
LOOP is executed until CTR is 0
Uses the same keywords PUSH[] VAR[] SET[]
These keywords work the same just uses and extra []
Uses the premade SI variable to point to the index of the current array
SET SI [value]
PUSH[] [array name]
-- Pushes the value of array name at the SI index
Uses the CALL keyword with a variable to store the index of the line where CALL is used
VAR [line var] [line index]
CALL [line var] [line index of the 1st line of function]
[codelines]
...
STOP
[First line of function]
[function codelines]
...
JUMP [line var]
Thanks for checking it out
If you find any Issue create a issue in the repo, I will fix it
HAPPY CODING :)