· 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 »
Definición de tipo de máquina virtual AQ - AQ

Definición de tipo de máquina virtual AQ - AQ

Dado que diferentes sistemas, hardware y otras condiciones externas tienen diferentes soportes y definiciones de memoria, para que la máquina virtual AQ cumpla con los requisitos para la operación multiplataforma, es esencial diseñar un estándar de tipo unificado. Este artículo define y estandariza los tipos de máquinas virtuales AQ para garantizar que las máquinas virtuales AQ en diferentes sistemas puedan ejecutarse normalmente.

Una excelente arquitectura de memoria para máquinas virtuales - AQ

Una excelente arquitectura de memoria para máquinas virtuales - AQ

La arquitectura de memoria de la máquina virtual afecta directamente el rendimiento y la ocupación de la máquina virtual. Diseñar una arquitectura excelente puede mejorar eficazmente el rendimiento y la eficiencia. Este artículo presentará la arquitectura de memoria utilizada por las máquinas virtuales AQ.

Anuncio sobre el soporte multilingüe del sitio web oficial de AQ - AQ

Anuncio sobre el soporte multilingüe del sitio web oficial de AQ - AQ

Debido al creciente trabajo de desarrollo de AQ, la falta de traductores profesionales y los resultados de traducción insatisfactorios, la versión multilingüe del sitio web oficial de AQ suspenderá el mantenimiento en tiempo real a partir de ahora. Sólo se conserva la compatibilidad con los idiomas inglés y chino.