---
# System prepended metadata

title: modl

---

# modl


## VM design

### instruction set

<!-- Why does load have 2 parameters? -->
<!-- not load, it'll have one -->
<!-- Wouldn't it be better to call it STORE? -->

<!-- what is S suffix* ?  suffix, right short? short as in type? why would we need that. ok i guess-->

Legend:
   + R-* Registers
   + ALN Alignment margin (To align the instruction for 8 bit)

|   OC   | INSTRUCTION |           PARAMETERS           | DESCRIPTION                                                                                                                   |
|:------:|:-----------:|:------------------------------:| ----------------------------------------------------------------------------------------------------------------------------- |
|   00   |     NOP     |                                | Does nothing                                                                                                                  |
|   01   |     RET     |                                | Returns control to the caller                                                                                                 |
|   02   |     MOV     |          DST/4 SRC/4           | Moves data from one register to another                                                                                       |
|   03   |    LOADR    |        R-DST/4 R-ADR/4         | Loads data into the specified register                                                                                        |
|   04   |    LOADC    |      ALN/4 R-DST/4 DATA/?      | Loads small data into specified register (data in SEBO format)                                                                |
|   05   |   TBLGETR   |        R-TBL/4 R-NAME/4        | Loads table's entry into the table's register. Name is specified in register R-NAME.                                          |
|   06   |   TBLGETC   |      ALN/4 R-TBL/4 NAME/?      | Loads table's entry into the table's register. Name is specified after the command (name in SEBO format).                     |
|   ~~   |    SETR     |        R-DST/4 R-VAL/4         | REMOVED!!! Rewrites value in the target register (changes value instead of reference)                                         |
|   ~~   |    SETC     |      ALN/4 R-DST/4 DATA/?      | REMOVED!!! Rewrites value in the target register (changes value instead of reference). data is provided as SEBO               |
|   09   |    CALLR    |         R-AC/4 R-FUN/4         | Calls function loaded into the register R-FUN, passes the amount of paramters in R-AC                                         |
|   0A   |    CALLC    |            OFFS/64             | Calls function by the relative signed 64 bit offset                                                                           |
|   0B   |    LOADD    |     ALN/4 R-DST/4 OFFS/64      | Parses and loads data taken from specified place (by using relative offset)                                                   |
|   0C   |   LOADFUN   |     ALN/4 R-DST/4 OFFS/64      | Loads new function into the specified register. OFFS - is a relative offset between current ip and a function's first command |
|   0D   |     ROL     |          R-L/4 R-R/4           | Bitwise shift left R-L << R-R                                                                                                 |
|   0E   |     ROR     |          R-L/4 R-R/4           | Bitwise shift right R-L >> R-R                                                                                                |
|   0F   |     IDIV    |          R-L/4 R-R/4           | Integer divide registers, result in R-L                                                                                       |
|   10   |     ADD     |          R-L/4 R-R/4           | Add up both registers, result in R-L                                                                                          |
|   11   |     SUB     |          R-L/4 R-R/4           | Subtract registers, result in R-L                                                                                             |
|   12   |     MUL     |          R-L/4 R-R/4           | Multiply registers, result in R-L                                                                                             |
|   13   |     DIV     |          R-L/4 R-R/4           | Divide registers, result in R-L                                                                                               |
|   14   |     MOD     |          R-L/4 R-R/4           | Get modulo (division rest) registers, result in R-L                                                                           |
|   15   |     AND     |          R-L/4 R-R/4           | Perform bitwise and on registers, result in R-L                                                                               |
|   16   |     OR      |          R-L/4 R-R/4           | Perform bitwise or on registers, result in R-L                                                                                |
|   17   |     XOR     |          R-L/4 R-R/4           | Perform bitwise xor on registers, result in R-L                                                                               |
|   18   |    NAND     |          R-L/4 R-R/4           | Perform invert bitwise and on registers, result in R-L                                                                        |
|   19   |     NOR     |          R-L/4 R-R/4           | Perform invert bitwise or on registers, result in R-L                                                                         |
|   1A   |    NXOR     |          R-L/4 R-R/4           | Perform invert bitwise xor on registers, result in R-L                                                                        |
|   1F   |     JMP     |            OFFS/64             | Long jump instruction (4 byte signed integer argument -- relative jump position)                                              |
| 20..29 |    CMPcc    |          R-L/4 R-R/4           | Compares objects in specified registers. suffixes:(EQ, NEQ, LT, NLT, GT, NGT, LE, NLE, GE, NGE)                               |
|   30   |     JCF     |     ALN/4 R-COND/4 OFFS/64     | if value is falsy in the specified register (condition register is placed in least significant bits)                          |
|   31   |     JCT     |     ALN/4 R-COND/4 OFFS/64     | Jumps if value is truthy in the specified register (condition register is placed in least significant bits)                   |
|   40   |     POP     |         ALN/4 R-DEST/4         | Perform POP on stack into register R-DEST                                                                                     |
|   41   |    PUSH     |         ALN/4 R-SRC/4          | Perform PUSH on stack from register R-SRC                                                                                     |
|   42   |   TBLPUSH   |        R-TBL/4 R-VAL/4         | Perform PUSH into the table from register R-VAL                                                                               |
|   43   |   TBLSETR   | R-TBL/4 R-NAME/4 ALN/4 R-VAL/4 | Sets table's values from register R-VAL                                                                                       |
|   44   |   TBLSETC   |    R-TBL/4 R-NAME/4  DATA/?    | Sets table's values from inline data in SEO format                                                                            |
|   45   |   ENVGETR   |        R-DST/4 R-NAME/4        | Searches environment for a variable with a given name (taken from R-NAME)                                                     |
|   46   |   ENVGETC   |      ALN/4 R-DST/4 NAME/?      | Searches environment for a variable with a given name (taken from NAME in SEBO format)                                        |
|   47   |   ENVSETR   |        R-NAME/4 R-VAL/4        | Sets the value of an environmental variable with a given name                                                                 |
|   48   |   ENVSETC   |      ALN/4 R-VAL/4 NAME/?      | Sets environment for a variable with a given name (taken from NAME in SEBO format)                                            |
|   49   |   ENVUPKR   |       R-ARRV/4 R-ARRK/4        | Unpack values from R-ARRV into environment under names in R-ARRK (invalid identifiers shall be omitted)                       |
|   4A   |   ENVUPKC   |      ALN/4 R-ARR/4 KEYS/?      | Unpack values from R-ARR into environment under names in KEYS (in SEBO format) (invalid identifiers shall be omitted)         |
|   4B   |   ENVUPKT   |         ALN/4 R-TBL/4          | Unpack values from R-TBL as a table, into environment under its keys as identifiers (invalid identifiers shall be omitted)    |
|   4C   |   ENVPUSH   |                                | Push env                                                                                                                      | 
|   4D   |   ENVPOP    |                                | Pop env                                                                                                                       |
|   50   |     NOT     |       ALN/4 R-OPERAND/4        | Perform logical "NOT" operation                                                                                               |
|   51   |     INV     |       ALN/4 R-OPERAND/4        | Perform bitwise "NOT" operation                                                                                               |
|   52   |     LEN     |       ALN/4 R-OPERAND/4        | Perform length operation, returning length of the string, table (where length indicates last index of pushed value)           |
|   53   |     NEG     |       ALN/4 R-OPERAND/4        | Negate                                                                                                                        |


### bytecode

```
here
```
