LayerASM

From Esolang
Jump to navigation Jump to search

LayerASM is an esoteric programming language created by User:Ashtons which works with four data grid layers which contain different types of data, and supports four instructions.

Data Layers

As stated previously, there are four data layers that contain a different data type each. Each data layer is a grid of 16 by 16 cells, with each cell containing one value. This could be infinite, but computers do not have infinite amounts of memory.

Layer Data Type Bytes per Cell Total Size (Bytes)
0 ASCII Character 1 256
1 8-bit Integer 1 256
2 16-bit Integer 2 512
3 32-bit Float 4 1024

Combining the size of all layers, 2,048 bytes (2 kibibytes) of memory are used for data.

Instructions

LayerASM has only four instructions which take one or three arguments.

  • `do` - takes in an operation to perform on the current data cell. Operations are increment, decrement, double, halve, input, and output
  • `mv` - takes in a direction and moves the data cell pointer one cell in that direction
  • `jp` - takes a direction, a condition, and a label and jumps to the label if the current cell and cell in the given direction meet the given condition
  • `cl` - takes a layer ID and changes the current data layer to the given layer. Each layer has a different data cell pointer.

Binary Representation

LayerASM code has to be compiled into bytecode. Each instruction has a different bytecode representation. While `jp` uses two bytes, the rest of the instructions can be represented using only one byte.

'do' is represented in bytecode as 00101???, where the ?s are the bits for the operation argument. Each operation is represented as follows:

  • increment is 000
  • decrement is 001
  • double is 010
  • halve is 011
  • input is 100
  • output is 101

'mv' is represented in bytecode as 01??0010, where the ?s are the bits for the direction argument. Up is 00, Down is 01, Right is 10, and Left is 11.

'jp' also has a direction argument, but it also has a condition argument and a label argument. Rather than writing out the label in ASCII in the bytecode, the label is turned into an 8-bit signed displacement. As such, 'jp' is represented as 10??1??? ????????, first two ?s are direction, next 3 ?s are condition, and the rest of the ?s is the displacement byte. The conditions are represented as so:

  • always jump is 000
  • jump if equal or zero is 001
  • jump if not equal or not zero is 010
  • jump if less than is 011
  • jump is more than is 100

'cl' is represented in bytecode as 11??1001, where the ?s are the layer ID.

Argument Notation

The official notation for different arguments are as follows.

Operations:

  • increment is `in`
  • decrement is `de`
  • double is `db`
  • halve is `hl`
  • input is `i`
  • output is `o`

Directions:

  • up
  • down is `dn`
  • right is `rt`
  • left is `lf`

Conditions:

  • jump always is `a`
  • jump if equal or zero is `z`
  • jump if not equal or not zero is `nz`
  • jump if less than is `lt`
  • jump if greater than is `gt`

Software

Bytecode Compiler: To Be Coded

Bytecode Interpreter: To Be Coded