【HDLBits刷题】Mt2015 q4.

Taken from 2015 midterm question 4

See mt2015_q4a and mt2015_q4b for the submodules used here. The top-level design consists of two instantiations each of subcircuits A and B, as shown below.

 

 Implement this circuit.

第一种是使用module

module top_module (input x, input y, output z);
    wire z1,z2,z3,z4;
    a a_instance1(
        .x(x),
        .y(y),
        .z(z1)
    );
    a a_instance2(
        .x(x),
        .y(y),
        .z(z3)
    );
    b b_instance1(
        .x(x),
        .y(y),
        .z(z2)
    );
    b b_instance2(
        .x(x),
        .y(y),
        .z(z4)
    );
    assign z = (z1|z2)^(z3&z4);
endmodule
module a (
	input wire x,
    input wire y,
    output wire z
);
    assign z = (x^y) & x;
endmodule

module b (
	input wire x,
    input wire y,
    output wire z
);
    assign z = ~x^y;
endmodule

第二种是使用task,从下面代码中可以看出来,同一个module的不同task的参数名是可以一样的,不会冲突,我理解可以认为就是局部变量;另外需要注意的就是task的调用必须在过程块中,比如always。

module top_module (input x, input y, output z);
    wire wire1,wire2,wire3,wire4;
    always@(*)begin
        A(x,y,wire1);
        A(x,y,wire2);
        B(x,y,wire3);
        B(x,y,wire4);
    end
    assign z = (wire1|wire2)^(wire3&wire4);
    //--------------task A-------------------
    task A;
        input x,y;
        output z;
        
        z = (x ^ y) & x;
    endtask
    //------------------task B-----------------
    task B;
        input x,y;
        output z;
        
        z = (x == y)?1:0;
    endtask
endmodule

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值