Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Instruction Set

Alex Rønne Petersen edited this page Nov 2, 2013 · 29 revisions

Miscellaneous Instructions

noop - No Operation

0x00     noop

Does nothing.

This instruction is potentially useful for marking sections of code for later processing.

copy - Copy Value

0x01     copy <tgt> <src>

Copies the value in src into tgt.

This doesn't actually perform a deep copy, just a copy of the pointer.

type - Get Type

0x02     type <tgt> <src>

Get the type of the value in src and assign it (as an atom) to tgt.

Possible values are 'nil', 'integer', 'float', 'atom', 'binary', 'address', 'function', 'tuple', 'list', 'map', 'set', and 'resource'.

Constant Load Instructions

load.nil - Load Nil

0x03     load.nil <tgt>

Loads the nil value into tgt.

load.int - Load Integer

0x04     load.int <tgt> (<integer>)

Loads the given integer into tgt.

load.flt - Load Float

0x05     load.flt <tgt> (<float>)

Loads the given float into tgt.

load.atom - Load Atom

0x06     load.atom <tgt> (<atom>)

Loads the given atom into tgt.

load.bin - Load Binary

0x07     load.bin <tgt> (<binary>)

Loads the given binary into tgt.

load.func - Load Function

0x08     load.func <tgt> <src1> <src2> <upv1> ... <upvN>

Loads a function value into tgt.

src1 must be an atom identifying the module containing the target function. src2 must be an atom identifying the function. Any following registers are upvalues.

If there are any upvalues, they will be passed as the first argument to the target function, in the form of a tuple where the elements are in the same order as they're given to this instruction.

Arithmetic/Bitwise Instructions

num.add - Arithmetic Add

0x09     num.add <tgt> <src1> <src2>

Adds the value in src2 to the value in src1 and stores the result in tgt.

src1 and src2 must be of the same type, which must be integer or float.

num.sub - Arithmetic Subtract

0x0A     num.sub <tgt> <src1> <src2>

Subtracts the value in src2 from the value in src1 and stores the result in tgt.

src1 and src2 must be of the same type, which must be integer or float.

num.mul - Arithmetic Multiply

0x0B     num.mul <tgt> <src1> <src2>

Multiplies the value in src1 with the value in src2 and stores the result in tgt.

src1 and src2 must be of the same type, which must be integer or float.

num.div - Arithmetic Divide

0x0C     num.div <tgt> <src1> <src2>

Divides the value in src1 with the value in src2 and stores the result in tgt.

src1 and src2 must be of the same type, which must be integer or float.

num.rem - Arithmetic Remainder

0x0D     num.rem <tgt> <src1> <src2>

Computes the remainder of dividing the value in src1 with the value in src2 and stores it in tgt.

src1 and src2 must be of the same type, which must be integer or float.

num.pow - Arithmetic Exponentiate

0x0E     num.pow <tgt> <src1> <src2>

Computes the value in src1 to the power of the value in src2 and stores the result in tgt.

src1 and src2 must be of the same type, which must be integer or float.

num.neg - Arithmetic Negate

0x0F     num.neg <tgt> <src>

Negates the value in src and stores the result in tgt.

src must be of type integer or float.

num.and - Bitwise AND

0x10     num.and <tgt> <src1> <src2>

Computes the bitwise AND between the values in src1 and src2 and stores the result in tgt.

src1 and src2 must be of type integer.

num.or - Bitwise OR

0x11     num.or <tgt> <src1> <src2>

Computes the bitwise OR between the values in src1 and src2 and stores the result in tgt.

src1 and src2 must be of type integer.

num.xor - Bitwise XOR

0x12     num.xor <tgt> <src1> <src2>

Computes the bitwise XOR between the values in src1 and src2 and stores the result in tgt.

src1 and src2 must be of type integer.

num.not - Bitwise Negate

0x13     num.not <tgt> <src>

Performs a bitwise negation of the value in src1 and stores the result in tgt.

src must be of type integer.

num.shl - Shift Left

0x14     num.shl <tgt> <src1> <src2>

Shifts the bits in src1 left by the amount specified in src2 and stores the result in tgt.

src1 and src2 must be of type integer.

num.shr - Shift Right

0x15     num.shr <tgt> <src1> <src2>

Shifts the bits in src1 left by the amount specified in src2 and stores the result in tgt.

src1 and src2 must be of type integer.

Relational Comparison Instructions

cmp.lt - Compare, Less

0x16     cmp.lt <tgt> <src1> <src2>

Determines whether the value in src1 is less than the value in src2. Stores the result in tgt as either the 'true' atom or the 'false' atom.

cmp.gt - Compare, Greater

0x17     cmp.gt <tgt> <src1> <src2>

Determines whether the value in src1 is greater than the value in src2. Stores the result in tgt as either the 'true' atom or the 'false' atom.

cmp.eq - Compare, Equal

0x18     cmp.eq <tgt> <src1> <src2>

Determines whether the value in src1 is equal to the value in src2. Stores the result in tgt as either the 'true' atom or the 'false' atom.

cmp.neq - Compare, Not Equal

0x19     cmp.neq <tgt> <src1> <src2>

Determines whether the value in src1 is not equal to the value in src2. Stores the result in tgt as either the 'true' atom or the 'false' atom.

cmp.lteq - Compare, Less or Equal

0x1A     cmp.lteq <tgt> <src1> <src2>

