Verilog: Can you put “assign” statements within always@ or begin/end statements?

后端 未结 7 1995
北海茫月
北海茫月 2020-12-18 10:34

Is this allowed?

input w;
     input [8:0]y;
     output reg [8:0]x;
     always@(w)
     begin


     //x[0] or A is never on in any next state
     as         


        
相关标签:
7条回答
  • 2020-12-18 10:50

    The procedural continuous assign statement was intended to be an optimized way of writing a mux-like behavior. For example, if you have

    always @(A or B or select)
      if (select)
        out = A;
      else
        out = B;
    

    You could write this as

    always @(select)
       assign out = A;
     else 
       assign out = B;
    

    But people don't like having to deal with sensitivity lists, so @(*) was added to Verilog, and SystemVerilog added always_comb.

    But the real killer for this construct is that many people would write code like

    always @(*)
       assign out = A;
    

    Which simulates fine, but you now have a double penalty in performance because the assign statement is already sensitive to changes in A, but so is the always block. This repeatedly executes the procedural assign statement replacing the same RHS.

    0 讨论(0)
  • 2020-12-18 10:51
    1. Thinking from the circuit level: this always(w) begin ..... end , so every code inside it will be activated whenever w is changed ie it falls or raise .
    2. assign statement requires pin/port which it assign to some wire or reg output
    3. its a complete combinational circuit I am unable to see how the same will only activate at w, that is who/what circuit will make it to only change when w either rises or fall
    4. anyway you cant assign a reg output to some wire/reg output using assign statement because as I said it requires you to put pin/port to be assigned only
    5. anyway if you go for basic verilog and not so called "Procedural Continuous Assignment" i guess its weird to use the same .
    0 讨论(0)
  • 2020-12-18 10:52

    You can, it's called a "Procedural Continuous Assignment". It overrides ordinary procedural assignments, there doesn't seem to be a call for them in the code you've posted. I'm not sure if they're synthesisable, but I never have cause to use them anyway.

    A note on your code - you're missing y from your sensitivity list: eg always @( w or y ) or always @(*) is safer.

    0 讨论(0)
  • 2020-12-18 11:02

    There is no need using assign inside a procedural block (In this case Always)

    Assign is a continuous assignment, and it has to go outside a procedural block.

    0 讨论(0)
  • 2020-12-18 11:07

    Yes, but you don't want to. Since x[] doesn't depend on x[] the order doesn't matter. Just use <= instead of assign =.

    0 讨论(0)
  • 2020-12-18 11:09

    Assign is a continuous assignment statement which is used with wires in Verilog. assign statements don't go inside procedural blocks such as always. Registers can be given values in an always block.

    Assign statements can be viewed as:

     always @(*)
    

    statements for wires.

    0 讨论(0)
提交回复
热议问题