Skip to content

Latest commit

 

History

History
59 lines (59 loc) · 16.4 KB

opcodes.md

File metadata and controls

59 lines (59 loc) · 16.4 KB

Pravda VM opcodes

Code Mnemonic Description
0x00 stop Stops program execution.
0x01 jump Alters program execution counter to value of first item of the stack.
0x02 jumpi If boolean value in head of stack is true then alters program execution counter to value of second item in the stack.
0x04 call Firstly, it pushes current program counter to the separate stack (so called 'call stack'). Then it alters program execution counter to the value of the first item of the stack.
0x05 ret Alters program execution counter to the value of the first item of the call stack (see CALL opcode).
0x06 pcall Takes two words by which it is followed. They are address a and the number of parameters n, respectively. Then it executes the program with the address a and passes there only $n$ top elements of the stack.
0x07 lcall Takes three words by which it is followed.They are address a, function f and the number of parameters n, respectively. Then it executes the function f of the library (which is a special form of program) with the address a and passes there only $n$ top elements of the stack.
0x08 scall Takes id of function from standard library and execute it.
0x10 pop Removes first item from the stack.
0x11 push Pushes the word following the opcode to the stack.
0x12 dup Duplicates first item of the stack.
0x13 dupn Duplicates (n+1)-th item of the stack where n is the first item in stack.
0x14 swap Swaps first two items in the stack.
0x15 swapn Swaps the second item of the stack with the (n+1)-th item of the stack where n is first item in the stack.
0x20 new Puts the data following the opcode to the heap. Pushes reference to the stack.
0x21 array_get Takes reference to array and index from the stack.Pushes to the stack a primitive at index in array corresponding by the given reference.
0x22 struct_get Takes reference to struct and key from the stack.Pushes to the stack a primitive at key in struct corresponding by the given reference.
0x24 array_mut Takes reference to array, primitive and index from the stack.Puts a primitive at index in array corresponding by the given reference.
0x25 struct_mut Takes key, primitive and reference to struct from the stack.Puts a primitive at key in struct corresponding by the given reference.
0x27 primitive_put Puts top item from the stack to the memory.Pushes reference to the stack.
0x28 primitive_get Uses top item from the stack as referenceto data in the memory of program. Pushesretrieved data to the stack.
0x29 new_array Takes type of desired array from the stack. Takes length of the desired array from the stack. Pushes reference of new array to the stack.
0x30 length Takes reference to array or Bytes or Utf8 from stack. Pushes length of given array, Bytes or Utf8 to the stack.
0x50 sput Pops first item from stack, interprets it as key. Pops second item from stack, interprets it as value. Puts (key -> value) record to program's storage.
0x51 sget Pops first item from stack, interprets it as key, retrieves corresponding record from a storage of the program and pushes the record to the stack. Otherwise throws an exception.
0x52 sdrop Pops first item from stack, interprets it as key and removes corresponding record from a storage of the program.
0x53 sexist Pops first item from stack, interprets it as key and checks existence of record correspond to the key in a storage of the program.
0x60 add Makes '+' operation on two top items from stack. Pushes result to stack.
0x61 mul Makes '*' operation on two top items from stack. Pushes result to stack.
0x62 div Makes '/' operation on two top items from stack. Pushes result to stack.
0x63 mod Makes '%' operation on two top items from stack. Pushes result to stack.
0x67 lt Checks top stack item is less than subsequent stack item. Pushes Bool result to stack.
0x68 gt Checks top stack item is greater than subsequent stack item.Pushes Bool result to stack.
0x80 not Logical NOT (negation).Pops items from stack.If it's 'true' pushes 'false' to stack.Its it's 'false' pushes 'true' to stack.
0x81 and Makes 'and' operation on two items from stack. Pushes result to stack.
0x82 or Makes 'or' operation on two items from stack. Pushes result to stack.
0x83 xor Makes 'xor' operation on two items from stack.Pushes result to stack.
0x84 eq Checks top stack item is equal to subsequent stack item. Pushes Bool result to stack.
0x90 cast Casts primitive to another type.
0x91 concat Takes two items from stack. Concatenates them and put result to stack.
0x92 slice Takes start index, end index and item from the stack. Makes slice of item and puts result to the stack.
0xA0 from Gives current executor address.
0xA1 meta
0xA2 paddr Gives current program address.
0xA5 pcreate Takes bytecode of a new program, put's it to state and returns program address.
0xA6 pupdate Takes address of a program and new bytecode. Replaces bytecode in storage. This opcode can be performed only from owner of the program
0xA7 owner Gives program owner's address. If there's no owner of the given address then the void address (32 zero bytes) is returned.
0xA8 seal Takes the address of an existing program, makes the program sealed
0xA9 throw Takes string from stack and throws an error with description as given string that stops the program.
0xAA event Takes string and arbitrary data from stack, create new event with name as given string and with given data.
0xC0 transfer Gets two parameters a and n from the stack and transfers n native coins from the executor account to the account a.
0xC1 ptransfer Gets two parameters a and n from the stack and transfers n native coins from the current program account to the account a
0xC2 balance Takes address from stack, pushes native coin balance to the stack