-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu-control.v
125 lines (101 loc) · 2.24 KB
/
alu-control.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
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
module ALUControl(alucontrol, jr, ALUOp, Funct);
input [1:0] ALUOp;
input [5:0] Funct;
output wire [3:0] alucontrol;
output wire jr;
reg [3:0] tmp;
parameter [2:0]
ADD = 2'b00,
SUB = 2'b01,
RFORMAT = 2'b10,
AND = 2'b11;
// Funct of R instructions
parameter [5:0]
ADD_FUNCT = 6'd32,
AND_FUNCT = 6'd36,
NOR_FUNCT = 6'd39,
SLT_FUNCT = 6'd42,
SLL_FUNCT = 6'd0,
JR_FUNCT = 6'd8;
// alu control signals
parameter [3:0]
ALU_ADD = 4'b0010,
ALU_SUB = 4'b0110,
ALU_SLL = 4'b0011,
ALU_AND = 4'b0000,
ALU_NOR = 4'b1100,
ALU_SLT = 4'b0111,
ALU_OR = 4'b0001;
assign #10 jr = (ALUOp == RFORMAT) && (Funct == JR_FUNCT);
assign #10 alucontrol = tmp;
always @(ALUOp or Funct) begin
case (ALUOp)
ADD: begin
tmp <= ALU_ADD;
end
SUB: begin
tmp <= ALU_SUB;
end
RFORMAT: begin
case(Funct)
ADD_FUNCT: begin
tmp <= ALU_ADD;
end
AND_FUNCT: begin
tmp <= ALU_AND;
end
NOR_FUNCT: begin
tmp <= ALU_NOR;
end
SLT_FUNCT: begin
tmp <= ALU_SLT;
end
SLL_FUNCT: begin
tmp <= ALU_SLL;
end
JR_FUNCT: begin
tmp <= 2'bxx;
end
endcase
end
AND: begin
tmp <= ALU_AND;
end
endcase
end
endmodule
module ALUControl_testbench();
reg [1:0] ALUOp;
reg [5:0] Funct;
wire [3:0] alucontrol;
wire jr;
ALUControl mALUControl(alucontrol, jr, sign, ALUOp, Funct);
parameter [2:0]
ADD = 2'b00,
SUB = 2'b01,
RFORMAT = 2'b10,
AND = 2'b11;
parameter [5:0]
ADD_FUNCT = 6'd32,
AND_FUNCT = 6'd36,
NOR_FUNCT = 6'd39,
SLT_FUNCT = 6'd42,
SLL_FUNCT = 6'd0;
initial begin
#10 ALUOp <= ADD;
#10 ALUOp <= SUB;
#10 ALUOp <= RFORMAT;
#10 Funct <= ADD_FUNCT;
#10 Funct <= AND_FUNCT;
#10 Funct <= NOR_FUNCT;
#10 Funct <= SLT_FUNCT;
#10 Funct <= SLL_FUNCT;
#10 ALUOp <= AND;
#10 $finish;
end
// for sumulation
initial begin
$dumpfile("ALUControl_testbench.vcd");
$dumpvars(0, ALUControl_testbench);
end
endmodule