Simple unsigned multiplier (how come there are always omissions, God! Level up is required !)

Source: Internet
Author: User
module multiplier(input clk,rst,input [7:0] A,B,output [16:0] C);reg [3:0] cnt;reg [16:0] temp;always@(posedge clk or negedge rst)if(!rst)begincnt<=0;temp<=0;endelse if(cnt==8)cnt<=0;else if(B[cnt])begintemp<=temp+(A<<cnt);cnt<=cnt+1;endelsecnt<=cnt+1;assign C=(cnt==8)?temp:0;endmodule 
8-digit multiplier, 17-digit product
 1 `timescale 1ns/1ns 2 module multiplier_tb; 3 reg [7:0] A,B; 4 reg clk,rst; 5 wire [16:0] C; 6  7 multiplier U( 8 .A(A), 9 .B(B),10 .clk(clk),11 .rst(rst),12 .C(C)13 );14 15 initial16 begin17 rst=0;18 clk=0;19 A=8‘hfc;20 B=8‘hcf;21 #5 rst=1;22 end23 always24 #10 clk=~clk;25 26 endmodule 
Test Platform

In the figure, the product is output for 8th pulses. Why? It can be seen from the program that temp and CNT are assigned a value in a process, that is, after the arrival of the 8th CLK, temp and CNT are assigned a value at the same time. One is the product of the result, one is CNT = 8; and because of the immediacy of assign, the product has been obtained in the 8th clks.

Considering the bitwise right of the multiplier, elementary school knows that the multiplication formula should be misaligned. Why don't you know it now !!

Simple unsigned multiplier (how come there are always omissions, God! Level up is required !)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.