Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

double and algorithm in Verilog

Status
Not open for further replies.

malikkhaled

Junior Member level 1
Junior Member level 1
Joined
Jan 14, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
sweden
Visit site
Activity points
1,447
multiplier algorithm in Verilog

i want to implement double ,add and reduce algorithm for modular multiplication, but unfortunately i am not able to get correct result. my algorithms works as: the register s1, s2 hold iterative results which are being initialized by 0 and operand a, these registers are updated in each iteration by values of t1 and t2 registers depending on bit of operand b, finally s1 register holds the final result(ab mod p). here i am posting my code, any help would be appreciated.



Code Verilog - [expand]
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

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top