Open redtechtiger opened 1 month ago
Each instruction is 8 bytes (64 bits) long, following this layout: | Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|---|
Purpose | Opcode | Size | Source1 High | Source1 Low | Source2 High | Source2 Low | Destination High | Destination Low |
Instructions are expected to begin at offset 0x00 (beginning of file) and to be aligned to a multiple of 8. The program counter increments by 8 after executing an instruction successfully. The last instruction is to be a halt, and following this, all variable storage is to be placed. source1
, source2
, and destination
are addresses that point to the base address of each variable. Size
is the amount of bytes to be read, starting with the base pointer.
Default endianness is now little-endian, to allow for variables to be downcasted. Instructions are no longer fixed-length but instead depend on the instructions. The pointer size (word size) is now 32 bits. The length of memory instructions should be dynamic and there are to be flags specifying the execution mode.
Layout: | Byte | 0 | 1 | 2 | .. |
---|---|---|---|---|---|
Purpose | Opcode | Pointer mode | Address size | Instruction-specific data .. |
Pointer mode: Each argument is assigned two bits, meaning that each instruction can have a maximum of four arguments. The first argument (leftmost) corresponds to bits 0 and 1 of the pointer mode field. These can be three values: 0: absolute addresses 1: pointer-to-pointer 2: immediate
Address size: Describes the length of data to be read at each one of the pointers. This is redundant if the pointer mode is pointer-to-pointer or immediate, as the pointer size is always 32 bits. Being an 8-bit (1 byte) field, this gives 2 bits per argument, i.e. three values: 0: 16 bit value 1: 32 bit value 2: 64 bit value
// Value Value Sum
add ptr_mode add_size arg_1 arg_2 arg_3
// Ptr Value
jie ptr_mode add_size arg_1 arg_2
//
hlt
Mov
Layout: opcode ptr_mode add_size arg_1 arg_2
Opcode: 0x01
Description: Sets arg_1 to arg_2
Add
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x02
Description: Adds arg_1 and arg_2 and stores in arg_3
Sub
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x03
Description: Subtracts arg_2 from arg_1 and stores in arg_3
Mul
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x04
Description: Multiplies arg_1 and arg_2 and stores in arg_3
Div
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x05
Description: Divides arg_1 by arg_2 and stores quotient in arg_3
Rem
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x06
Description: Divides arg_1 and arg_2 and stores remainder in arg_3
Equ
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x07
Description: If arg_1 is equal to arg_2, store 0x1 in arg_3, otherwise store 0x0
Cgt
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x08
Description: If arg_1 is greater than arg_2, store 0x1 in arg_3, otherwise store 0x0
Clt
Layout: opcode ptr_mode add_size arg_1 arg_2 arg_3
Opcode: 0x09
Description: If arg_1 is less than arg_2, store 0x1 in arg_3, otherwise store 0x0
Jmp
Layout: opcode ptr_mode arg_1
Opcode: 0x0A
Description: Set program counter to arg_1, effectively jumping to arg_1
Jie
Layout: opcode ptr_mode add_size arg_1 arg_2
Opcode: 0x0B
Description: Set program counter to arg_2 if arg_1 is 0x1.
Jne
Layout: opcode ptr_mode add_size arg_1 arg_2
Opcode: 0x0C
Description: Set program counter to arg_2 if arg_1 is 0x0.
PutI
Layout: opcode ptr_mode add_size arg_1
Opcode: 0x0D
Description: Print arg_1 to the console as an integer.
PutC
Layout: opcode ptr_mode add_size arg_1
Opcode: 0x0E
Description: Print arg_1 to the console as an ascii character.
Imz
Layout: opcode ptr_mode add_size arg_1
Opcode: 0x0F
Description: Invokes the image size (in bytes) from the virtual machine and stores it in arg_1
Hlt
Layout: opcode
Opcode: 0xFF
Description: Halts execution and exits the virtual machine
This is important because it will allow for changes to be made more swiftly to the project.