-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode.v
85 lines (81 loc) · 1.55 KB
/
decode.v
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
module decode (
clk,
reset,
Op,
Funct,
Rd,
FlagW,
PCS,
NextPC,
RegW,
MemW,
IRWrite,
AdrSrc,
ResultSrc,
ALUSrcA,
ALUSrcB,
ImmSrc,
RegSrc,
ALUControl
);
input wire clk;
input wire reset;
input wire [1:0] Op;
input wire [5:0] Funct;
input wire [3:0] Rd;
output reg [1:0] FlagW;
output wire PCS;
output wire NextPC;
output wire RegW;
output wire MemW;
output wire IRWrite;
output wire AdrSrc;
output wire [1:0] ResultSrc;
output wire [1:0] ALUSrcA;
output wire [1:0] ALUSrcB;
output wire [1:0] ImmSrc;
output wire [1:0] RegSrc;
output reg [1:0] ALUControl;
wire Branch;
wire ALUOp;
// Main FSM
mainfsm fsm(
.clk(clk),
.reset(reset),
.Op(Op),
.Funct(Funct),
.IRWrite(IRWrite),
.AdrSrc(AdrSrc),
.ALUSrcA(ALUSrcA),
.ALUSrcB(ALUSrcB),
.ResultSrc(ResultSrc),
.NextPC(NextPC),
.RegW(RegW),
.MemW(MemW),
.Branch(Branch),
.ALUOp(ALUOp)
);
// ALU Decoder
always @(*)
if (ALUOp) begin
case (Funct[4:1])
4'b0100: ALUControl = 2'b00;
4'b0010: ALUControl = 2'b01;
4'b0000: ALUControl = 2'b10;
4'b1100: ALUControl = 2'b11;
default: ALUControl = 2'bxx;
endcase
FlagW[1] = Funct[0];
FlagW[0] = Funct[0] & ((ALUControl == 2'b00) | (ALUControl == 2'b01));
end
else begin
ALUControl = 2'b00;
FlagW = 2'b00;
end
// PC Logic
assign PCS = ((Rd == 4'b1111) & RegW) | Branch;
// Instr Decoder
assign ImmSrc = Op;
assign RegSrc[1] = Op == 2'b01; // RegSrc1 is 1 for STR, 0 for DP and the rest don't care
assign RegSrc[0] = Op == 2'b10; // RegSrc0 is only 1 for B instructions
endmodule