HDL 4.1 Find bug

这两题没有给出具体的函数代码,我觉得fix bugs 的解题思路是,首先清楚常规函数的代码原理,然后根据原理修改代码,其中修改一些代码不规范的错误,

4.1.2 NAND

源代码:

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_and;
    andgate inst1 ( .out(out_and), .a(a), .b(b), .c(c), .d(1'b1), .e(1'b1) );
    assign out = !out_and;
endmodule
  1. 函数参数位置是否正确?
  2. 参数引用是否正确?
  3. 判断每个参数的长度是否一致? 

4.1.3 MUX

需要清楚4选一是怎么实现的?

所以mux0 和 mux1需要用来判断sel为0,1,2,3时对应的四选一分别为a,b,c,d。

mux0为sel[1]为0时,从sel为0,1选择a,b

mux1为sel[1]为1时,从sel为2,3选择c,d

最后mux3通过第二位进位是否为1来判断选择mux0还是mux1的结果

源代码: 

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

修改后的代码: 

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] mux00, mux11;
    mux2 mux0 ( sel[0]&!sel[1],    a,    b, mux00 );
    mux2 mux1 ( sel[1]&sel[0],    c,    d, mux11 );	//confirm the order 
    mux2 mux3 ( sel[1], mux00, mux11,  out );

endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值