Files
MyLittleCPU/instruction.h

33 lines
872 B
C
Raw Normal View History

2026-07-14 19:54:23 +10:00
#pragma once
#include <cstdint>
#include <unordered_map>
#include <vector>
enum class InstType : uint8_t {
MOV, MVI, ADD, SUB, LOAD, STORE, AND, OR, XOR, SHF, JMP, JIZ, CALL, RET, SYS, HLT
};
enum class OperandType {
ImmNone, Imm4, Imm8
};
using BytecodeInstruction = uint16_t;
static std::unordered_map<InstType, std::vector<OperandType>> instructionOperandTypes = {
{InstType::MOV, {OperandType::Imm4, OperandType::Imm4, OperandType::Imm4}}
};
struct Instruction {
InstType opcode = InstType::MOV;
uint16_t arg1 = 0;
uint16_t arg2 = 0;
uint16_t arg3 = 0;
BytecodeInstruction asBytecodeInstruction() const;
Instruction() = default;
Instruction(InstType opcode, uint16_t arg1, uint16_t arg2, uint16_t arg3)
: opcode(opcode), arg1(arg1), arg2(arg2), arg3(arg3) {}
Instruction(BytecodeInstruction bytecodeInst);
};