47--加法数乘法器

module add_tree(out,a,b,clk); 
output[15:0] out; 
input[7:0] a,b; 
input clk; 
wire[15:0] out; 
wire[14:0] out1,c1; 
wire[12:0] out2; 
wire[10:0] out3,c2; 
wire[8:0] out4; 
reg[14:0] temp0; 
reg[13:0] temp1; 
reg[12:0] temp2; 
reg[11:0] temp3; 
reg[10:0] temp4; 
reg[9:0] temp5; 
reg[8:0] temp6; 
reg[7:0] temp7; 
function[7:0] mult8x1;                 //该函数实现 8×1乘法 
input[7:0] operand; 
input sel; 
    begin 
    mult8x1= (sel) ? (operand) : 8'b00000000; 
        end 
    endfunction 

    always @(posedge clk)                  //调用函数实现操作数b 各位与操作数 a的相乘 

      begin 

         temp7<=mult8x1(a,b[0]); 

         temp6<=((mult8x1(a,b[1]))<<1); 

         temp5<=((mult8x1(a,b[2]))<<2); 

         temp4<=((mult8x1(a,b[3]))<<3); 

         temp3<=((mult8x1(a,b[4]))<<4); 

         temp2<=((mult8x1(a,b[5]))<<5); 

         temp1<=((mult8x1(a,b[6]))<<6); 

         temp0<=((mult8x1(a,b[7]))<<7); 

      end 

    assign    out1 = temp0 + temp1;            //加法器树运算 

    assign    out2 = temp2 + temp3; 

    assign    out3 = temp4 + temp5; 

    assign    out4 = temp6 + temp7; 

    assign    c1 = out1 + out2; 

    assign    c2 = out3 + out4; 

    assign    out = c1 + c2; 

    endmodule 

`timescale 1ns/1ns
module tb_mult();
wire [15:0]out;
reg [7:0]a,b;
reg clk;

add_tree u1(.out(out),.a(a),.b(b),.clk(clk)); 
initial begin
clk=1'b0;
a=8'b00110100;
b=8'b01010001;
#50 a=8'b01010110;
end
always #5 clk=~clk;
endmodule

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值