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

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

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

`timescale 1ns/1ns
//换成移位和加即可
module calculation(
	input clk,
	input rst_n,
	input [3:0] a,
	input [3:0] b,
	output [8:0] c
	);
	//12 1100,5 0101

	reg [8:0] c;
	reg [7:0]   temp_a2,
				temp_a3,
				temp_b1,
				temp_b2;
	always @(posedge clk or negedge rst_n)
		if(!rst_n)	begin
			temp_a2 <= 'd0;
			temp_a3 <= 'd0;
			temp_b1 <= 'd0;
			temp_b2 <= 'd0;
		end
		else	begin
			temp_a2<=(a<<2);
			temp_a3<=(a<<3);
			temp_b1<=b;
			temp_b2<=(b<<2);
		end

	always @(posedge clk or negedge rst_n)
		if(!rst_n)	
			c <= 'd0;
		else begin
			c<= temp_a2 + temp_a3+ temp_b1+ temp_b2;
		end


endmodule

全部评论

相关推荐

07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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