-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructionDecoder.sv.bak
More file actions
70 lines (62 loc) · 1.46 KB
/
Copy pathInstructionDecoder.sv.bak
File metadata and controls
70 lines (62 loc) · 1.46 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
module InstructionDecoder(
input logic[31:0] Instruction,
output logic[4:0] ReadReg1,
output logic[4:0] ReadReg2,
output logic[4:0] WriteReg,
output logic[11:0] Immediate,
output logic[6:0] OpCode);
assign OpCode = Instruction[6:0];
always_comb
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'b0110111 ||
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
//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
endmodule