-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructionDecoder.sv
More file actions
131 lines (117 loc) · 2.88 KB
/
Copy pathInstructionDecoder.sv
File metadata and controls
131 lines (117 loc) · 2.88 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
module InstructionDecoder(
input logic[31:0] Instruction,
output logic[4:0] ReadReg1,
output logic[4:0] ReadReg2,
output logic[4:0] WriteReg,
output logic[31:0] Immediate,
output logic[6:0] OpCode);
assign OpCode = Instruction[6:0];
always_comb //ReadReg 1&2 and WriteReg
begin
ReadReg1=0;
ReadReg2=0;
WriteReg=0;
//R-Type Instructions
if(Instruction[6:0]==7'b0110011)
begin
ReadReg1=Instruction[19:15];
ReadReg2=Instruction[24:20];
WriteReg=Instruction[11:7];
end
//R&I-Type Instructions
if(Instruction[6:0]==7'b0010011)
begin
if(Instruction[14:12]==3'b001) //It's R-Type Instruction
begin
ReadReg1=Instruction[19:15];
ReadReg2=Instruction[24:20];
WriteReg=Instruction[11:7];
end else begin //It's I-Type Instruction
ReadReg1=Instruction[19:15];
ReadReg2=0;
WriteReg=Instruction[11:7];
end
end
//I-Type Instructions
if(Instruction[6:0]==7'b1110011 ||
Instruction[6:0]==7'b0010111 ||
Instruction[6:0]==7'b0000011 ||
Instruction[6:0]==7'b1100111)
begin
ReadReg1=Instruction[19:15];
ReadReg2=0;
WriteReg=Instruction[11:7];
end
if(Instruction[6:0]==7'b0110111)
begin
ReadReg1=0;
ReadReg2=0;
WriteReg=Instruction[11:7];
end
//S-Type Instructions
if(Instruction[6:0]==7'b0100011 ||
Instruction[6:0]==7'b1100011)
begin
ReadReg1=Instruction[19:15];
ReadReg2=Instruction[24:20];
WriteReg=0;
end
//U-Type Instructions
if(Instruction[6:0]==7'b1101111)
begin
ReadReg1=0;
ReadReg2=0;
WriteReg=Instruction[11:7];
end
end
always_comb //Immidiate formation
begin
Immediate={32{1'b0}};
//I-Immediate
if(Instruction[6:0]==7'b1110011 ||
Instruction[6:0]==7'b0010011 ||
Instruction[6:0]==7'b0000011 ||
Instruction[6:0]==7'b1100111)
begin
Immediate[31:11]={21{Instruction[31]}};
Immediate[10:5]=Instruction[30:25];
Immediate[4:1]=Instruction[24:21];
Immediate[0]=Instruction[20];
end
//S-Immediate
if(Instruction[6:0]==7'b0100011)
begin
Immediate[31:11]={21{Instruction[31]}};
Immediate[10:5]=Instruction[30:25];
Immediate[4:1]=Instruction[11:8];
Immediate[0]=Instruction[7];
end
//B-Immediate
if(Instruction[6:0]==7'b1100011)
begin
Immediate[31:12]={20{Instruction[31]}};
Immediate[11]=Instruction[7];
Immediate[10:5]=Instruction[30:25];
Immediate[4:1]=Instruction[11:8];
Immediate[0]=0;
end
//U-Immediate
if(Instruction[6:0]==7'b0110111 ||
Instruction[6:0]==7'b0010111)
begin
Immediate[31]=Instruction[31];
Immediate[30:12]=Instruction[30:12];
Immediate[11:0]=12'b000000000000;
end
//J-Immediate
if(Instruction[6:0]==7'b1101111)
begin
Immediate[31:20]={12{Instruction[31]}};
Immediate[19:12]=Instruction[19:12];
Immediate[11]=Instruction[20];
Immediate[10:5]=Instruction[30:25];
Immediate[4:1]=Instruction[24:21];
Immediate[0]=1'b0;
end
end
endmodule