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
| module multiplier(
input [7:0] a,
input [7:0] b,
input clk,
input reset,
output reg[7:0] out
);
reg [7:0] s1,s2,b2;
wire [7:0]t1,t2,u;
wire bi;
reg [2:0] count;
assign bi=b2[7];
assign u= bi? s2:s1;
///////// calculate t1= 2u mod p(31)///////
left_shift shift1(u,t1);
//////// calculate t2= s1+s2 mod p/////
adder_dub add1(s1,s2,1'b0,t2);
always @ (posedge clk)
if (~reset)
begin
s1=0; s2= a;
count= 3'd7;
end
/////////////////////////////////////////////////////////////////////////////
else begin
if (count >= 0) begin
if (bi==1)
begin
s1=t1;
s2=t2;
end
else begin
s1=t2;
s2=t1;
end
count= count-1;
end
out<= s1;
end
//////////////// left shift of input b//////////////////////
always @(posedge clk)
if (~reset) begin
b2=b;
end
else begin
b2= {b2[6:0],1'b0};
end
endmodule |