hdlbits find bugs in code!!!

hdlbits系列(1) find bugs in code
这是我的第一篇文章,一定要坚持下去,想想过去内心浮躁的不成样子,不知道自己做些什么,什么都想学,最后的结果就是什么也学不会,还不如静下心来好好做一件事情,hdlbits真的是一个超级好的网站,废话不多说下面进行第一篇博客的分享。
目录
原题目重现
代码书写
测试与分析
原题目重现
在这里插入图片描述
在这里插入图片描述
代码书写
在这里插入图片描述
这道题的错误在于输出位宽与输入定义不一致,错误输出如下
在这里插入图片描述
当输入与输出位宽不符合的时候,输出呈现高阻态,高阻态可以理解为什么也没接,常用于一个总线挂有多个设备,因此需要重新定义输出位宽。
在这里插入图片描述
经过测试成功。
在这里插入图片描述
代码书写
在这里插入图片描述
在这里插入图片描述
代码书写
在这里插入图片描述
多路选择器有多种实现方式,这只是其中一种,后续文章将会更新,在数字设计基础教程中,经过测试后成功。
在这里插入图片描述
在这里插入图片描述
正常case endcase中要有default语句,避免生成锁存器,由于题目中输入确定因此省略了default选项。
在这里插入图片描述
module top_module (
input [7:0] code,
output reg [3:0] out,
output reg valid=1);//

 always @(*)
    case (code)
        8'h45: 
            begin
            out = 0;
            valid=1;
            end
        8'h16: 
             begin
            out = 1;
           valid=1;
             end
        8'h1e:
            begin
            out = 2;
           valid=1;
            end
        8'h26: 
            begin
            out = 3;
           valid=1;
            end
        8'h25:
            begin
            out = 4;
             valid=1;
            end
        8'h2e: 
            begin
            out = 5;
            valid=1;
            end
        8'h36: 
            begin
            out = 6;
            valid=1;
            end
        8'h3d: 
            begin
            out = 7;
           valid=1;
            end
        8'h3e:
            begin
            out = 8;
           valid=1;
            end
        8'h46: 
             begin
            out = 9;
            valid=1;
             end
        default:  
            begin
            out=0;
           valid=0;
            end
    endcase

endmodule
分析:这道题的问题在于输出不能直接给初值,如果直接在输出给值无法传递和保持,若改成reg valid=1’b1,则会报错,因为输出不能重新被定义或声明,写成output reg valid=1’b1;没有语法错误,若写成output valid,reg valid=1’b1;则会出现上述问题,上述代码测试成功。
下一节更新build large circuit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这些是来自 SonarQube 静态代码分析工具的警告和建议。我将逐个解释它们的含义: 1. "SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings." 这表示 SonarQube 无法自动检测到你的项目的源代码管理(SCM)提供者。你需要手动设置 "sonar.scm.provider" 参数来定义你的项目的 SCM,或在项目设置中禁用 SCM 传感器。 2. "Your code is analyzed as compatible with python 2 and 3 by default. This will prevent the detection of issues specific to python 2 or python 3. You can get a more precise analysis by setting a python version in your configuration via the parameter "sonar.python.version"." 这表示默认情况下,你的代码被分析为与 Python 2 和 3 兼容。这将阻止检测特定于 Python 2 或 Python 3 的问题。你可以通过在配置中设置 Python 版本参数 "sonar.python.version" 来获得更精确的分析。 3. "There are problems with file encoding in the source code. Please check the scanner logs for more details." 这表示源代码中存在文件编码问题。请检查扫描器日志以获取更多详细信息。 4. "24 unanalyzed C files were detected in this project during the last analysis. C cannot be analyzed with your current SonarQube edition. Please consider upgrading to Developer Edition to find Bugs, Code Smells, Vulnerabilities and Security Hotspots in this file." 这表示在最近的分析中检测到了 24 个未分析的 C 文件。你当前使用的 SonarQube 版本无法分析 C 语言。请考虑升级到 Developer Edition,以便在该文件中查找错误、代码异味、漏洞和安全热点。 希望这些解释对你有所帮助!如果你需要进一步的解释或有其他问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值