首页IT科技刷题笔多少钱(【HDLBits刷题笔记】15 Finding bugs in code)

刷题笔多少钱(【HDLBits刷题笔记】15 Finding bugs in code)

时间2025-06-21 01:23:35分类IT科技浏览5644
导读:Bugs mux2 原本代码的逻辑是反的,这不是坑人吗。...

Bugs mux2

原本代码的逻辑是反的               ,这不是坑人吗              。

Bugs nand3

五输入的与门现在要实现三输入的与非门                     ,多余的门可以输入1并将输出取反                      。

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

Bugs mux4

bug1:mux0和mux1的位宽没设置       ,默认是1;

bug2:选通引脚有问题               ,应该先通过mux[0]判断是ac还是bd                     ,再通过mux[1]进行判断       。

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 u_mux0 ( sel[0], a, b, mux0 ); mux2 u_mux1 ( sel[0], c, d, mux1 ); mux2 u_mux2 ( sel[1], mux0, mux1, out ); endmodule

Bugs addsubz

verilog中~是按位取反       ,!是逻辑取反       。

同时需要补充out不为0的情况        ,否则输出会默认保持                     ,综合出latch                      。

// 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 @(*) begin case (do_sub) 0: out = a+b; 1: out = a-b; endcase if (!out) result_is_zero = 1; else result_is_zero = 0; end endmodule

Bugs case

这道题比较考验眼力              ,一个是d要改成h        ,还有一个是6位改成8位              。晕       。

还有就是先给两个输出赋默认值                      ,就不会综合出latch了              ,而且代码也更加简洁                      。

module top_module ( input [7:0] code, output reg [3:0] out, output reg valid );// always @(*) begin out = 0; valid = 1b1; case (code) 8h45: out = 0; 8h16: out = 1; 8h1e: out = 2; 8h26: out = 3; 8h25: out = 4; 8h2e: out = 5; 8h36: out = 6; 8h3d: out = 7; 8h3e: out = 8; 8h46: out = 9; default: valid = 0; endcase end endmodule
声明:本站所有文章,如无特殊说明或标注                      ,均为本站原创发布              。任何个人或组织                     ,在未征得本站同意时,禁止复制              、盗用                      、采集       、发布本站内容到任何网站       、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益               ,可联系我们进行处理                      。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
领劵优惠(如何**领卷赚佣金-0门槛0囤货0风险,躺赚实现月入过万!)