-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
63 lines (52 loc) · 1.41 KB
/
main.cpp
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
#include <iostream>
#include <stdint.h>
#include <tuple>
#include <fstream>
#include <string>
#include <iomanip>
#include <map>
// Global variables
int pc = 0;
int next_pc = pc + 4;
// Custom functions
#include "control_unit.h"
#include "decode.h"
#include "fetch.h"
#include "execute.h"
#include "writeback.h"
using namespace std;
int main()
{
// Get the name of the text file with instructions
string textFile = "sample_part1.txt";
// cin >> textFile;
while(true){
// FETCH
string instruction = fetch(textFile);
// If no instruction, terminate program
if(instruction == ""){
cout << endl;
cout << "program terminated:" << endl;
cout << "total execution time is " + to_string(total_clock_cycles) + " cycles" << endl;
return 0;
}
// cout << "Fetched instruction: " + instruction << endl;
cout << endl;
// DECODE
int readData1, readData2;
string destReg;
tie(destReg, readData1, readData2) = decode(instruction);
// CONTROL UNIT
int opcode = binaryToDecimal(instruction.substr(0, 6));
int funct = binaryToDecimal(instruction.substr(26, 6));
int ALUControl_result = controlUnit(opcode, funct);
// EXECUTE
int alu_result = execute(readData1, readData2, ALUControl_result);
// No WRITEBACK (J, JR, BEQ)
if(destReg == "none") {
continue;
}
// WRITEBACK
writeback(destReg, alu_result);
}
}