文章目录

  • 例题1
    • 原题复现
    • 题目分析
    • 改进之后
  • 例题2
    • 原题复现
    • 题目分析
    • 改进程序
  • 例题3
    • 原题复现
    • 题目分析
    • 改进程序
  • 例题4
    • 原题复现
    • 题目分析
    • 改进程序
  • 例题5
    • 原题复现
    • 题目分析
    • 改进程序

例题1

原题复现

原题链接
This 8-bit wide 2-to-1 multiplexer doesn’t work. Fix the bug(s).

module top_module (input sel,input [7:0] a,input [7:0] b,output out  );assign out = (~sel & a) | (sel & b);endmodule

题目分析

sel作为选择信号,1的话选择b输出,否则选择a输出。

  • 首先第一个问题在于输出的位宽定义有问题;
  • 由于a和b都是8位的信号,但是通过位运算符和sel进行运算,位宽不对应,需要扩展。

改进之后

module top_module (input sel,input [7:0] a,input [7:0] b,output [7:0] out  );assign out = ({8{sel}} & a) | (~{8{sel}} & b);endmodule

例题2

原题复现

原题链接
This three-input NAND gate doesn’t work. Fix the bug(s).

You must use the provided 5-input AND gate:

module andgate ( output out, input a, input b, input c, input d, input e );


module top_module (input a, input b, input c, output out);//andgate inst1 ( a, b, c, out );endmodule

题目分析

由于采用的例化方式是位置对应方式,所以,例化时候位置需要严格对应。

改进程序

module top_module (input a, input b, input c, output out);//wire out_mid;andgate inst1 ( out_mid, a, b, c,1, 1 );assign out = ~out_mid;endmodule

例题3

原题复现

原题链接
This 4-to-1 multiplexer doesn’t work. Fix the bug(s).

You are provided with a bug-free 2-to-1 multiplexer:

module mux2 (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out
);


module top_module (input [1:0] sel,input [7:0] a,input [7:0] b,input [7:0] c,input [7:0] d,output [7:0] out  ); //wire mux0, mux1;mux2 mux0 ( sel[0],    a,    b, mux0 );mux2 mux1 ( sel[1],    c,    d, mux1 );mux2 mux2 ( sel[1], mux0, mux1,  out );endmodule

题目分析

  • 问题1,在于中间变量的位宽定义不正确;
  • 问题2,例化名不要和模块名一致;
  • 问题3,第二个例化程序的选择变量有问题;

改进程序

module top_module (input [1:0] sel,input [7:0] a,input [7:0] b,input [7:0] c,input [7:0] d,output [7:0] out  ); //wire [7:0] mux0, mux1;mux2 inst_mux0 ( sel[0],    a,    b, mux0 );mux2 inst_mux1 ( sel[0],    c,    d, mux1 );mux2 inst_mux2 ( sel[1], mux0, mux1,  out );endmodule

例题4

原题复现

题目链接
The following adder-subtractor with zero flag doesn’t work. Fix the bug(s).

// synthesis verilog_input_version verilog_2001
module top_module ( input do_sub,input [7:0] a,input [7:0] b,output reg [7:0] out,output reg result_is_zero
);//always @(*) begincase (do_sub)0: out = a+b;1: out = a-b;endcaseif (~out)result_is_zero = 1;endendmodule

题目分析

  • 一个always组合逻辑块内不要既有case又有其他的逻辑,有的允许,有的不允许,尽量不用。
  • out全为0时候,其自或运算为0,否则为1;

改进程序

// synthesis verilog_input_version verilog_2001
module top_module ( input do_sub,input [7:0] a,input [7:0] b,output reg [7:0] out,output  result_is_zero
);//always @(*) begincase (do_sub)0: out = a+b;1: out = a-b;endcaseendassign result_is_zero = ~(|out)?1:0;
endmodule

例题5

原题复现

原题链接

This combinational circuit is supposed to recognize 8-bit keyboard scancodes for keys 0 through 9. It should indicate whether one of the 10 cases were recognized (valid), and if so, which key was detected. Fix the bug(s).

module top_module (input [7:0] code,output reg [3:0] out,output reg valid=1 );//always @(*)case (code)8'h45: out = 0;8'h16: out = 1;8'h1e: out = 2;8'd26: out = 3;8'h25: out = 4;8'h2e: out = 5;8'h36: out = 6;8'h3d: out = 7;8'h3e: out = 8;6'h46: out = 9;default: valid = 0;endcaseendmodule

题目分析

为了把程序改错,真是用心恶毒呀,位宽改,进制改,逻辑改。。。好吧。还好可以实时调试。

改进程序

module top_module (input [7:0] code,output reg [3:0] out,output reg valid=1 );//always @(*) beginvalid = 0;out = 0;case (code)8'h45: beginout = 0;valid = 1;end8'h16: beginout = 1;valid = 1;end8'h1e: beginvalid = 1; out = 2;end8'h26: beginout = 3;valid = 1; end8'h25: beginout = 4;valid = 1;end8'h2e: beginvalid = 1;out = 5;end8'h36: beginvalid = 1;out = 6;end8'h3d: beginvalid = 1;out = 7;end8'h3e: beginvalid = 1;out = 8;end8'h46: beginvalid = 1;out = 9;endendcaseendendmodule

