-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.v
56 lines (52 loc) · 1.12 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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 19:11:44 05/24/2016
// Design Name:
// Module Name: alu
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module alu(
input signed [31:0]a,
input signed [31:0]b,
input [3:0]aluc,
output [31:0]r,
output z
);
wire [31:0]d_and = a & b;
wire [31:0]d_or = a | b;
wire [31:0]d_xor = a ^ b;
wire [31:0]d_lui = {b[15:0], 15'b0};
wire [31:0]d_and_or = aluc[2] ? d_or : d_and;
wire [31:0]d_xor_lui = aluc[2] ? d_lui : d_xor;
wire [31:0]d_as, d_sh;
assign d_as = aluc[2] ? (a - b) : (a + b);
shift shifter(
.d(b),
.sa(a[4:0]),
.right(aluc[2]),
.arith(aluc[3]),
.sh(d_sh)
);
mux4 mux4_EXE(
.mux4_0(d_as),
.mux4_1(d_and_or),
.mux4_2(d_xor_lui),
.mux4_3(d_sh),
.select4(aluc[1:0]),
.mux4_out(r)
);
assign z = ~|r;
endmodule