题解 | #流水线乘法器#
流水线乘法器
https://www.nowcoder.com/practice/be97f63817c543fe9260d46d971a7283
//temp 一定给out的位宽 也就是俩倍 //打一拍输出 `timescale 1ns/1ns module multi_pipe#( parameter size = 4 )( input clk , input rst_n , input [size-1:0] mul_a , input [size-1:0] mul_b , output reg [size*2-1:0] mul_out ); wire [size*2-1:0]temp0; wire [size*2-1:0]temp1; wire [size*2-1:0]temp2; wire [size*2-1:0]temp3; reg [size*2-1:0]temp; assign temp0=mul_b[0]?{4'b0,mul_a}:0; assign temp1=mul_b[1]?{3'b0,mul_a,1'b0}:0; assign temp2=mul_b[2]?{2'b0,mul_a,2'b0}:0; assign temp3=mul_b[3]?{1'b0,mul_a,3'b0}:0; always@(posedge clk or negedge rst_n)begin if(!rst_n) mul_out<=0; else mul_out<=temp;end always@(posedge clk or negedge rst_n)begin if(!rst_n) temp<=0; else temp<=temp0+temp1+temp2+temp3;end endmodule