generated from cepdnaclk/eYY-XXX-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.v
67 lines (48 loc) · 1.3 KB
/
alu.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
// 32 bit integer ALU
module alu(DATA1,DATA2,ALU_OPERATION,RESULT);
input [31:0] DATA1,DATA2;
input [3:0] ALU_OPERATION;
output reg [31:0] RESULT;
wire [31:0] subOut,addOut,andOut,orOut;
and_1 and_1(DATA1,DATA2,andOut);
sub_1 sub_1(DATA1,DATA2,subOut);
add_1 add_1(DATA1,DATA2,addOut);
or_1 or_1(DATA1,DATA2,orOut);
always @(ALU_OPERATION,subOut,addOut,andOut,orOut)
begin
case(ALU_OPERATION)
4'b0000 :RESULT=andOut;
4'b0001 :RESULT=orOut;
4'b0010 :RESULT=addOut;
4'b0110 :RESULT=subOut;
endcase
end
endmodule
module add_1(DATA1,DATA2,addOut);
input [31:0] DATA1,DATA2;
output reg [31:0] addOut;
always @(DATA1,DATA2) begin
#1 addOut = DATA1 + DATA2;
end
endmodule
module sub_1(DATA1,DATA2,subOut);
input [31:0] DATA1,DATA2;
output reg [31:0] subOut;
always @(DATA1,DATA2) begin
#2 subOut = DATA1 - DATA2;
end
endmodule
module and_1(DATA1,DATA2,andOut);
input [31:0] DATA1,DATA2;
output reg [31:0] andOut;
always @(DATA1,DATA2) begin
#1 andOut = DATA1 & DATA2;
end
endmodule
module or_1(DATA1,DATA2,orOut);
input [31:0] DATA1,DATA2;
output reg [31:0] orOut;
always @(DATA1,DATA2) begin
#1 orOut = DATA1 | DATA2;
end
endmodule