-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstruction_Memory.cpp
More file actions
70 lines (49 loc) · 1.93 KB
/
Instruction_Memory.cpp
File metadata and controls
70 lines (49 loc) · 1.93 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
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Instruction_Memory.h"
Instruction_Memory::Instruction_Memory() {
}
Instruction_Memory::~Instruction_Memory() {
}
void Instruction_Memory::seperate(string tmp)
{
if (tmp.length() != DATA_BITS)return;
this->op = tmp.substr(0, 6);
this->rs = tmp.substr(6, 5);
this->rt = tmp.substr(11, 5);
int o = 0;
for (int i = 0; i < 6; i++) { o += pow(2, 5 - i) * (op.at(i)-'0'); }
this->add = tmp.substr(16);
this->rd = tmp.substr(16, 5);
this->shamt = tmp.substr(21, 5);
this->ff = tmp.substr(26);
// if (o == 35 || o == 43) {
// this->add = tmp.substr(16);
// this->rd = tmp.substr(16, 5);
// this->shamt = tmp.substr(21, 5);
// this->ff = tmp.substr(26);
// }
// else {
// this->rd = tmp.substr(16, 5);
// this->shamt = tmp.substr(21, 5);
// this->ff = tmp.substr(26);
// }
}
void Instruction_Memory::print(){
cout << "op : " << this->op << " , rs : " << this->rs << " , rt : " << this->rt
<< " , rd : " << this->rd << " , shamt : " << this->shamt << " , fuction_field : " << this->ff << endl << "addres : " << this->add << endl;;
}
string Instruction_Memory::get_op() { return this->op; }
string Instruction_Memory::get_rs() { return this->rs; }
string Instruction_Memory::get_rt() { return this->rt; }
string Instruction_Memory::get_rd() { return this->rd; }
string Instruction_Memory::get_shamt(){ return this->shamt; }
string Instruction_Memory::get_ff() { return this->ff; }
string Instruction_Memory::getAddress()
{
control_class.sign_extend(add, address);
add = control_class.bool_to_str(address, DATA_BITS);
return add;
}
void Instruction_Memory::set_rs(string rs_c) { this->rs = rs_c; }
void Instruction_Memory::set_rt(string rt_c) { this->rt = rt_c; }
void Instruction_Memory::set_rd(string rd_c) { this->rd = rd_c; }
void Instruction_Memory::set_control(Control& ctr) { this->control_class = ctr; }