-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplier.v
89 lines (84 loc) · 1.77 KB
/
multiplier.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: UdS
// Engineer: Peter Jose
//
// Create Date: 09:35:46 09/08/2022
// Design Name: multiplication
// Module Name: multiplier
// Project Name: multiplication
// Target Devices: Basys2
// Tool versions: ISE P.68d
// Description: Multiplies two numbers
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module multiplier#(parameter M = 3,
parameter N = 4)(
input clk, // clock
input [M-1:0] multiplier, // multiplier with M as width
input [N-1:0] multiplicand, // multiplicand with N as width
input en, // enable to start
output reg done, // done flag
output reg [M+N-1:0] product // product output
);
reg[N:0] index;
reg[M+N-1:0] product_out;
initial
begin
product <= 0;
done <= 0;
index <= 0;
product_out <= 0;
end
always @ (posedge clk)
begin
if (en == 1)
if (done == 0)
if(index < N)
begin
if(multiplicand[index] ==1'b1)
product_out = product_out + (multiplier << index);
index <= index+1;
end
else
begin
done <=1;
index <= 0;
product <= product_out;
end
else
begin
done <= 0;
index <= 0;
product <= 0;
end
end
// One clock cycle
// always @ (posedge clk)
// begin
// if (en == 1)
// begin
// if (done == 0)
// begin
// for ( index = 0; index < 4 ; index = index +1) begin
// if(multiplicand[index] ==1'b1)
// begin
// product = product + (multiplier << index);
// end
// end
// done <=1;
// end
// end
// else
// begin
// product <= 0;
// done <= 0;
// end
// end
endmodule