Determines whether the value in src1 is less than or equal to the value in src2. Stores the result in tgt as either the 'true' atom or the 'false' atom.

cmp.gteq - Compare, Greater or Equal

0x1B     cmp.gteq <tgt> <src1> <src2>

Determines whether the value in src1 is greater than or equal to the value in src2. Stores the result in tgt as either the 'true' atom or the 'false' atom.

Function Invocation Instructions

call.rem - Call Remote Function

0x1C     call.rem <tgt> <src1> <src2> <arg1> ... <argN>

Calls the function identified by the atom in src2 in the module identified by the atom in src1 and stores the result in tgt. All remaining registers are arguments passed to the target function.

src1 and src2 must be of type atom.

call.func - Call Function Value

0x1D     call.func <tgt> <src> <arg1> ... <argN>

Invokes the function value in src and assigns the result to tgt. All following registers are arguments to pass to the target function (after the upvalues tuple possibly passed as the first argument).

tgt must be of type atom. src must be of type function.

call.up - Native Upcall

0x1E     call.up <tgt> <src1> <src2> <arg1> ... <argN>

Calls a native function in the virtual machine or in a shared library. src1 is an atom identifying the library, e.g. '__kernel__' for functions in the VM or 'edit' for functions in the libedit.so shared library. src2 is the name of the function as an atom. The result will be stored in tgt.

src1 and src2 must be of type atom.

Tuple Manipulation Instructions

tup.make - Create Tuple

0x1F     tup.make <tgt> <elt1> ... <eltN>

tup.get - Extract Tuple Element

0x20     tup.get <tgt> <src1> <src2>

tup.set - Set Tuple Element

0x21     tup.set <tgt> <src1> <src2> <src3>

tup.del - Delete Tuple Element

0x22     tup.del <tgt> <src1> <src2>

tup.size - Get Tuple Size

0x23     tup.size <tgt> <src>

List Manipulation Instructions

list.make - Create List

0x24     list.make <tgt> <elt1> ... <eltN>

list.head - Get List Head

0x25     list.head <tgt> <src>

list.tail - Get List Tail

0x26     list.tail <tgt> <src>

list.cons - Prepend List Element

0x27     list.cons <tgt> <src1> <src2>

Map Manipulation Instructions

map.make - Create Map

0x28     map.make <tgt> <src1> ... <srcN>

map.add - Add Map Pair

0x29     map.add <tgt> <src1> <src2> <src3>

map.get - Get Map Value

0x2A     map.get <tgt> <src1> <src2>

map.del - Delete Map Key

0x2B     map.del <tgt> <src1> <src2>

map.size - Get Map Size

0x2C     map.size <tgt> <src>

msp.keys - Get Map Keys

0x2D     map.keys <tgt> <src>

map.vals - Get Map Values

0x2E     map.vals <tgt> <src>

Set Manipulation Instructions

set.make - Create Set

0x2F     set.make <tgt> <src1> ... <srcN>

set.add - Add Set Element

0x30     set.add <tgt> <src1> <src2>

set.find - Find Set Element

0x31     set.find <tgt> <src1> <src2>

set.del - Delete Set Element

0x32     set.del <tgt> <src1> <src2>

set.size - Get Set Size

0x33     set.size <tgt> <src>

set.vals - Get Set Values

0x34     set.vals <tgt> <src>

Binary Manipulation Instructions

bin.size - Get Binary Size

0x35     bin.size <tgt> <src>

bin.ebin - Encode Sub-Binary

0x36     bin.ebin <tgt> <src1> <src2> <src3>

bin.dbin - Decode Sub-Binary

0x37     bin.dbin <tgt> <src1> <src2> <src3>

bin.efs - Encode Single-Precision Float

0x38     bin.efs <tgt> <src1> <src2> <src3> (<endianness>)

bin.efd - Encode Double-Precision Float

0x39     bin.efd <tgt> <src1> <src2> <src3> (<endianness>)

bin.dfs - Decode Single-Precision Float

0x3A     bin.dfs <tgt> <src1> <src2> (<endianness>)

bin.dfd - Decode Double-Precision Float

0x3B     bin.dfd <tgt> <src1> <src2> (<endianness>)

bin.eisu - Encode Signed/Unsigned Integer

0x3C     bin.eisu <tgt> <src1> <src2> <src3> <src4> (<endianness>)

bin.dis - Decode Signed Integer

0x3D     bin.dis <tgt> <src1> <src2> <src3> (<endianness>)

bin.diu - Decode Unsigned Integer

0x3E     bin.diu <tgt> <src1> <src2> <src3> (<endianness>)

Control Flow Instructions

jump.goto - Unconditional Jump

0x3F     jump.goto (<block>)

Branches to block.

This is a terminator instruction.

jump.cond - Conditional Jump

0x40     jump.cond <src> (<block1> <block2>)

Branches to block1 if src is the 'true' atom. Otherwise, branches to block2.

This is a terminator instruction.

jump.ret - Return Value

0x41     jump.ret <src>

Returns src from the current function, transferring control to the calling function.

This is a terminator instruction.

Exception Handling Instructions

exc.new - Raise New Exception

0x42     exc.new <src>

This is a terminator instruction.

exc.get - Get Current Exception

0x43     exc.get <tgt>

exc.cont - Continue Current Exception

0x44     exc.cont

This is a terminator instruction.

Clone this wiki locally