-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplier1.v
More file actions
125 lines (84 loc) · 2.45 KB
/
Copy pathmultiplier1.v
File metadata and controls
125 lines (84 loc) · 2.45 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
module Mul_datapath(result,eqz,data_in,ldA,ldB,ldP,clrP,decB,clk);
input ldA,ldB,ldP,clrP,decB,clk;
input [15:0] data_in;
output eqz;
output reg [15:0] result;
wire [15:0] x,y,z,Bout,Bus ; //reg x,y,z,Bout are not permissible(port iss)
//always@(posedge clk)
//if(eqz==0)
PIPO_r A(x,Bus,ldA,clk);
PIPO_p P(y,z,ldP,clrP,clk);
ADDER AD(z,x,y);
DEC_B DB(Bout,Bus,ldB,decB,clk);
COMP CP(eqz,Bout);
always@(eqz ) begin
result<=eqz ? y : 16'bx ; end
assign Bus = data_in ;
endmodule // Mul_datapath
module controller(done,ldA,ldB,ldP,clrP,decB,start,data_in,eqz,clk);
input start,eqz,clk;
input [15:0] data_in;
output reg ldA,ldB,ldP,clrP,decB,done;
parameter s0=3'b000 , s1=3'b001 ,s2=3'b010 ,s3=3'b011 ,s4=3'b100 ;
reg [2:0]state ;
always@(posedge clk)
case (state)
s0 : state<= start ? s1 : s0 ;
s1 : state<=s2;
s2 : state<=s3;
s3 : state<= eqz ? s4 : s3 ;
s4 : state<=s4;
default: state<=s0 ;
endcase
always@(state)
case (state)
s0 : {done,ldA,ldB,ldP,clrP,decB}=0 ;
s1 : begin {done,ldB,ldP,clrP,decB}=0 ; ldA=1 ;end
s2 : begin {done,ldA,ldP,decB}=0 ; ldB=1; clrP=1 ;end
s3 : begin {done,ldA,ldB,clrP}=0 ; ldP=1; decB=1; end
s4 : begin {ldA,ldB,ldP,clrP,decB}=0 ; done=1; end
default : {done,ldA,ldB,ldP,clrP,decB}=0 ;
endcase // case (state)
endmodule // controller
module PIPO_r(out,in,ld,clk);
input [15:0] in;
input ld, clk;
output reg [15:0] out;
always @ ( posedge clk ) begin
if(ld==1) out<=in ;
end
endmodule // PIPO_r
module PIPO_p(out,in,ld,clr,clk);
input [15:0] in;
input ld, clk,clr;
output reg [15:0] out;
always @ ( posedge clk ) begin
case(1'b1)
clr : out<=0 ;
ld : out<=in ;
endcase
/*if(clr==1) out<=0 ; //why this shows as syntax error??
elseif(ld==1) out<=in ; */
end
endmodule // PIPO_p
module ADDER (out,in1,in2 ) ;
input [15:0]in1,in2;
output [15:0] out;
assign out = in1+in2;
endmodule // ADDER
module DEC_B(out,in,ld,en,clk ) ;
input [15:0] in;
input ld, clk, en;
output reg [15:0] out;
always@(posedge clk)
case (1'b1)
ld : out<=in ;
en : out<=out ? out-1: out;
default :out<=out;
endcase // case (1'b1)
endmodule // DEC_B
module COMP (out,in ) ;
input [15:0]in ;
output out ;
assign out= in ? 0 :1 ;
endmodule // COMP