用了1个时钟周期便得到了输出
module mul_pipeling( clk, x, a, y,rst
);
input clk;
input rst;
input [2:0] x, a;
output [5:0] y;
reg [5:0] y;
reg [5:0] sum0;
reg [5:0] sum1;
reg [5:0] sum2;
always @(posedge clk or posedge rst)
if(rst) begin
sum0 <= 6'b0;
sum1 <= 6'b0;
sum2 <= 6'b0;
end
else begin
sum0 <= a[0]? {3'b000,x} : 6'b0;
sum1 <= a[1]? {2'b00,x,1'b0} : 6'b0;
sum2 <= a[2]? {1'b0, x,2'b00} : 6'b0;
y <= sum0 + sum1 + sum2;
end
endmodule