【问题标题】:wire output can be used as an inside variable?线输出可以用作内部变量吗?
【发布时间】:2022-11-10 20:46:43
【问题描述】:

我正在学习verilog,我正在https://hdlbits.01xz.net/wiki上做练习题。 问题之一是:

所以我的回答是:

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
    
    wire and_ab;
    wire and_cd;
    wire or_out;
    and(and_ab,a,b);
    and(and_cd, c, d);
    or(or_out, and_ab, and_cd);
    assign out= or_out;
    not(out_n,or_out);
endmodule

毫无疑问这是正确的,但他们的答案是:

module top_module (
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n );
    
    wire w1, w2;        // Declare two wires (named w1 and w2)
    assign w1 = a&b;    // First AND gate
    assign w2 = c&d;    // Second AND gate
    assign out = w1|w2; // OR gate: Feeds both 'out' and the NOT gate

    assign out_n = ~out;    // NOT gate
    
endmodule

我的问题是他们怎么可能将“输出”线用作同一模块中分配的“输入”?它不是 reg 来保存它的值,并不是说我知道你是否可以将 reg 用作“输出”类型。

【问题讨论】:

    标签: verilog system-verilog fpga hdl


    【解决方案1】:

    Verilog 和 SV 允许从模块内读取输出。
    它与不允许相同的 VHDL 不同。

    【讨论】:

    • 所以我可以从驱动它的同一个模块读取输出?它的“reg”还是“wire”有关系吗?
    • 是的,在 Verilog 或 SV 中,可以从驱动输出的模块中读取输出。是否将其定义为 reg 或 wire 无关紧要。
    • VHDL2008 确实允许读取输出
    猜你喜欢
    • 1970-01-01
    • 2017-09-19
    • 2010-10-03
    • 1970-01-01
    • 2021-06-20
    • 2018-07-08
    • 2013-05-23
    • 1970-01-01
    • 2016-09-29
    相关资源
    最近更新 更多