About

Interpreter...

FSL (Full Stack Language) is a language created with educational and challenging purposes. Inspired in Assembly languages.
This language works only with numeric stacks (not linear memory).

Made by Ivancea

Value type List

NotationInfoExample
0xNN..NHexadecimal0xD9
NN..NDecimal217
0NN..N or 0oNN..NOctal0331 or 0o331
0bNN..NBinary0b11011001
'C'Character (Unicode) ['\t' -> Tabulator; '\n' -> Line feed]'j'
"str"String of Character Future implementation"str"
sNStack N, top value (0 ≤ N ≤ Stack Count - 1)s0
cNStack N, element count (0 ≤ N ≤ Stack Count - 1)c5

Code List

Note: <value> expects a simple value, while <stack> expects a stack index

CodeInfo
//[Comment]Ignored
:<tag_name>Tag
Stack
PUSH <stack> <value>Push value or top value from second stack to first stack
POP <stack>Pop value from first stack
COPY <stack> <stack>Push top value from second stack to first stack
Instruction pointer and conditions
JMP <tag_name>Jump to label
JZ <stack> <tag_name>If Zero
JNZ <stack> <tag_name>If Non-Zero
JN <stack> <tag_name>If Negative
IO
READ <stack>Read value and push it to stack
READCHAR <stack>Read character and push it to stack
WRITE <value>Write value
WRITECHAR <value>Write character
Arithmetic
ADD <stack>Add top-value and next value from stack, pop both, and push result
SUB <stack>Substract top-value and next value from stack, pop both, and push result
MUL <stack>Multiply top-value and next value from stack, pop both, and push result
DIV <stack>Divide top-value and next value from stack, pop both, and push result
MOD <stack>Divide top-value and next value from stack, pop both, and push remainder
Call stack
CALL <tag_name>Push instruction direction to the call stack and jump to tag
RETPop the call stack and jump to that direction (If stack is empty, finishes the program

Example: Using stack as index

// Requires 21 stacks

JMP start

:inc0
PUSH 0 1
ADD 0
RET

// Initialization
:start
PUSH 0 1 // Counter

:loop1
PUSH s0 s0 // Push to pile[Counter]
PUSH s0 5
MOD s0

PUSH 0 s0 // Compare with 20 (limit)
PUSH 0 20
SUB 0
JZ 0 end1 // If is 20, ended

POP 0 // If isn't 20, increment counter
CALL inc0
JMP loop1

:end1

// Clear Counter Stack and re-initialize
POP 0
PUSH 0 1

:loop2
COPY 0 s0
WRITE s0 // Write value from stack[counter]
POP 0
WRITECHAR '\n'

PUSH 0 s0 // Compare with 20
PUSH 0 20
SUB 0
JZ 0 end2 // If is 20, ended

POP 0 // If isn't 20, increment counter
CALL inc0
JMP loop2
:end2