-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathALUControlUnit.v
114 lines (106 loc) · 2.26 KB
/
ALUControlUnit.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// fullname : Milad Nooraei
// student number : 9935701
// Computer Architecture HomeWork 1
//////////////////////////////////////////////////////////////////////////////////
module ALUControlUnit(
input [1:0]ALUOP,
input [2:0]Function3bit,
input [6:0]Function7bit,
output reg [3:0]ALUCtr
);
always@(Function3bit, Function7bit, ALUOP)
begin
//add
if(ALUOP == 'b00 & Function3bit == 'b000 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0000;
end
//addi
else if(ALUOP == 'b01 & Function3bit == 'b000)
begin
ALUCtr = 'b0000;
end
//sub
else if(ALUOP == 'b00 & Function3bit == 'b000 & Function7bit == 'b0100000)
begin
ALUCtr = 'b0001;
end
//xor
else if(ALUOP == 'b00 & Function3bit == 'b100 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0010;
end
//xori
else if(ALUOP == 'b01 & Function3bit == 'b100)
begin
ALUCtr = 'b0010;
end
//or
else if(ALUOP == 'b00 & Function3bit == 'b110 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0011;
end
//ori
else if(ALUOP == 'b01 & Function3bit == 'b110)
begin
ALUCtr = 'b0011;
end
//and
else if(ALUOP == 'b00 & Function3bit == 'b111 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0100;
end
//andi
else if(ALUOP == 'b01 & Function3bit == 'b111)
begin
ALUCtr = 'b0100;
end
//not
else if(ALUOP == 'b00 & Function3bit == 'b011 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0101;
end
//sll
else if(ALUOP == 'b00 & Function3bit == 'b001 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0110;
end
//slli
else if(ALUOP == 'b01 & Function3bit == 'b001)
begin
ALUCtr = 'b0110;
end
//srl
else if(ALUOP == 'b00 & Function3bit == 'b101 & Function7bit == 'b0000000)
begin
ALUCtr = 'b0111;
end
//srli
else if(ALUOP == 'b01 & Function3bit == 'b101)
begin
ALUCtr = 'b0111;
end
//slt
else if(ALUOP == 'b00 & Function3bit == 'b010 & Function7bit == 'b0000000)
begin
ALUCtr = 'b1000;
end
//slti
else if(ALUOP == 'b01 & Function3bit == 'b010)
begin
ALUCtr = 'b1000;
end
//sw-lw
else if(ALUOP == 'b10)
begin
ALUCtr = 'b0000;
end
//beq
else if(ALUOP == 'b11)
begin
ALUCtr = 'b0001;
end
end
endmodule