题解 | #流水线乘法器#

流水线乘法器

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		
);

wire [size*2-1:0] mul_out_1;
wire [size*2-1:0] mul_out_2;
wire [size*2-1:0] mul_out_3;
wire [size*2-1:0] mul_out_4;
wire [size*2-1:0] mul_out_all;

reg [size*2-1:0] mul_a_reg;
reg [size*2-1:0] mul_b_reg;
always @(posedge clk or negedge rst_n)begin
	if(!rst_n)begin
		mul_a_reg <= 0;
		mul_b_reg <= 0;
	end
	else begin
		mul_a_reg <= mul_a;
		mul_b_reg <= mul_b;
	end
end

assign mul_out_1 = mul_b_reg[0] ? mul_a_reg : 0;
assign mul_out_2 = mul_b_reg[1] ? {mul_a_reg,1'b0} : 0;
assign mul_out_3 = mul_b_reg[2] ? {mul_a_reg,2'b00}  : 0;
assign mul_out_4 = mul_b_reg[3] ? {mul_a_reg,3'b000}  : 0;
assign mul_out_all = mul_out_1 + mul_out_2 + mul_out_3 + mul_out_4;

always @(posedge clk or negedge rst_n)begin
	if(!rst_n)begin
		mul_out <= 0;
	end
	else begin
		mul_out <= mul_out_all;
	end
end


endmodule

全部评论

相关推荐

bg&nbsp;为&nbsp;985&nbsp;本应届生,方向是嵌入式软件。纠结了很久,两边都不太了解,恳请各位大佬帮选,非常感谢🙏。
ResourceUtilization:求稳海能达,趁着年轻赚它一笔就relink吧,有个疑惑,怎么睿连同岗位多这么多base原因吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务