-
Notifications
You must be signed in to change notification settings - Fork 0
/
Processor.java
75 lines (46 loc) · 1.61 KB
/
Processor.java
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
71
72
73
74
75
public class Processor{
private static int mux(int value1, int value2, boolean getSecond) {
if(getSecond) {
return value2;
}
return value1;
}
public static void main(String[] args) {
String ins;
String opcode;
String funct;
int rs,rt,rd,imm;
int alu_out = 0;
boolean alu_zero = false;
int data_out = 0;
int regData1 = 0;
int regData2 = 0;
int write_data;
ALU alu= new ALU();
ALUControl aluControl=new ALUControl();
InstructionMemory insMem=new InstructionMemory();
int numOfInstructions=insMem.getNumOfInstructions();
InstructionDecode decode;
RegisterFile register=new RegisterFile();
MemoryFile memory=new MemoryFile();
for(int i=0;i<numOfInstructions;i++){
ins=insMem.InstructionFetch();
//System.out.println(ins);
decode=new InstructionDecode(ins);
opcode=decode.getOpcode();
Control control = new Control(decode);
//reg
rd = mux(decode.getReadRegister2(), decode.getWriteRegister(), control.isRegDist());
register.setRegisters(decode.getReadRegister1(),decode.getReadRegister2(),rd);
regData1=register.readData1();
regData2=register.readData2();
System.out.println("rs="+decode.getReadRegister1()+" "+"rt="+decode.getReadRegister2()+" "+"rd="+rd+" "+"readData1="+regData1+" "+"readData2="+regData2);
//memory
data_out = memory.cycle(alu_out, decode.getReadRegister2(), control.isMemRead(), control.isMemWrite());
//System.out.println(data_out);
//Writeback
write_data = mux(alu_out, data_out, control.isMemtoReg());
register.write(control.isRegWrite(), rd);
}
}
}