Skip to content

Instantly share code, notes, and snippets.

@hUwUtao
Last active November 2, 2023 12:58
Show Gist options
  • Save hUwUtao/38393807731afceeee03c91f73dc06e1 to your computer and use it in GitHub Desktop.
Save hUwUtao/38393807731afceeee03c91f73dc06e1 to your computer and use it in GitHub Desktop.
The FISL Assembly

FISL - Flat Instruction Set List

  • Is a language to define the list of instruction. It is extendable, but not dedicated to any platform
  • Is a language that similar to LISP, the way it describe the code and operators through syntax
  • It is compact to read. Trailing tab/space is optional. Syntax is limited to ASCII, even better, it is only [a-zA-Z0-9.\s]
  • It's design is not intended for automatic/smart expression parsing.
  • It is a scalar, but neat to see that any object is statically typed, allocated and limbo between manual and automated memory management. Worse: it ignore any stack dead, because it is synchronous by the design
  • Define a number, then the binary, so it is the ROM

Brief summary

FISL aim is to make a 1-dimension memory allocated in a "make sense" way.

Without further explain, move to the first ever example for a clear view.

fn fibonacci n
stack
stack
stack
.n
.1
call le
call if
.n
else
stack
stack
.n
call fibonacci
stack
stack
.n
2
call sub
call fibonacci
call add
return

It is obviously too flat, at it is, so lets add some trailing tab to demonstrate the way it work.

fn fibonacci n
stack
	stack
		stack
			.n
			.1
		call le
	call if
		.n
	else
		stack
			stack
				.n
			call fibonacci
			stack
				stack
					.n
					2
				call sub
			call fibonacci
		call plus
		
return

as it equivalent to this piece of code in C

unsigned int fibonacci(unsigned int n) {
	return (n <= 1) ? n : fibonacci(n) + fibonacci(n - 2);
}

Structs

Struct is the most important feature in all language. (Un)Fortunately, FISL is an assembly-kind language, there is no gun-foot-proof.

struct VecD {
	int a;
	int b;
}

struct VecD v = {0xAB, 0xCD}; //important part
stack
.171
.205
ref v

In our FISL code, v is a reference/pointer to our heap (the size in memory is static, maybe generated upon compilation). Basically, if the code somewhere, refer to the stack definition, it will set the size for it automatically.

[Memory] So what are stacks

FISLstack, is a memory structure to store one or many value, with fixed size allocation

When you define a stack, the function of its instruction must allocate the memory piece on its own segment.

Here is our memory, for a program that create a stack of 1 bit during runtime (casually 1 byte on a normal scenario)

fn a
stack
.0b1
ref a
## breakpoint

fn b
stack
.0b01
ref b
call a

# |0|1|1
# |	  | a's memory
# |___ b's memory

[Memory] free()

Function heap is died once the function is done. So threadding task must use it own heap.

Guarantee pointer segfault

Copy copy copy. We might even have buffer for that. A guarantee that:

  • Function allocation always larger than its own return value.
  • Its value is not a pointer How
  • Just push the value inward (by default)
  • Or keep anything (fake that value is size-padded) --Dewp (end with pad)

Array

what else it could be, obviously a fixed array. It is also a stack. what we need is a way to allocate it more convenient and sizewise, and read it.

stack ## bake 8 * 12
# bake it just compile time evaluator (math only maybe)
ref a

read it

stack
.a
.5
.8
call se # seg is an operator lmfao

stack
.a
call si

So a few conclusion

  • function is a list of instruction
  • heap is a dynamic size, bytewise, 1 dimension array.
  • stack is a memory allocated structure. It is rather a memory definition and compactor than a real structure to programming.
  • ref is a memory address to stack heap. while stack is not represent a value in that allocation, even another stack store is as memory, low level function, and the processor itself should resolve it on run (more segfault risk).
  • so afterall, everything is a stack, a sized allocation in memory, its instance or reference anywhere else is a reference "pointer"

Part 2: The syntax

Basic control flow syntax

  • fn: define the function
  • stack (stackdef): start define the stack
  • ref: stop define the stack
  • call: is ref, then invoke a call to a function with that stack reference. The return value will be put in current stackdef
  • fi: is a control flow that is stopping current if not fast-forward without extra operation?
  • else: call if with reused not stack (must call fi first)

Operators (it is all functions)

  • or: (Incremental 0cf)
  • and
  • if: ?
  • eq: Equal
  • se: Stack segmentation
  • xo: XOR
  • sl/sr: Shift left/right
  • mk: Mask

Number specific

  • ne: Not equal
  • gr/ge: Greater/Greater or equal
  • ls/le: Less/Less or equal
  • si: Stack size

Algebra (number) specific operators (also functions), libstd thing

  • pow: Power
  • srt: Square root 2
  • nst: Square root n
  • cei: Ceil
  • flo: Floor
  • clp: Clamp
  • [a](sin|cos|tan|cot): Geometry thing

Defined std size (for languages implementation)

  • c: 8
  • s: 16
  • i: 32
  • l: 64
  • u(c|s|i|l): as (c|s|i|l) interpreted as unsigned
  • sx: as ui (system type for size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment