// 加法器的分流水线实现
module adder8(cout,sum,clk,cina,cinb,cin);
input [7:0] cina,cinb;
input clk,cin;
output [7:0] sum;
output cout;
reg cout;
reg [7:0] sum;
always @( cina or cinb or cin )
begin
{cout,sum}=cina+cinb+cin;
end
endmodule
//二级流水线 加法器的流水线实现
module adder8_2(cout,sum,clk,cina,cinb,cin);
input [7:0] cina,cinb;
input clk,cin;
output [7:0] sum;
output cout;
reg cout;
reg cout1;
reg [3:0] sum1;
reg [7:0] sum;
always @( posedge clk )
begin
{cout1,sum1}=cina[3:0]+cinb[3:0]+cin;
end
always @( posedge clk )
begin
{cout,sum}={ {cina[7],cin[7:4]}+{cinb[7],cinb[7:4]+cout1},sum1 };
end
endmodule
//四级流水线 加法器的流水线实现
module adder8_4(cout,sum,clk,cina,cinb,cin);
input [7:0] cina,cinb;
input clk,cin;
output [7:0] sum;
output cout;
reg cout;
reg cout1,cout2,cout3;
reg [2:0] sum1;
reg [4:0] sum2;
reg [6:0] sum3;
reg [7:0] sum;
always @( posedge clk )
begin
{cout1,sum1}=cina[1:0]+cinb[1:0]+cin;
end
always @( posedge clk )
begin
{cout2,sum2}={ {cina[3],cin[3:2]}+{cinb[3],cinb[3:3]+cout1},sum1 };
end
always @( posedge clk )
begin
{cout3,sum3}={ {cina[5],cin[5:4]}+{cinb[5],cinb[5:4]+cout2},sum2 };
end
always @( posedge clk )
begin
{cout,sum}={ {cina[7],cin[7:6]}+{cinb[7],cinb[7:6]+cout3},sum3 };
end
endmodule
文章评论(0条评论)
登录后参与讨论