forked from sudhamshu091/32-Verilog-Mini-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodified_booth.v
67 lines (60 loc) · 1.45 KB
/
modified_booth.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
module MBA_module(p,a,b,clock);
output [15:0] p;
input [7:0] a, b;
input clock;
reg [15:0] p,ans;
integer i, lookup_tbl;
integer operate;
initial
begin
p=16'b0;
ans=16'b0;
end
always @(negedge clock)
begin
p=16'b0;
for(i=1;i<=7;i=i+2)
begin
if(i==1)
lookup_tbl = 0;
else
lookup_tbl = b[i-2];
lookup_tbl = lookup_tbl + 4*b[i] + 2*b[i-1];
if(lookup_tbl == 0 || lookup_tbl == 7)
operate = 0;
else if(lookup_tbl == 3 || lookup_tbl == 4)
operate = 2;
else
operate = 1;
if(b[i] == 1)
operate = -1*operate;
case(operate)
1:
begin
ans=a;
ans=ans<<(i-1);
p=p+ans;
end
2:
begin
ans=a<<1;
ans=ans<<(i-1);
p=p+ans;
end
-1:
begin
ans=~a+1;
ans=ans<<(i-1);
p=p+ans;
end
-2:
begin
ans=a<<1;
ans=~ans+1;
ans=ans<<(i-1);
p=p+ans;
end
endcase
end
end
endmodule