forked from 3820bilal/Verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALU.v
94 lines (71 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module ALU
#(
parameter WIDTH = 32,
parameter op = 2
)
(
input [op-1:0] opcode,
input [WIDTH-1:0] op1,
input [WIDTH-1:0] op2,
output reg [WIDTH-1:0] alu_out
);
wire [WIDTH-1:0] mux_4_to_1_out;
wire [WIDTH-1:0] bitwise_nand_out;
wire [WIDTH-1:0] mult_out;
wire [WIDTH-1:0] sub_out;
wire [WIDTH-1:0] add_out;
add
#(
.WIDTH (WIDTH)
)
add_inst
(
.in1 (op1),
.in2 (op2),
.out (add_out)
);
sub
#(
.WIDTH (WIDTH)
)
sub_inst
(
.in1 (op1),
.in2 (op2),
.out (sub_out)
);
mult
#(
.WIDTH (WIDTH)
)
mult_inst
(
.in1 (op1),
.in2 (op2),
.out (mult_out)
);
bitwise_nand
#(
.WIDTH (WIDTH)
)
bitwise_nand_inst
(
.in1 (op1),
.in2 (op2),
.out (bitwise_nand_out)
);
mux_4_to_1
#(
.WIDTH (WIDTH)
)
mux_4_to_1_inst
(
.i_data0 (add_out),
.i_data1 (sub_out),
.i_data2 (mult_out),
.i_data3 (bitwise_nand_out),
.i_sel (opcode),
.o_data (mux_4_to_1_out)
);
always@* alu_out = mux_4_to_1_out;
endmodule