-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisassembler.cpp
More file actions
31 lines (27 loc) · 1.02 KB
/
Copy pathdisassembler.cpp
File metadata and controls
31 lines (27 loc) · 1.02 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
#include "disassembler.h"
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>
const std::unordered_map<uint8_t, std::string>
two_b_completed_disassembler::bin_to_opcodes = {
{0b00, "LDST"}, {0b01, "NAND"}, {0b10, "CMP"}, {0b11, "ADDEQ"}};
two_b_completed_disassembler::two_b_completed_disassembler() {}
// The issue is there is no way of discerning data from instruction so I
// interpret all data as instruction
std::vector<std::string>
two_b_completed_disassembler::disassemble(std::vector<uint8_t> &machine_code) {
std::vector<std::string> program;
for (int line = 0; line < machine_code.size(); line++) {
std::string instruction = "";
instruction += bin_to_opcodes.at(machine_code[line] >> 6);
instruction += ' ';
uint8_t rx = machine_code[line] >> 3 & 0x7;
instruction += 'R' + std::to_string(rx);
uint8_t ry = machine_code[line] & 0x7;
instruction += ',';
instruction += " R" + std::to_string(ry);
program.push_back(instruction);
}
return program;
}