HDLBits_Module cseladd

本文介绍如何使用提供的add16模块构建一个高效的32位加法器,通过 Carry-Select 结构改进传统 Ripple-Carry 加法器,减少延迟,提高运算速度。关键步骤包括使用二选一数据选择器根据低16位进位决定高16位的处理方式。

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.

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.

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 );

在这里插入图片描述
题目基本意思是让你实现一个32位加法器,题目已经提供好了add16,只不过在进行高16位的计算时要根据低16位的进位,通过一个二选一数据选择器来确定高16位
错误点:
直接将低16位的进位用作高16位的进位
结果是正确的但是无法通过测试点,因为这个二选一数据选择器选择顺序恰好和进位一致。提交会显示
在这里插入图片描述

正确代码

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire cout;
    wire [15:0] buffer1,buffer2;
    add16 u1(a[15:0],b[15:0],1'b0,sum[15:0],cout);
    add16 u2(a[31:16],b[31:16],1'b0,buffer1);
    add16 u3(a[31:16],b[31:16],1'b1,buffer2);
    assign sum[31:16] = cout? buffer2:buffer1;
    
        

endmodule
module add1(input a,input b,input cin,output sum,output cout);
    assign sum = a^b^cin;
    assign cout = a&b | a&cin | b&cin;
endmodule
CC=aarch64-linux-gnu-gcc \ CXX=aarch64-linux-gnu-g++ \ AR=aarch64-linux-gnu-ar \ RANLIB=aarch64-linux-gnu-ranlib \ ./configure \ --prefix=/opt/nginx \ --with-cc=aarch64-linux-gnu-gcc \ --with-cpp=aarch64-linux-gnu-cpp \ --with-ld-opt="-static" \ # 可选:静态链接减少依赖 --without-http_rewrite_module \ --without-http_gzip_module \ --without-pcre \ --without-http_ssl_module \ --without-http_proxy_module \ --without-http_fastcgi_module \ --without-http_uwsgi_module \ --without-http_scgi_module \ --without-http_memcached_module \ --without-http_empty_gif_module \ --without-http_browser_module \ --without-http_geo_module \ --without-http_map_module \ --without-http_split_clients_module \ --without-http_referer_module \ --without-http_limit_conn_module \ --without-http_limit_req_module \ --without-http_auth_basic_module \ --without-http_access_module \ --without-http_realip_module \ --without-http_addition_module \ --without-http_degradation_module \ --without-http_flv_module \ --without-http_mp4_module \ --without-http_sub_module \ --without-http_slice_module \ --without-mail_pop3_module \ --without-mail_imap_module \ --without-mail_smtp_module \ --without-http_upstream_ip_hash_module \ --without-http_upstream_least_conn_module \ --without-http_upstream_keepalive_module \ --without-http_upstream_zone_module \ --without-threads \ --without-select_module \ --without-poll_module \ --without-kqueue_module \ --without-eventport_module \ --without-file_aio \ --without-http_dav_module \ --without-http_ssi_module \ --crossbuild=Linux::x86_64::unknown 把这个命令改成没有\的,横向的
最新发布
11-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值