HDLBits 系列(43)找 bug 专题相关推荐

  1. HDLBits答案(23)_找BUG

    Finding bugs in code HDLBits链接 前言 今天更新HDLBits习题部分找BUG部分,比较简单,大家看一下即可. 题库 8bit_2_1_Mux 原Code: module ...

  2. HDLBits 系列(0)专题目录

    本篇博文是近来总结HDLBits系列的目录,点击蓝色字体即可进入查看具体内容. HDLBits 系列(1)从HDLBits中获取灵感,整顿自己,稳步前行 HDLBits 系列(2)如何避免生成锁存器? ...

  3. 漫谈程序员系列:找工作的辟邪剑谱

    我原来面试过一个哥们儿,半年内换了七家公司,我表示膜拜. 还有一些哥们儿,七年不换工作.这得是多稳定的工作啊,七年之痒都扛过去了,真心不错. 这都是极端,一般的程序员,可能会一年半载或者三两年换一次工 ...

  4. 给简书找BUG赢好礼17.04.11——简书iOS 3.5.0 公测【 App内支持提现/创作流程优化】...

    你给简书找bug,简书给你送好礼.即日起,参与简书公测就有机会获得简书提供的精美周边!点我快速获得公测资格>> 本期公测版本-简书iOS 3.5.0: 更新说明 1.1 App内支持直接提 ...

  5. 给简书找BUG赢好礼17.11.27——简书iOS 4.2.0 公测(全新简友圈、发现页;连载内容横空出世)...

    这一次,我们很不一般!简书iOS最新版4.2.0公测!现在召集首批体验的用户,您的意见将会非常地宝贵和重要! 为表达谢意,凡参与简书公测,就有机会获得简书提供的精美周边! 点击下载4.2.0>& ...

  6. 给简书找BUG赢好礼17.06.02——简书Android 2.4.0 公测【私密文章支持预览/手机支持直接提现】...

    你给简书找bug,简书给你送好礼.即日起,参与简书公测就有机会获得简书提供的精美周边!公测版下载>>公测版下载备用地址>> 本期公测版本-简书Android 2.4.0: 更新 ...

  7. 海王星给你好看!FineUI v4.0公测版发布暨《你找BUG我送书》活动开始

    海王星是太阳系八大行星中距离太阳最远的,体积是太阳系第四大,但质量排名是第三.海王星的质量大约是地球的17倍.海王星以罗马神话中的尼普顿(Neptunus)命名,因为尼普顿是海神,所以中文译为海王星. ...

  8. 海王星给你好看!FineUI v4.0公测版发布暨《你找BUG我送书》活动开始(活动已结束!)...

    <FineUI v4.0 你找BUG我送书>活动已结束,恭喜如下三位网友获得由 FineUI 作者亲自翻译的图书<jQuery实战 第二版>! 奋斗~ 吉吉﹑ purplebo ...

  9. 客户花钱雇黑客,竟是为Zoom找bug:风口浪尖的视频会议No.1,安全问题如此魔幻...

    白交 鱼羊 发自 凹非寺 量子位 报道 | 公众号 QbitAI 客户花钱找黑客,帮你产品找Bug-- 这样的客户哪里找?这样的产品又究竟有怎样的福报? Zoom,疫情之下最火爆的视频会议公司,又上演 ...

最新文章

  1. 20190408 Java中的Double类型计算
  2. [译].Net中的内存-什么分配在了哪里
  3. Oracle【IT实验室】数据库备份与恢复之二:SQL*Loader
  4. MySQL学习——操作存储过程
  5. C语言字符串处理函数
  6. 《你好李焕英》票房超《神奇女侠》,贾玲成全球票房最高女导演
  7. 继涉黄被约谈 “比心陪练”App因内容涉宣扬暴力再被处罚
  8. Python基础——字典(dictionary)
  9. Linux下selinux简单梳理
  10. 算法导论第三版第一章答案
  11. 阻抗测试仪软件,特性阻抗测试仪 阻抗测试仪 Tektronix 泰克 TDR DSA8300
  12. java软件制作教程_Minecraft Java版材质包制作教程
  13. switch之enum
  14. Qt利用QZXing和QRenCode识别二维码和制作二维码
  15. [extjs5学习笔记]第三十七节 Extjs6预览版都有神马新东西
  16. Animation和Animator的区别
  17. ARKit之路-ARSession生命周期管理与跟踪质量
  18. cocos2d-x传智播客_Hanselminutes播客167-与Jeremy Miller进行的配置约定
  19. easycode 表配置信息不正确
  20. 量化分析师的Python日记【第6天:数据处理的瑞士军刀pandas下篇

热门文章

  1. 第一部分:开发前的准备-第三章 Application 基本原理
  2. python的六大数据类型中可以改变的数据类型为_Python中数据类型转换
  3. linux下查找网口_Linux查看网络端口
  4. 故障模块名称kernelbase.dll_TLY-01L12/16宜宾智能照明调光模块
  5. html提交表单原理,HTML表单、HTTP Get与Post杂谈
  6. 为什么可积不一定可导_耳机为什么分L和R?你一定不知道真相
  7. 代码和普通的java_Java中普通代码块,构造代码块,静态代码块区别及代码示例...
  8. 第十七届全国大学生智能车竞赛完全模型组 I 型车模数据
  9. 利用反射光电管 ITR9909 制作节能信标光电感应开关
  10. 智慧AI组对于激光投影的检测方案