Lasm
LASM
What is LASM?
LASM (Lua Assembly), is a low-level programming language created by User: Alx was designed to be used for a Lua/Python compiler, for an abandoned and unnamed project which compiled Lua to LASM (and assembled into LASM bytecode).
LASM VM
The LASM VM is a register machine, which also utilizes a stack incase register operations are not safe, otherwise register operations are preferred. The LASM VM has 3 registers, being A, B and C.
LASM Instruction Specifications
LASM Instruction Format
The LASM instruction size is a fixed 4 bytes / 32 bits long, with the exception of two instructions, which both have unsigned longs as as operand.
The LASM instruction layout specification is as follows:
Instruction Type A
First Bit (0) Opmode: 8 bits Operand A: 8 Bits Operand B: 8 bits Opcode: 8 bits Last Bit (32)
Instruction Type B
First Bit (0) Opmode: 8 bits Operand A: 8 Bits Operand B: 8 bits Opcode: 8 bits Extened Operand: 32 bits Last Bit (64)
The opmode specification specifies if the operands are immediate values, or register values. The opmode pairing specification is as follows:
OPMODE A SPEC | OPMODE B SPEC | VALUE (base16) |
---|---|---|
REGISTER | REGISTER | 0x11 |
REGISTER | IMMEDIATE | 0x10 |
IMMEDIATE | REGISTER | 0x01 |
IMMEDIATE | IMMEDIATE | 0x00 |
LASM Instruction Set
The following table contains the entire LASM instruction set.
Legend: ... -> N/A
Opcode | Operand A | Operand B | Opmode | Description |
---|---|---|---|---|
ADD_R | uint8_t | uint8_t | ... | Add two registers, store result in first register. |
ADD_S | ... | ... | ... | Pop two items off the stack, perform addition and push back to stack. |
AND_S | ... | ... | ... | Pop two items off the stack, perform a logical AND, push back to stack. |
BOR_S | ... | ... | ... | Pop two items off the stack, perform a logical OR and push back to stack. |
CMP | uint8_t | ... | ... | Pop two items off the stack, perform one of the following: (==, ~=, <=, >=, <, >) and push result to stack. |
CMP_R | uint8_t | uint8_t | ... | Obselete opcode. |
FASTCALL | uint8_t | ... | ... | The first calling convention, which will use registers as the arguments for the function call. (Max argc: 3) |
IMPORT | uint8_t | ... | ... | Obselete opcode. |
JMP_ULONG | uint8_t | uint32_t | ... | Absolute long jump. |
JMP_ULONG_FALSE | uint8_t | uint32_t | ... | Conditional long jump. |
MMUL_R | uint8_t | uint8_t | ... | Obselete opcode. |
MMUL_S | ... | ... | ... | Obselete opcode. |
MOD_R | uint8_t | uint8_t | ... | Perform modulo on two registers, store result in first register. |
MOD_S | ... | ... | ... | Pop two items off the stack, perform modulo and push back to stack. |
MOV | uint8_t | uint8_t | ... | Move either a register into a register, or an immediate value into a register. |
MOVG_A | uint8_t | ... | ... | Move a global (first operand pointing to the global name in the constants pool) into register A. |
MOVG_B | uint8_t | ... | ... | Move a global (first operand pointing to the global name in the constants pool) into register B. |
MOVG_C | uint8_t | ... | ... | Move a global (first operand pointing to the global name in the constants pool) into register C. |
MOVK_A | uint8_t | ... | ... | Move a constant value (first operand pointing to the constant in the constant pool) into register A. |
MOVK_B | uint8_t | ... | ... | Move a constant value (first operand pointing to the constant in the constant pool) into register B. |
MOVK_C | uint8_t | ... | ... | Move a constant value (first operand pointing to the constant in the constant pool) into register C. |
MUL_R | uint8_t | uint8_t | ... | Perform multiplication on two registers, store result in first register. |
MUL_S | ... | ... | ... | Pop two items off the stack, perform multiplication and push back to stack. |
POP | uint8_t | ... | ... | Pop the topmost stack item into a register. |
POW_R | uint8_t | uint8_t | ... | Perform exponentiation on two registers, store result in first register. |
POW_S | ... | ... | ... | Pop two items off the stack, perform exponentiation and push back to stack. |
PUSH_G | uint8_t | ... | ... | Push a global to the stack. |
PUSH_K | uint8_t | ... | ... | Push a constant to the stack. |
PUSH_R | uint8_t | ... | ... | Push register contents to the stack. |
STDCALL | uint8_t | ... | ... | The second calling convention, where the arguments are on the stack, rather than registers. |
SUB_R | uint8_t | uint8_t | ... | Perform subtraction on two registers, store result in first register. |
SUB_S | ... | ... | ... | Pop two items off the stack, perform subtraction and push back to stack. |
XOR_S | ... | ... | ... | Pop two items off the stack, perform a bitwise XOR and push back to stack. |
NOT | ... | ... | ... | Performs a logical NOT on the topmost stack item. |
RET | ... | ... | ... | Jump to offset stored in register C. Used for non-nested custom function calls. |
STORE_R | uint8_t | uint8_t | ... | Store register contents in a global pointed to by operand A. |
STORE_S | uint8_t | ... | ... | Pop an item off the stack, and store it in a global pointed to by operand A. |
JMP_INC | uint8_t | ... | ... | Incremental short absolute jump. |
JMP_INC_FALSE | uint8_t | ... | ... | Incremental short conditional jump. |
DISCARD | ... | ... | ... | Pop the topmost stack item off the stack. |
JMP_UCHAR | uint8_t | ... | ... | Stores current offset in register C, and short absolute jumps to offset in operand A. |
GETATTR_R | uint8_t | uint8_t | ... | Obselete opcode. |
JMP_DEC | uint8_t | ... | ... | Decremental absolute jump. |
JMP_UCHAR_T | uint8_t | ... | ... | Short absolute jumps to offset in operand A. Does not store previous offset. |
PUSH_LL | uint8_t | ... | ... | Obselete opcode. |
MOVLL_A | uint8_t | ... | ... | Obselete opcode. |
MOVLL_B | uint8_t | ... | ... | Obselete opcode. |
MOVLL_C | uint8_t | ... | ... | Obselete opcode. |
LASM Language Rules
LASM follows the simple language layout.
(opcode) [operand], [operand] [$opmode]
LASM Example programs
1. Hello World
; constant indexes in constants pool #const __PyGbl_print = 0 #const __Py_hello_world = 1 jmp_uchar main main: push_g __PyGbl_print $KK movk_a __Py_hello_world $KK fastcall 1 $KK
Extra
I may expand this.