· 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 الصيانة في الوقت الفعلي من الآن فصاعدًا. يتم الاحتفاظ بدعم اللغة الإنجليزية والصينية فقط.