Verilog error: not a valid l-value

前端 未结 2 1459
花落未央
花落未央 2021-01-28 06:17

I\'m trying to test if a wire(s) is on or not to signify if there is an error/overflow in my alu code. Given this code:

output reg[3:0]x;                                


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-28 07:03

    The code in the example has several issues.

    1) you tried to use 'procedural assignments' which is an advanced verilog topic. In other words assign statement inside of an always block. This is not synthesizable, can only be used on reg types, and is there in verilog for very special cases. Do not use it.

    You error messages coming from the fact that error and overflow are declared as wire.

    2) you are trying to assign inverted version of a value to itself in a non-clocked logic. It will not behave the way you expect. Depending on usage it can either not toggle or will cause an infinite zero-delay loop, or in your case it could just generate a glitch.

    So, potentially, your code should look something like the following:

    input wire clk; // << you need clock
    output reg[3:0]x;                       // line 149
    output wire error;
    output wire overflow;
    
    reg error_reg, overflow_reg; 
    
     always @(posedge clk) begin
        if(error || overflow) begin         
            x <= 4'b1111;             // line 155
            error_reg <= ~error;
            overflow_reg <= ~overflow;
        end else begin
            x <= opcode;
        end
     assign error = error_reg;
     assign overflow = overflow_reg;
    end
    

提交回复
热议问题