Instructions
op format: iiOOOOOO
i: if # jump.
i: if @ use indirect register.
00: nothing
01: indirect, not change register
10: indirect, increment register
11: indirect, decrement register
O: opcode
NOTE1: @arg -> support indirect
NOTE2: @ can change instruction behaviour
instruction |
id |
arg1 |
arg2 |
description |
|---|---|---|---|---|
PUSH_NULL |
0x00 |
none |
none |
push NULL value |
PUSH_NULL_N |
0x01 |
u8 |
none |
pushes N null values onto the stack |
PUSH_TRUE |
0x02 |
none |
none |
push boolean true value |
PUSH_FALSE |
0x03 |
none |
none |
push boolean false value |
PUSH_INT |
0x04 |
i32 |
none |
push integer value |
PUSH_UINT |
0x05 |
u32 |
none |
push unsigned integer value |
PUSH_0 |
0x06 |
none |
none |
push unsigned integer 0 |
PUSH_1 |
0x07 |
none |
none |
push unsigned integer 1 |
PUSH_CHAR |
0x08 |
u8 |
none |
push unsigned integer value of char |
PUSH_FLOAT |
0x09 |
f32 |
none |
push float value |
PUSH_CONST_UINT8 |
0x0a |
@u32 |
none |
push constant uint8 value from program address |
PUSH_CONST_INT8 |
0x0b |
@u32 |
none |
push constant int8 value from program address |
PUSH_CONST_UINT16 |
0x0c |
@u32 |
none |
push constant uint16 value from program address |
PUSH_CONST_INT16 |
0x0d |
@u32 |
none |
push constant int16 value from program address |
PUSH_CONST_UINT32 |
0x0e |
@u32 |
none |
push constant uint32 value from program address |
PUSH_CONST_INT32 |
0x0f |
@u32 |
none |
push constant int32 value from program address |
PUSH_CONST_FLOAT |
0x10 |
@u32 |
none |
push constant float value from program address |
PUSH_CONST_STRING |
0x11 |
@u32 |
none |
push constant string value from program address |
NEW_LIB_OBJ |
0x12 |
none |
none |
create a new heap object referenced to library. @ make static (will not be released by GC) |
NEW_HEAP_OBJECT |
0x13 |
none |
none |
make a new heap object and move first element of stack to new object. @ make static (will not be released by GC) |
PUSH_HEAP_OBJECT |
0x14 |
none |
none |
push a heap object |
FREE_HEAP_OBJECT |
0x15 |
none |
none |
mark as free a HEAP object |
NEW_ARRAY |
0x16 |
u16 |
none |
create new array in heap and fill with n elements from stack. Push heap index |
PUSH_ARRAY |
0x17 |
none |
none |
push array to stack |
GET_ARRAY_VALUE |
0x18 |
@u16 |
none |
get value from array |
SET_ARRAY_VALUE |
0x19 |
@u16 |
none |
set value on array |
ADD |
0x1a |
none |
none |
add top and second element from stack |
SUB |
0x1b |
none |
none |
subtract top and second element from stack |
MUL |
0x1c |
none |
none |
multiply top and second element from stack |
DIV |
0x1d |
none |
none |
divide top and second element from stack |
MOD |
0x1e |
none |
none |
module from top and second element of stack |
OR |
0x1f |
none |
none |
logical or from top and second element of stack |
AND |
0x20 |
none |
none |
logical and from top and second element of stack |
LT |
0x21 |
none |
none |
lesser. in mod jump if true |
LTE |
0x22 |
none |
none |
lesser or equal. in mod jump if true |
GT |
0x23 |
none |
none |
greater. in mod jump if true |
GTE |
0x24 |
none |
none |
greater or equal. in mod jump if true |
INC |
0x25 |
none |
none |
increment number (if not number do nothing). in mod jump |
DEC |
0x26 |
none |
none |
decrement number (if not number do nothing). in mod jump |
EQU |
0x27 |
none |
none |
equality. in mod jump if true |
NOT |
0x28 |
none |
none |
binary not |
SET_GLOBAL |
0x29 |
u32 |
none |
set global variable (global 0xffffffff is indirect register) |
GET_GLOBAL |
0x2a |
u32 |
none |
get global variable (global 0xffffffff is indirect register) |
GOTO |
0x2b |
@u32 |
none |
jump to pc |
GOTOZ |
0x2c |
@u32 |
none |
jump to pc if top stack is zero |
CALL |
0x2d |
u8 |
@u32 |
call function in pc with u8 stack reserved for local variables |
RETURN |
0x2e |
none |
none |
return from function without values |
RETURN_VALUE |
0x2f |
none |
none |
return from function with value |
CALL_FOREIGN |
0x30 |
u8 |
@u32 |
call foreign function |
LIB_FN |
0x31 |
u8 |
@u32 |
call library function entry for lib_obj in stack with u8 function call type and u32 arguments |
GET_LOCAL |
0x32 |
u32 |
none |
get local variable |
GET_LOCAL_FF |
0x33 |
u8 |
none |
get local variable (first 0xff) |
SET_LOCAL |
0x34 |
u32 |
none |
set local variable |
SET_LOCAL_FF |
0x35 |
u8 |
none |
set local variable (first 0xff) |
GET_RETVAL |
0x36 |
none |
none |
push in stack value from function return |
TO_TYPE |
0x37 |
u8 |
none |
convert value to new type |
DROP |
0x38 |
none |
none |
drop top of stack |
SWAP |
0x39 |
none |
none |
swap top and second element on stack |
HALT |
0x3a |
u8 |
none |
stop vm |
Instruction Description
- PUSH_NULL
Program: noneStack: ( - NULL)- PUSH_NULL_N
Program: u8 = NStack: ( - NULL ..(n) NULL)- PUSH_TRUE
Program: noneStack: ( - true )- PUSH_FALSE
Program: noneStack: ( - false )- PUSH_INT
Program: i32Stack: ( - i32 )- PUSH_UINT
Program: noneStack: ( - u32 )- PUSH_0
Program: noneStack: ( - 0 )- PUSH_1
Program: noneStack: ( - 1 )- PUSH_CHAR
Program: u8Stack: ( - u8 )- PUSH_FLOAT
Program: f32Stack: ( - f32 )- PUSH_CONST_UINT8
Create a copy of a value in program areaProgram: @u32Stack: ( - u8 )- PUSH_CONST_INT8
Create a copy of a value in program areaProgram: @u32Stack: ( - i8 )- PUSH_CONST_UINT16
Create a copy of a value in program areaProgram: @u32Stack: ( - u16 )- PUSH_CONST_INT16
Create a copy of a value in program areaProgram: @u32Stack: ( - i16 )- PUSH_CONST_UINT32
Create a copy of a value in program areaProgram: @u32Stack: ( - u32 )- PUSH_CONST_INT32
Create a copy of a value in program areaProgram: @u32Stack: ( - i32 )- PUSH_CONST_FLOAT
Create a copy of a value in program areaProgram: @u32Stack: ( - f32 )- PUSH_CONST_STRING
Create a static reference of a string in program areaProgram: @u32Stack: ( - cstr )- NEW_LIB_OBJ
Create a new heap object referenced to library. @ make static (will not be released by GC)Program: noneStack: ( lib id - )- NEW_HEAP_OBJECT
Make a new heap object and move first element of stack to new object. @ make static (will not be released by GC)Program: noneStack: ( value - )- PUSH_HEAP_OBJECT
Program: noneStack: ( id - )- FREE_HEAP_OBJECT
Program: noneStack: ( id - )- NEW_ARRAY
Create a new array in Heap, fill with stack elements and return an array objectProgram: u16Stack: ( value ...(n) value - array )- PUSH_ARRAY
Return an array object of Heap idx indexProgram: noneStack: ( idx - array )- GET_ARRAY_VALUE
Program: @u16Stack: ( - value )- SET_ARRAY_VALUE
Program: @u16Stack: ( value - )- ADD
Program: noneStack: ( value value - value )- SUB
Program: noneStack: ( value value - value )- MUL
Program: noneStack: ( value value - value )- DIV
Program: noneStack: ( value value - value )- MOD
Program: noneStack: ( value value - value )- OR
Program: noneStack: ( value value - value )- AND
Program: noneStack: ( value value - true/false )- LT
Program: #u32Stack: ( value value - true/false )- LTE
Program: #u32Stack: ( value value - true/false )- GT
Program: #u32Stack: ( value value - true/false )- GTE
Program: #u32Stack: ( value value - true/false )- INC
Program: #u32Stack: ( value - value )- DEC
Program: #u32Stack: ( value - value )- EQU
Program: #u32Stack: ( value value - true/false )- NOT
Program: noneStack: ( bool - bool )- SET_GLOBAL
Program: u32Stack: ( value - )- GET_GLOBAL
Program: u32Stack: ( - value )- GOTO
Program: @u32Stack: ( - )- GOTOZ
Program: @u32Stack: ( value - )- CALL
Program: u8: reserved space for local variables, @u32: program positionStack: ( - )- RETURN
Program: noneStack: ( - )- RETURN_VALUE
Value returned is saved on ret_val registerProgram: noneStack: ( - )- CALL_FOREIGN
Program: u8: internal function (see FFI), @u32: Foreign function idStack: ( - )- LIB_FN
Program: u8: internal function (see LIBRARIES), @u32: Library idStack: ( - )- GET_LOCAL
Program: u32: local indexStack: ( - value )- GET_LOCAL_FF
Program: u8: local indexStack: ( - value )- SET_LOCAL
Program: u32: local indexStack: ( value - )- SET_LOCAL_FF
Program: u8: local indexStack: ( value - )- GET_RETVAL
Retrieve value for return registerProgram: noneStack: ( - value )- TO_TYPE
Program: u8: new typeStack: ( value - value )- DROP
Program: noneStack: ( value - )- SWAP
Program: noneStack: ( a b - b a )- HALT
Returns a value for internal usesProgram: u8Stack: ( - )