-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCU.h
More file actions
57 lines (49 loc) · 1.18 KB
/
CU.h
File metadata and controls
57 lines (49 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#ifndef CU_H
#define CU_H
#include <cstdint>
#include <string>
using namespace std;
// Opcode 정의
enum Opcode {
OP_LDA = 0x0,
OP_STA = 0x1,
OP_ADD = 0x2,
OP_MUL = 0x3,
OP_DIV = 0x4,
OP_MOD = 0x5,
OP_SEA = 0xF
};
class CU {
public:
CU() {}
// 명령어 해독
Opcode decode(uint16_t instruction) {
return static_cast<Opcode>((instruction >> 12) & 0x0F);
}
// Opcode-> 문자열
string opcodeToString(Opcode op) {
switch (op) {
case OP_LDA: return "LDA";
case OP_STA: return "STA";
case OP_ADD: return "ADD";
case OP_MUL: return "MUL";
case OP_DIV: return "DIV";
case OP_MOD: return "MOD";
case OP_SEA: return "SEA";
default: return "UNKNOWN";
}
}
// 문자열-> Opcode
int stringToOpcode(const string& str) {
if (str == "LDA") return OP_LDA;
if (str == "STA") return OP_STA;
if (str == "ADD") return OP_ADD;
if (str == "MUL") return OP_MUL;
if (str == "DIV") return OP_DIV;
if (str == "MOD") return OP_MOD;
if (str == "SEA") return OP_SEA;
return -1;
}
};
#endif