题解 | #流水线乘法器#
流水线乘法器
https://www.nowcoder.com/practice/be97f63817c543fe9260d46d971a7283
`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 ); reg[size*2-1:0]temp; wire [size*2-1:0] temp0 ; wire [size*2-1:0] temp1 ; wire [size*2-1:0] temp2 ; wire [size*2-1:0]temp3 ; assign temp0 = mul_b[0]? mul_a : 'd0; assign temp1 = mul_b[1]? (mul_a<<1) : 'd0; assign temp2 = mul_b[2]? (mul_a<<2) : 'd0; assign temp3 = mul_b[3]? (mul_a<<3) : 'd0; always @(posedge clk or negedge rst_n) begin if(!rst_n) begin mul_out <= 'd0; temp<=0; end else begin temp<=temp0+temp1+temp2+ temp3; mul_out<=temp; end end endmodule