HDLBits刷题_Verilog Language_Bcdadd100_bcd add100_Little_Engineer456的博客-程序员宅基地

技术标签: fpga开发  HDLBits刷题  

You are provided with a BCD one-digit adder named bcd_fadd that adds two BCD digits and carry-in, and produces a sum and carry-out.

module bcd_fadd {
    input [3:0] a,
    input [3:0] b,
    input     cin,
    output   cout,
    output [3:0] sum );

Instantiate 100 copies of bcd_fadd to create a 100-digit BCD ripple-carry adder. Your adder should add two 100-digit BCD numbers (packed into 400-bit vectors) and a carry-in to produce a 100-digit sum and carry out.

注意:这一题中,貌似always内不能调用块,因此造成很大的误导。另未用bac_fadd块也可完成。

module top_module( 
    input [399:0] a, b,
    input cin,
    output cout,
    output [399:0] sum );
    
    //assign cout = (sum[3:0] > 9) ? 1 : 0 ;
    /*wire [4:0] me;
    wire [3:0] ml;
    always @(*)begin
        me = a[3:0] + b[3:0] + cin;
        sum[3:0] = (me < 10) ? me: (me-10);
        cout = (me > 9) ? 1 : 0 ;
        for (int i=4; i<400; i=i+4)
        begin
            me = a[i+:4] + b[i+:4] + cout;
            sum[i+:4] = (me < 10) ? me: (me-10);
            cout = (me > 9) ? 1 : 0 ;
        end
    end*/
    wire [400:0] cout1;
    bcd_fadd add0(a[3:0],b[3:0],cin,cout1[4],sum[3:0]);
    always @(*)begin 
        for (i=4; i<400; i=i+4) begin
            bcd_fadd add1(a[i+:4], b[i+:4], cout1[i], cout1[i+4], sum[i+:4]); //使用 
                                                                //always不能调用module块
        end
    end
    assign cout = cunt1[i];
    
    /*wire [99:0] temp;
    bcd_fadd add0(a[3:0],b[3:0],cin,temp[0],sum[3:0]);
    genvar i;
    generate 
        for(i=4;i<400;i=i+4) begin: add45
            bcd_fadd add1(a[i+3:i],b[i+3:i],temp[(i>>2)-1],temp[i>>2],sum[i+3:i]);
        end
    endgenerate
    assign cout = temp[99];*/

endmodule

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_65438107/article/details/122115879

智能推荐

递归想法和实现介绍,消除递归-程序员宅基地

递归思想的一点思考参考,还有递归的实现,和消除递归的思路和实现代码

提取视频关键帧和关键帧的时间点信息_如何根据关键帧获取广告的开始时间结束时间-程序员宅基地

这篇文章的原文地址是:http://www.videoproductionslondon.com/blog/scene-change-detection-during-encoding-key-frame-extraction-code里面主要介绍了如何提取视频关键帧,以及视频关键帧的时间点信息,这样就能做出各大视频网站的那种:点击视频下方进度条,显示该时间点附近关键帧图片的效果。_如何根据关键帧获取广告的开始时间结束时间

rvm的安装与使用_rvm安装-程序员宅基地

rvm的安装与使用,ruby版本管理器_rvm安装

说说ThreadPoolExecutor饱和策略CallerRunsPolicy_忆之独秀的博客-程序员宅基地

之前在文章深入线程池ThreadPoolExecutor中聊到了线程池_callerrunspolicy

AtCode ABC123 - D - Cake 123_atcoder abc123-程序员宅基地

标签全搜索、优先队列题目地址D - Cake 123https://atcoder.jp/contests/abc123/tasks/abc123_d问题描述The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively. Each cak_atcoder abc123

李沐深度学习教程笔记 (1)_vrbd嗨起来-程序员宅基地

框架:Mxnet/Gluon 教程的网页资料:http://zh.gluon.ai 教程的GitHub地址:https://github.com/mli/cvpr17 直播:在斗鱼平台搜索“将门风投”_vrbd嗨起来

随便推点

[论文阅读 2019 CVPR 目标跟踪]Unsupervised Deep Tracking_revisiting correlation tracking_lingqing97的博客-程序员宅基地

简介paper:Unsupervised Deep Trackingcode:594422814/UDT_pytorch这篇论文的亮点在于通过无监督学习的方式来进行目标跟踪,且取得了与监督学习模型相当的精度。论文的基本思想是:首先将当前帧作为template frame,后一帧作为Search frame,从而得到响应RSR_SRS​,之后反过来,将后一帧作为template frame同时以预测结果RSR_SRS​作为其标签,然后当前帧作为Search frame预测当前帧的响应RTR_TRT​,_revisiting correlation tracking

Lua学习笔记六——package-程序员宅基地

lua和其他语言一样,也有模块/包的概念,稍微有点不同的是,默认先从环境变量LUA_PATH中搜索lua文件,如果搜索不到,则从LUA_CPATH中搜索C文件。 对于我来说,时而去改变环境变量,则显得麻烦,并且在另外的环境中部署时还要修改环境变量,则显得不人性化,因此,觉得如下方式增加搜索路径比较好: --将自定义包路径加入package的搜索路径中。也可以加到环境变量LUA_P

kubsphere挂本地节点机运行devops-程序员宅基地

看到很多教程都是基于docker挂载到k8s上的,因为我们客户端的产品都是运行在桌面端,比如mac、window、Ubuntu上,所以分享一个基于公司的k8s搭建的一个针对客户端的devops流程。1使外部集群可以访问到jenkins服务创建k8s后,修改 jenkins agent service,使集群外部可以访问此服务kubectl edit svc -n kubesphere-devops-system ks-jenkins-agent将服务类型修改为 NodePort,此时通过下面命令可以

Citrix各系列产品安装光盘资源下载链接-程序员宅基地

对Citrix产品感兴趣的网友们,福利来啦!Citrix各系列产品安装光盘资源下载链接1、CitrixXenApp:http://www.xen800.com/thread-1561-1-1.html2、CitrixXenDesktop:http://www.xen800.com/thread-1762-1-1.html3、CitrixXenServer:ht...

hadoop map/reduce setup_hadoop setup-程序员宅基地

1, What Is Apache Hadoop?The Apache Hadoop project develops open-source software for reliable, scalable, distributed computing.The Apache Hadoop software library is a framework that allows f_hadoop setup

python中gbk含有0x_命令行调用python出现编码错误:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x9a in position ...-程序员宅基地

命令行输入python,出现一大串警告内容如下所示:Type "help", "copyright", "credits" or "license" for more information.Failed calling sys.__interactivehook__Traceback (most recent call last):File "D:\anaconda3\lib\site.py",...

推荐文章

热门文章

相关标签