hdlbits答案:Notgate、Wire decl、The 7458 取消定义中间量,减少代码行数

10 篇文章 0 订阅
9 篇文章 0 订阅

Notgate

Create a module that implements a NOT gate.

This circuit is similar to wire, but with a slight difference. When making the connection from the wire in to the wire out we're going to implement an inverter (or "NOT-gate") instead of a plain wire.

Use an assign statement. The assign statement will continuously drive the inverse of in onto wire out.

module top_module( input in, output out );
    assign out=~in;
endmodule

Wire decl:

If you're following the circuit structure in the diagram, you should end up with four assign statements, as there are four signals that need a value assigned.

`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
wire ab,cd,abcd;
	assign ab=a&b;
	assign cd=c&d;
	assign abcd=ab|cd;
	assign out=abcd;
	assign out_n=~abcd;
endmodule

代码其实可以优化到更简单,具体如下:

`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
	assign out=(a&b) | (c&d);
	assign out_n=~( (a&b) | (c&d) );
endmodule

The 7458 :

The 7458 is a chip with four AND gates and two OR gates. This problem is slightly more complex than 7420

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );

assign p2y=(p2a&p2b) | (p2c&p2d);
assign p1y=(p1a&p1c&p1b) | (p1f&p1e&p1d);

endmodule

取消定义中间量,代码行数减少,但是代码的可读性变差。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值