【问题标题】:What is the difference between assigning a variable inside begin-end block and outside it?在 begin-end 块内部和外部分配变量有什么区别?
【发布时间】:2021-03-04 07:40:24
【问题描述】:

考虑一个连线类型变量 x。在 begin-end 块内赋值。例如 开始 x = 1'b0 结束

在 begin-end 块之外。例如

赋值 x = 1'b0

它们之间的主要区别是什么?

【问题讨论】:

  • 您不能对电线进行程序分配

标签: system-verilog


【解决方案1】:

Verilog 有两种结构,结构和程序。

在模块中,您可以有声明和结构构造,例如generate,模块实例,分配。这些是代表电路中一部分的东西。

  input data
  wire a;
  wire b;
  assign a = data; // this is a wire connection in the circuit
  assign b = ~data; // this an inverted gate and b is connected to its output

你有过程上下文,你可以在其中描述更像编程的逻辑。

 // sequential logic
 always @(posedge clk or negedge rstn) begin
    // here you cannot assign
    if(~rstn) begin
      // here you reset your logic
    end
    else begin
      // here you write some logic that can be though
      // as an event handler
      // every variable here will be be store in a flop
      a <= data; 
      // the value of a is not updated at this point
      // only after the block execution ends
      // it is called non-blocking assignment

    end
 end
 input data;
 reg b;
 always @(data) begin
   b = data; // b is not a flop even though it was declared as a reg.
 end

还有很多,如果你把你的问题更具体一些,它可能有助于回答。

【讨论】:

    猜你喜欢
    • 2012-10-02
    • 2015-02-10
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 2013-09-06
    • 2017-11-04
    相关资源
    最近更新 更多