-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALU.v
56 lines (46 loc) · 1.36 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
`ifndef MODULE_ALU
`define MODULE_ALU
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2018/11/12 22:41:18
// Design Name:
// Module Name: ALU
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module ALU(ALU_in1, ALU_in2, ALU_control, Zero, result);
input [31:0] ALU_in1, ALU_in2;
input [3:0] ALU_control;
output Zero;
output [31:0] result;
reg [31:0] result;
assign Zero = (result == 0);
initial begin
result = 0;
end
always @ (ALU_in1 or ALU_in2 or ALU_control)
begin
if (ALU_control == 4'b0000) result = ALU_in1 & ALU_in2;
else if (ALU_control == 4'b0001) result = ALU_in1 | ALU_in2;
else if (ALU_control == 4'b0010) result = ALU_in1 + ALU_in2;
else if (ALU_control == 4'b0110) result = ALU_in1 - ALU_in2;
else if (ALU_control == 4'b0111) begin
if (ALU_in1 < ALU_in2) result = 1;
else result = 0;
end
else if (ALU_control == 4'b1100) result = ~ (ALU_in1 | ALU_in2);
end
endmodule
`endif