10.1 非流水线方式的8位全加器
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module adder8(cout,sum,ina,inb,cin,clk);
reg cout;
output [7:0] sum;
reg [7:0] sum;
input [7:0] ina,inb;
input cin;
reg [7:0] tempa,tempb;
reg tempc;
always @ (posedge clk)
begin
tempa=ina;tempb=inb;tempc=cin;
end
always @ (posedge clk)
begin
assign {cout,sum}=tempa+tempb+tempc;
end
endmodule
10.2 4级流水线方式的8位全加器
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
output [7:0] sum;
output cout;
input [7:0] ina,inb;
input cin,clk;
reg [7:0] tempa,tempb,sum;
reg tempci,firstco,secodeco,thirdco,cout;
reg [1:0] firsts,thirda,thridb;
reg [3:0] seconds,seconda,secondb;
reg [5:0] thirds,firsta,firstb;
always @ (posedge clk)
begin
tempa=ina;tempb=inb;tempci=cin;
end
always @ (posedge clk)
begin
{firstco,firsts}=tempa[1:0]+tempb[1:0]+tempci;
firsta=tempa[7:2];
firstb=tempb[7:2];
end
always @ (posedge clk)
begin
{secondco,thirds}={firsta[1:0]+firstb[1:0]+firstco,firsts};
seconda=first