HDLbits答案更新系列21(4 Verification: Reading Simulation 4.1 Finding bugs in code)

目录

前言

4 Verification: Reading Simulation

4.1 Finding bugs in code

4.1.1 Mux(Bugs mux2)

4.1.2 NAND(Bugs nand3)

4.1.3 Mux(Bugs mux4)

4.1.4 Add/sub(Bugs addsubz)

4.1.5 Case statement(Bugs case)

结语

HDLbits网站链接


前言

今天进入到了第四部分,这部分第一小节的内容比较简单,直接更新吧。

4 Verification: Reading Simulation

4.1 Finding bugs in code

4.1.1 Mux(Bugs mux2)

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

    assign out = sel ? a : b;

endmodule

这道题目的错误在于a和b都是多比特的数据,而sel信号是单比特的。如果a、b也是单比特,那么可以用修改前的方式。

4.1.2 NAND(Bugs nand3)

module top_module (input a, input b, input c, output out);
    
    wire out_1;

    andgate inst1 (out_1, a, b, c, 1'b1,1'b1);
    
    assign out = ~out_1;

endmodule

这道题第一处错误是端口映射没有将out写在第一位,第二处错误是题目要求完成与非门,作者给出的可引用的module是与门。

4.1.3 Mux(Bugs mux4)

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;
    wire[7:0]	mux1;
    
    mux2 u1_mux2 ( sel[0],    a,    b, mux0 );
    mux2 u2_mux2 ( sel[0],    c,    d, mux1 );
    mux2 u3_mux2 ( sel[1], mux0, mux1,  out );

endmodule

这道题目中首先mux0和mux1应该定义为8bit,然后实例化的前两个mux应该是sel[0]。

4.1.4 Add/sub(Bugs addsubz)

// 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 == 8'd0)
            result_is_zero = 1;
        else
            result_is_zero = 0;
    end

endmodule

这道题目要将result_is_zero补充完整。

4.1.5 Case statement(Bugs case)

module top_module (
    input [7:0] code,
    output reg [3:0] out,
    output reg valid
);

    always @(*)begin
        case (code)
            8'h45: out = 0;
            8'h16: out = 1;
            8'h1e: out = 2;
            8'h26: out = 3;
            8'h25: out = 4;
            8'h2e: out = 5;
            8'h36: out = 6;
            8'h3d: out = 7;
            8'h3e: out = 8;
            8'h46: out = 9;
            default: out = 0;
        endcase
        if(out == 4'd0 && code != 8'h45)begin
            valid = 1'b0;
        end
        else begin
            valid = 1'b1;
        end
    end
    
    /*
    //second way
    always @(*) begin
		out = 0;
		valid = 1;	
		case (code)
			8'h45: out = 0;
			8'h16: out = 1;
			8'h1e: out = 2;
			8'h26: out = 3;	
			8'h25: out = 4;
			8'h2e: out = 5;
			8'h36: out = 6;
			8'h3d: out = 7;
			8'h3e: out = 8;
			8'h46: out = 9;
			default: valid = 0;
		endcase
	end
    */

endmodule

这道题给出两种方法,大家看一下就可以了。第一种方法我将valid和out全部写在一个always中,这是不好的,建议大家分开写。

结语

今天更新这个小节吧,应该没有特别难的题目,如果我有代码错误的地方欢迎留言指出哦。

HDLbits网站链接

https://hdlbits.01xz.net/wiki/Main_Page

解决 “Verification error: self-signed certificate in certificate chain” 错误通常有以下几种方法: #### 临时绕过证书验证 在测试或开发环境中,可以临时绕过证书验证,但这种方法不建议在生产环境中使用,因为会带来安全风险。 - **Postman**:在 Postman 中,可关闭 “设置(SETTINGS)” 选项里的 “SSL certificate verification” 开关,关闭后请求便能正常传到后台并获取数据[^4]。 - **Python 的 requests 库**:在使用 `requests` 库发送请求时,可通过设置 `verify=False` 来绕过证书验证。示例代码如下: ```python import requests try: response = requests.post('https://example.com', verify=False) print(response.text) except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` #### 将自签名证书添加到信任列表 可以将自签名证书添加到系统或应用程序的信任证书列表中,使系统或应用程序信任该证书。 - **Linux 系统**: - 将自签名证书复制到 `/usr/local/share/ca-certificates/` 目录下。 - 运行 `update-ca-certificates` 命令更新系统的 CA 证书。 - **Windows 系统**: - 打开 “管理计算机证书” 工具。 - 在 “受信任的根证书颁发机构” 存储中导入自签名证书。 - **Java 应用程序**:可以使用 `keytool` 工具将自签名证书添加到 Java 的信任库中。示例命令如下: ```bash keytool -import -alias mycert -file mycert.crt -keystore cacerts ``` #### 使用受信任的 CA 签名证书 为服务器获取由受信任的证书颁发机构(CA)签名的证书,这是最安全和推荐的方法。可以向知名的 CA 机构申请证书,如 Let's Encrypt,它提供免费的 SSL/TLS 证书。
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值