· Blog  · 3 min read

How to design a virtual machine instruction set? - AQ

How to design a virtual machine instruction set? This article is a design proposal for the AQ virtual machine instruction set.

How to design a virtual machine instruction set? This article is a design proposal for the AQ virtual machine instruction set.

Introduction

How to design a virtual machine instruction set?
What instructions should be included in the instruction set?
This article is a design proposal for the AQ virtual machine instruction set.

Instructions

AQ虚拟机的指令集定义在AQ根目录的”/aqvm/interpreter/bytecode/opcode”。

您可以在Github查看本目录:https://github.com/aq-org/AQ/tree/main/aqvm/interpreter/bytecode/opcode

内含两个文件:

  1. opcode.h - AQ虚拟机指令集的枚举类型指令执行函数等声明
    源代码:https://github.com/aq-org/AQ/blob/main/aqvm/interpreter/bytecode/opcode/opcode.h
  2. opcode.c - AQ虚拟机指令集的指令执行函数的定义
    源代码:https://github.com/aq-org/AQ/blob/main/aqvm/interpreter/bytecode/opcode/opcode.c
  3. CMakeLists.txt - 编译指令集的CMake脚本
    源代码:https://github.com/aq-org/AQ/blob/main/aqvm/interpreter/bytecode/opcode/CMakeLists.txt
  4. 暂无…

由于C语言代码命名可能出现重复,因此AQ虚拟机的代码均以Aqvm开头,后加入文件路径等命名空间,用_区分前面的命名空间和后面的具体名称,例如:AqvmInterpreterBytecodeOpcode_Type

enum AqvmInterpreterBytecodeOpcode_Type {
  AqvmInterpreterBytecodeOpcodeType_NOP = 0x00,
  AqvmInterpreterBytecodeOpcodeType_LOAD,
  AqvmInterpreterBytecodeOpcodeType_STORE,
  AqvmInterpreterBytecodeOpcodeType_NEW,
  AqvmInterpreterBytecodeOpcodeType_FREE,
  AqvmInterpreterBytecodeOpcodeType_SIZE,
  AqvmInterpreterBytecodeOpcodeType_ADD,
  AqvmInterpreterBytecodeOpcodeType_SUB,
  AqvmInterpreterBytecodeOpcodeType_MUL,
  AqvmInterpreterBytecodeOpcodeType_DIV,
  AqvmInterpreterBytecodeOpcodeType_REM,
  AqvmInterpreterBytecodeOpcodeType_NEG,
  AqvmInterpreterBytecodeOpcodeType_SHL,
  AqvmInterpreterBytecodeOpcodeType_SHR,
  AqvmInterpreterBytecodeOpcodeType_SAR,
  AqvmInterpreterBytecodeOpcodeType_IF,
  AqvmInterpreterBytecodeOpcodeType_AND,
  AqvmInterpreterBytecodeOpcodeType_OR,
  AqvmInterpreterBytecodeOpcodeType_XOR,
  AqvmInterpreterBytecodeOpcodeType_CMP,
  AqvmInterpreterBytecodeOpcodeType_INVOKE,
  AqvmInterpreterBytecodeOpcodeType_RETURN,
  AqvmInterpreterBytecodeOpcodeType_GOTO,
  AqvmInterpreterBytecodeOpcodeType_THROW,
  AqvmInterpreterBytecodeOpcodeType_WIDE = 0xFF
};

以上是目前的AQ虚拟机指令集的全部指令,后续可能有所更改。
AQ虚拟机的字节码的操作符采用定长字节码,长度为1个字节。如果需要扩展操作符的长度,则采用WIDE指令。(目前且未来很长一段时间仍不需要使用)

AQ虚拟机的操作数采用变长字节码,操作数个数一般固定,但操作数的第一个字节是操作数长度,指定后续读取的操作数的长度。因此操作数的长度不固定。

以下是AQ虚拟机指令的解释:

指令名称16进制参数解释
NOP0x00空指令

Unfinished Business.

We are working hard on developing the AQ virtual machine. We would appreciate it if you could give us a star on Github. If you want to learn more or participate in the development work, please follow our official website: https://www.axa6.com and GitHub: https://github.com/aq-org/AQ.

This article is published under the AQ License: https://github.com/aq-org/AQ/blob/main/LICENSE. If needed, please adapt or reprint according to the AQ License.

Share:
Back to Blog

Related Posts

View All Posts »
Type Definition of AQ Virtual Machine - AQ

Type Definition of AQ Virtual Machine - AQ

Since different systems, hardware and other external conditions have different support and definitions for memory, it is necessary to design a unified type standard in order to make AQ virtual machine meet the requirements of cross-platform operation. This article defines and standardizes the type of AQ virtual machine to ensure that AQ virtual machines on different systems can run normally.

An excellent virtual machine memory architecture - AQ

An excellent virtual machine memory architecture - AQ

The memory architecture of a virtual machine directly affects the performance and occupancy of the virtual machine. Designing an excellent architecture can effectively improve performance and efficiency. This article will introduce the memory architecture used by the AQ virtual machine.

Announcement on multi-language support for the AQ official website - AQ

Announcement on multi-language support for the AQ official website - AQ

Due to the increasing development work of AQ, the lack of professional translators and unsatisfactory translation results, the multi-language version of the AQ official website will be temporarily suspended from real-time maintenance from today. Only English and Chinese will be supported.