· 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 »
Определение типа виртуальной машины AQ — AQ

Определение типа виртуальной машины AQ — AQ

Поскольку разные системы, оборудование и другие внешние условия имеют разную поддержку и определения памяти, чтобы виртуальная машина AQ соответствовала требованиям кроссплатформенной работы, важно разработать единый стандарт типа. В этой статье определяются и стандартизируются типы виртуальных машин AQ, чтобы гарантировать нормальную работу виртуальных машин AQ в разных системах.

Отличная архитектура памяти виртуальной машины - AQ

Отличная архитектура памяти виртуальной машины - AQ

Архитектура памяти виртуальной машины напрямую влияет на производительность и заполняемость виртуальной машины. Разработка превосходной архитектуры может эффективно повысить производительность и эффективность. В этой статье будет представлена ​​архитектура памяти, используемая виртуальными машинами AQ.

Объявление о мультиязычной поддержке официального сайта AQ - AQ

Объявление о мультиязычной поддержке официального сайта AQ - AQ

Из-за растущей работы по развитию AQ, нехватки профессиональных переводчиков и неудовлетворительных результатов перевода, многоязычная версия официального сайта AQ с этого момента будет приостановлена ​​в режиме реального времени. Сохраняется только поддержка английского и китайского языков.