Skip to content
Joachim Wester edited this page Apr 25, 2016 · 106 revisions

The Addie VM

Addie is an interpreted language for maximum portability. To be fast and efficient, we have chosen a register based virtual machine architecture.

Our fixed size bytecode instruction

Bytecode instructions are fixed in size (64 bits). The cost of having 64 bit instructions is offset by the fact that there are combinatory instructions for common operational sequences such as CALL_IF_TRUE_GOTO and MOVE_MOVE.

Registers

There are 32 general purpose 64 bit registers named r0 to r31. The register r0 is used to store return values. In addition, there are a few fixed purpose registers.

Addresses

Memory addresses occupy 24 bits and points to slots. Each slot is 64 bytes wide.

The operation layout

The OP code uses 8 bits. The structure of the remaining 56 bits depend on the OP code at hand.

63-56 55-48 47-40 39-32 31-24 23-16 15-8 7-0
A B C D E F G OP
A2 C2 D2 G OP
A3 D2 F2 OP
A4 E3 OP
A5 F2 OP
A6 G OP
A7 OP

Depending on the operation, the operands are of mixed numbers and sizes (4, 8, 16, 24, 32, 40, 48 or 56 bit). However, the operands always amount to 56 bits. The 4 bit operands are named Al/Ah, Bl/Bh, etc.

The core instruction set

As Addie is (potentially) interpreted, we will try to use as many high level OPs as possible. To make comprehension simpler, we divide the OP codes into the core set and the extended set. The OP prefix and OP suffix are for mnemonics only, the two are baked together into a single byte.

OP prefix OP suffix Description
MOVE rr
ra
ar
aa
Move data between registers and memory
LOAD Load a value into a register
CALL noarg
fixarg
vararg
Call a subroutine (by polymorphic combination or message and arguments)
GOTO Jump to an address
RETURN void,val Return from a subroutine
IF_TRUE_GOTO r0
rx
Conditional jump
IF_FALSE_GOTO r0
rx
Conditional jump
CLOSURIZE Create a closure

The extended instruction set

To make efficient use of the 64 bit instruction set, common combinations are baked into a single operation. Also, if data types are known, fixed operations can be performed.

OP prefix OP suffix Description
MOVE_MOVE rara
arar
rarr
arrr
rrrr
Move data between registers and memory.
LOAD_LOAD 48_8
32_16
24_24
Load two values into two registers
CALL_IF_TRUE_GOTO Conditional jump
CALL_IF_FALSE_GOTO Conditional jump

Static function and type instruction set

If data types and functions are statically known, fixed code operations can be performed. However, in Addie, this is not usually the case.

OP prefix OP suffix Description
FIXED_CALL noarg
fixarg
vararg
Call a fixed subroutine. This can be done is there is a guarantee of a non polymorphic implementation
IF_EQUAL_GOTO Conditional jump
IF_NOT_EQUAL_GOTO Conditional jump
IF_SMALLER_GOTO i
f
Conditional jump
IF_ATMOST_GOTO i
f
Conditional jump
IF_ATLEAST_GOTO i
f
Conditional jump
IF_LARGER_GOTO i
f
Conditional jump
INC_IF_SMALLER_GOTO i
f
Conditional jump
INC_IF_ATMOST_GOTO i
f
Conditional jump
DEC_IF_ATLEAST_GOTO i
f
Conditional jump
DEC_IF_LARGER_GOTO i
f
Conditional jump
ADD i
f
Add
SUB i
f
Subtract
MUL i
f
Multiply
INC i
f
Increment
DEC i
f
Decrement
Clone this wiki locally