实现指令编解码与反汇编,冻结 disasm 格式。

- Encode.h/Encode.cpp:encode/decode 往返 + disasm 一行文本
- 指令与映像.md 新增反汇编格式表(9 种形态 + 未知操作码)
- Op.h STORE_* 注释对齐 disasm(rs, slot 寄存器在前)
This commit is contained in:
2026-08-19 14:06:20 +08:00
parent 7c855b1618
commit eba48f852e
4 changed files with 149 additions and 3 deletions
+31
View File
@@ -0,0 +1,31 @@
/**
* @file Encode.h
* @brief 指令编解码与反汇编
* @author
* @date 2026-08-19
*/
#pragma once
#include <cstddef>
#include <cstdint>
#include "isa/Instr.h"
#include "isa/Op.h"
namespace isa {
// 解码后的字段视图
struct Decoded {
Op op;
uint8_t rd;
uint8_t a;
uint8_t b;
};
// 编解码往返:encode(decode(w)) == w
Instr encode(Decoded d);
Decoded decode(Instr w);
// 反汇编一行文本,写入 out,至多 cap 字节(含 '\0')。格式见 Doc/isa/指令与映像.md。
void disasm(Instr w, char* out, size_t cap);
}
+3 -3
View File
@@ -32,11 +32,11 @@ namespace isa {
JT = 16, // JT r, offset
JF = 17, // JF r, offset
LOAD_I = 18, // LOAD_I rd, slot
STORE_Q = 19, // STORE_Q slot, rs
STORE_Q = 19, // STORE_Q rs, slot
LOAD_M = 20, // LOAD_M rd, slot
STORE_M = 21, // STORE_M slot, rs
STORE_M = 21, // STORE_M rs, slot
LOAD_GLOBAL = 22, // LOAD_GLOBAL rd, slot
STORE_GLOBAL = 23, // STORE_GLOBAL slot, rs
STORE_GLOBAL = 23, // STORE_GLOBAL rs, slot
CAL_TON = 24, // CAL_TON instance_slot
CAL_TOF = 25, // CAL_TOF instance_slot
CAL_CTU = 26, // CAL_CTU instance_slot