-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplier_4bit.v
More file actions
51 lines (34 loc) · 850 Bytes
/
multiplier_4bit.v
File metadata and controls
51 lines (34 loc) · 850 Bytes
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
module multiplier_4bit(out, a, b);
output reg [7:0] out;
input [3:0] a, b;
/*
wire [7:0] temp1;
integer i;
assign temp1 = b;
always @(a or b) begin
out = 8'd0;
for(i = 0; i<4; i=i+1) begin
out = out + (temp1<<i)*a[i];
end
end
*/
/* Dataflow */
wire [7:0] pro1, pro2, pro3, pro4;
assign out = 8'd0;
assign pro1 = {4'b0000, a[3]&b[0], a[2]&b[0], a[1]&b[0], a[0]&b[0]};
assign pro2 = {3'b000, a[3]&b[1], a[2]&b[1], a[1]&b[1], a[0]&b[1], 1'b0};
assign pro3 = {2'b00, a[3]&b[2], a[2]&b[2], a[1]&b[2], a[0]&b[2], 2'b00};
assign pro4 = {1'b0, a[3]&b[3], a[2]&b[3], a[1]&b[3], a[0]&b[3], 3'b000};
assign out = pro1 + pro2 + pro3 + pro4;
endmodule
/*
module testbench;
reg [3:0] a, b;
wire [7:0] out;
multiplier_4bit mul(out, a, b);
initial begin
a = 4'b1011;
b = 4'b0110;
end
endmodule
*/