题解 | #编写乘法器求解算法表达式#
编写乘法器求解算法表达式
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