-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.v
81 lines (76 loc) · 1.9 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer: Omar Amr
//
// Create Date: 02/10/2023 09:00:49 PM
// Design Name: Arithmatic-Logic Unit
// Module Name: alu
// Project Name: ALU
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module alu
#(
parameter WIDTH = 32
)(
input wire [2:0] sel,
input wire [WIDTH-1: 0] A, B,
output reg [WIDTH-1: 0] alu_result,
output reg sign_flag, zero_flag
);
localparam [2:0] ADD = 3'b000,
SHL = 3'b001,
SUB = 3'b010,
NOTUSED = 3'b011,
XOR = 3'b100,
SHR = 3'b101,
OR = 3'b110,
AND = 3'b111;
always @ (*)
begin
alu_result = {WIDTH{1'b0}};
case(sel)
ADD:
begin
alu_result = A + B;
end
SHL:
begin
alu_result = A << B;
end
SUB:
begin
alu_result = A - B;
end
XOR:
begin
alu_result = A ^ B;
end
SHR:
begin
alu_result = A >> B;
end
OR:
begin
alu_result = A | B;
end
AND:
begin
alu_result = A & B;
end
default:
alu_result = {WIDTH{1'b0}};
endcase
zero_flag = ~(| alu_result);
sign_flag = alu_result[WIDTH-1];
end
endmodule