HDL—Verilog Language—Modules:Hierarchy—Carry-select adder

这个部分就开始考虑到加速的一些东西了

之前几个写的不论是1位加法器还是16位的加法器,实际上都是1位的,可以观察到,如果前面cout没有给出进位的数据,后面是没法开始运算的,所以前面的加法器就会很慢,延迟很高

但实际上,后面模块的运算可以优先进行,把进位是0和1的值都算出来,然后通过判断cout是0还是1,直接输出,这样就可以节约在知道cout的值之后,还需给运算的时间。

n this exercise, you are provided with the same module add16 as the previous exercise, which adds two 16-bit numbers with carry-in and produces a carry-out and 16-bit sum.  You must instantiate three of these to build the carry-select adder, using your own 16-bit 2-to-1 multiplexer.

Connect the modules together as shown in the diagram below.  The provided module add16 has the following declaration:

module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );

在这个练习中,你将使用与前一个练习相同的模块add16,它将两个带进位的16位数字相加,并生成一个带进位的16位和。用户必须实例化其中三个来构建进位选择加法器,使用用户自己的16位2对1多路复用器。
如下图所示,将模块连接在一起。提供的模块add16有如下声明:
模块add16(输入[15:0]a,输入[15:0]b,输入cin,输出[15:0]sum,输出cout);

主要是理解这个提前运算的概念,实际设计就按照图片给的连线就可以了。

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire c_choose;
    wire [15:0]sum_2;
    wire [15:0]sum_3;
    add16 add16_1(.a(a[15:0]),.b(b[15:0]),.cin(0),.cout(c_choose),.sum(sum[15:0]));
    add16 add16_2(.a(a[31:16]),.b(b[31:16]),.cin(0),.cout(),.sum(sum_2));
    add16 add16_3(.a(a[31:16]),.b(b[31:16]),.cin(1),.cout(),.sum(sum_3));
    assign sum[31:16] = (c_choose) ? sum_3 : sum_2 ;
endmodule

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值