-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.v
86 lines (79 loc) · 1.42 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
82
83
84
85
86
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 21:27:43 12/30/2021
// Design Name:
// Module Name: alu
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module alu(
input [31:0] A,
input [31:0] B,
input [3:0] Op,
output [31:0] Out,
output reg Zero
);
reg [31:0] alu_out;
assign Out = alu_out;
integer i;
always@(*) begin
case(Op)
4'b0000:
alu_out = A + B;
4'b0001:
alu_out = A + (~B+1);
4'b0010:
alu_out = A & B;
4'b0011:
alu_out = A | B;
4'b0100:
alu_out = ~A;
4'b1000:
alu_out = {A[31], A[31:1]};
4'b1010:
alu_out = {1'b0, A[31:1]};
4'b1001:
alu_out = {A[30:0], 1'b0};
4'b1100:
alu_out = {A[30:0], A[31]};
4'b1101:
alu_out = {A[0], A[31:1]};
endcase
end
/*
for (genvar i = 0; i < 32; i=i+1) begin : setZero
assign Zero = Zero | alu_out[i];
end
assign Zero = ~Zero;
*/
always@(alu_out) begin
if (alu_out == 0) begin
Zero = 1;
end
else begin
Zero = 0;
end
end
/*
always@(alu_out) begin
case(alu_out)
32'b00000000000000000000000000000000:
Zero <= 1;
default:
Zero <= 0;
endcase
end
*/
endmodule