题解 | #编写乘法器求解算法表达式#

编写乘法器求解算法表达式

https://www.nowcoder.com/practice/c414335a34b842aeb9960acfe5fc879f

`timescale 1ns/1ns

module mul(
	input [3:0] a,
	input [3:0] b,
	output [7:0] result
);
	genvar i;
	wire [7:0] c [0:3]; 
	generate
		for(i = 0; i <= 3; i = i + 1) begin
			 assign c[i] = b[i] ? a<<i : 0;
		end
	endgenerate

	assign result = c[0] + c[1] + c[2] + c[3];

endmodule

module calculation(
	input clk,
	input rst_n,
	input [3:0] a,
	input [3:0] b,
	output [8:0] c
	);

	reg [8:0] c_reg;
	wire [7:0] temp0,temp1;
	mul mul0(.a(12),.b(a),.result(temp0));
	mul mul1(.a(5),.b(b),.result(temp1));

	always @(posedge clk or negedge rst_n) begin
		if(~rst_n) begin
			c_reg <= 0;
		end
		else begin
			c_reg = temp0 + temp1;
		end
	end
	assign c = c_reg;
endmodule


乘法器采用单周期完成,比较简单。

全部评论

相关推荐

11-23 15:33
已编辑
门头沟学院 Java
CUTMR:换账号试试重启推荐算法,我换账号之后回复率还不错,约莫有个20%左右的消息回复率,前几页、主动招呼的HR也开始符合我期望薪资,此前的大号从招呼、回复、前几页的岗位薪资在涨幅30%+以上 用着用着聊着聊着就变成-20%,而且我开通会员之后直接0面试
点赞 评论 收藏
分享
今天 09:59
复旦大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务