-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (43 loc) · 1.29 KB
/
main.cpp
File metadata and controls
50 lines (43 loc) · 1.29 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 <bits/stdc++.h>
#include "pipeline.cpp"
using namespace std;
string dummy_instruction = "00100111111100000000000000000000";
int main(){
vector<string> v;
Assembler* assembler = new Assembler();
Fetch* f=new Fetch();
v=assembler->generateMachineCode();
f->setMachineCode(v);
ControlUnit* c=new ControlUnit();
ALU* alu=new ALU();
Cache* cache=new Cache();
Memory* mem=new Memory(*cache);
Writeback* wb=new Writeback();
int cnt=0, meaningfulInstructions=0;
bool skip=0;
while(!finito){
if(!skip){
f->setInstruction(v);
if(f->getIn(0,32) != dummy_instruction) meaningfulInstructions++; //if not addi $31,$0,0 which is our dummy instruction
}
c->takeFromRegister();
alu->takeFromRegister();
mem->takeFromRegister();
wb->takeFromRegister();
if(skip){
skip=0;
cnt++;
}
f->giveToRegister();
c->giveToRegister();
alu->giveToRegister();
mem->giveToRegister();
wb->writeBackToRegister();
if(cnt<1)skip=stall(f);
else cnt=0;
Clock++;
}
out<<"Clocks: "<<Clock<<"\n";
out<<"CPI : "<<setprecision(10)<<float(float(Clock)/meaningfulInstructions)<<"\n";
return 0;
}