-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDisassembler.cpp
More file actions
executable file
·51 lines (44 loc) · 1.25 KB
/
Disassembler.cpp
File metadata and controls
executable file
·51 lines (44 loc) · 1.25 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
#include <iomanip>
#include <iostream>
#include "Disassembler.hpp"
#include "Instructions.hpp"
using namespace std;
Disassembler::Disassembler(const vector<char>& program)
: _program(program)
{
}
void Disassembler::Print() const
{
for (vector<char>::const_iterator it = _program.begin(); it != _program.end(); ++it)
{
cout << hex << setfill('0') << setw(4) << uppercase
<< distance(_program.begin(), it) << ":\t";
if (*it < NUM_INSTRUCTIONS)
{
string inst = InstStrings[*it];
cout << inst;
char suffix = inst[inst.size()-1];
if (suffix == '1')
{
cout << "\t0x" << hex << setfill('0') << setw(2)
<< unsigned(*(++it));
}
else if (suffix == '2')
{
cout << "\t0x" << hex << setw(4) << setfill('0')
<< ((unsigned(*(++it) << 8) | unsigned(*(++it))));
}
}
else
{
cout << "0x" << hex << unsigned(*it);
/*
cout << "\t" << dec << unsigned(*it);
if (isgraph(*it))
{
cout << "\t" << *it;
}*/
}
cout << '\n';
}
}