Verilog刷题[hdlbits] :Module cseladd

题目:Module cseladd

One drawback of the ripple carry adder (See previous exercise) is that the delay for an adder to compute the carry out (from the carry-in, in the worst case) is fairly slow, and the second-stage adder cannot begin computing its carry-out until the first-stage adder has finished. This makes the adder slow. One improvement is a carry-select adder, shown below. The first-stage adder is the same as before, but we duplicate the second-stage adder, one assuming carry-in=0 and one assuming carry-in=1, then using a fast 2-to-1 multiplexer to select which result happened to be correct.

  • ripple carry adder(见之前的练习)的一个缺点是,加法器计算carry out(从carry-in,在最坏的情况下)的延迟相当慢,而第二阶段的加法器在第一阶段的加法器完成之前无法开始计算其carry out。这使得加法器变慢。一种改进是carry-select adder,如下所示。第一阶段的加法器与之前相同,但我们复制了第二阶段的加法器,一个假设carry-in=0,另一个假设carry-in=1,然后使用快速的2-to-1多路复用器选择哪个结果是正确的。

In 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.

  • 在本练习中,您将使用与之前的练习相同的模块add16,该模块将两个16位数字与carry-in相加并产生一个carry-out和16位和。您必须实例化三个这样的模块来构建carry-select adder,使用您自己的16位2-to-1多路复用器。

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

  • 将模块按照下面的图示连接起来。提供的模块add16具有以下声明:
    module add16 ( input15:0 a, input15:0 b, input cin, output15:0 sum, output cout );

在上一题Module fadd中,高16位的计算需要在得出进位信号后才能进行,这会使加法器变慢。同时由于进位信号只有0或1两种可能,所以在本题Module cseladd中,使用了两个add16来计算高16位的结果,并且这两个add16的进位信号cin分别为0和1。此时,在计算加法的计算步骤为,低16位相加(进位为0)、高16位相加(进位为0)与高16位加法(进位为1)三部分并行进行,再根据低16位相加得出的进位结果选取正确的高16位相加结果,进而得出最终答案。

objectivec 复制代码
module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
	//进位信号
    wire cout;
    //存储 高16位相加(进位为0) 的结果
    wire [15:0] sum_high_1;
    //存储 高16位相加(进位为0) 的结果
    wire [15:0] sum_high_2;
	//低16位相加
	add16 add16_init_0( 
        .a(a[15:0]), 
        .b(b[15:0]),
        .cin(1'b0), 
        .sum(sum[15:0]), 
        .cout(cout) 
    );
    //高16位相加(进位为0)
	add16 add16_init_1( 
        .a(a[31:16]), 
        .b(b[31:16]),
        .cin(1'b0), 
        .sum(sum_high_1), 
        .cout() 
    );  
    //高16位相加(进位为1)
	add16 add16_init_2( 
        .a(a[31:16]), 
        .b(b[31:16]),
        .cin(1'b1), 
        .sum(sum_high_2), 
        .cout() 
    );  
	//根据进位结果选取正确的高16位运算结果
    assign  sum[31:16] = cout ? sum_high_2 : sum_high_1;
	    
endmodule
相关推荐
物质波波波5 小时前
WS-RPE:面向边缘物理AI实时特征值计算的硬件工作窃取调度器与冗余PE激活架构
人工智能·fpga开发·架构·系统架构·硬件架构
我爱C编程8 小时前
基于FPGA的DSB调制解调系统verilog开发
fpga开发·verilog·fpga·dsb
zlinear数据采集卡8 小时前
USB HS 480M高速传输与SRAM记录仪:DABM-D223数据存储系统全解析
arm开发·嵌入式硬件·fpga开发·开源
逻辑诗篇10 小时前
基于 XCVU13P 的 4 路 100G 光纤 PCIe 处理板 PCIE727 硬件规格全解析
fpga开发
玩嵌入式谁会脱发呀14 小时前
【FPGA】 verilog设计spi读写flash实现数据DMA搬运
fpga开发
LabVIEW开发2 天前
LabVIEW 如何把地下震源定位误差做到5米内
fpga开发·labview·labview知识·labview功能·labview程序
Dr.kangder2 天前
嵌入式处理器架构解析(十)——DSP+FPGA
fpga开发·架构·嵌入式
szxinmai主板定制专家2 天前
Zynq MPSoC实现半导体真空腔体状态监测|FPGA多传感器时序同步采集方案
fpga开发·zynq·控制器·mpsoc·半导体设备·fpga同步
学习FPGA的电气小兴兴2 天前
基于FPGA的DDS信号发生器设计,生成频率可调的正弦波、三角波、锯齿波和方波
fpga开发·数字信号处理·fpga·vivado·dsp·dds·diy
szxinmai主板定制专家3 天前
Zynq MPSoC半导体高精度运动控制方案|FPGA硬件插补实现亚微米级伺服实时控制
人工智能·嵌入式硬件·fpga开发·zynq·运动控制·ethercat