-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu_inner_modules.v
136 lines (88 loc) · 2.19 KB
/
alu_inner_modules.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
module ADD_4bit(
input [3:0] a,
input [3:0] b,
output [7:0] out,
output cout
);
wire [2:0] carry;
ADDER_4bit adder_4bit0(a, b, 0, out[3:0], cout);
assign out[7:4] = { 4{out[3]} };
endmodule
module SUB_4bit(
input [3:0] a,
input [3:0] b,
output [7:0] out,
output cout
);
ADDER_4bit adder_4bit0(a, ~b, 1, out[3:0], cout);
assign out[7:4] = { 4{out[3]} };
endmodule
module OR_4bit(
input [3:0] a,
input [3:0] b,
output [7:0] out
);
assign out[3:0] = a | b;
assign out[7:4] = 4'b0000;
endmodule
module XOR_4bit(
input [3:0] a,
input [3:0] b,
output [7:0] out
);
assign out[3:0] = a ^ b;
assign out[7:4] = 4'b0000;
endmodule
module AND_4bit(
input [3:0] a,
input [3:0] b,
output [7:0] out
);
assign out[3:0] = a & b;
assign out[7:4] = 4'b0000;
endmodule
module MUL_4bit(
input [3:0] a,
input [3:0] b,
output [7:0] out
);
wire [7:0] extended_a = {4'h0, a};
wire [7:0] ab0;
wire [7:0] ab1;
wire [7:0] ab2;
wire [7:0] ab3;
SWITCH_8bit sw0(extended_a , b[0], ab0);
SWITCH_8bit sw1(extended_a << 1, b[1], ab1);
SWITCH_8bit sw2(extended_a << 2, b[2], ab2);
SWITCH_8bit sw3(extended_a << 3, b[3], ab3);
wire [7:0] ab01;
wire [7:0] ab23;
ADDER_8bit adder_8bit0(ab0, ab1, ab01);
ADDER_8bit adder_8bit1(ab2, ab3, ab23);
ADDER_8bit adder_8bit2(ab01, ab23, out);
endmodule
module MUX_8_1(
input [7:0] in0,
input [7:0] in1,
input [7:0] in2,
input [7:0] in3,
input [7:0] in4,
input [7:0] in5,
input [7:0] in6,
input [7:0] in7,
input [2:0] c,
output [7:0] out
);
wire [7:0] m;
DEC_3_8 dec(c, m);
wire [7:0] x [0:7];
SWITCH_8bit sw0(in0, m[0], x[0]);
SWITCH_8bit sw1(in1, m[1], x[1]);
SWITCH_8bit sw2(in2, m[2], x[2]);
SWITCH_8bit sw3(in3, m[3], x[3]);
SWITCH_8bit sw4(in4, m[4], x[4]);
SWITCH_8bit sw5(in5, m[5], x[5]);
SWITCH_8bit sw6(in6, m[6], x[6]);
SWITCH_8bit sw7(in7, m[7], x[7]);
assign out = x[0] | x[1] | x[2] | x[3] | x[4] | x[5] | x[6] | x[7];
endmodule