简体   繁体   English

为什么导线变量导致连续分配中的非法左侧?

[英]Why is wire variable causing illegal left-hand side in continuous assignment?

I have read through all similar posts, but none address the issue I'm having, namely that line 41 assign Y[b]=~Y[b]; 我已经阅读了所有类似的帖子,但是都没有解决我遇到的问题,即第41行assign Y[b]=~Y[b]; causes error "Illegal left-hand side in continuous assignment." 导致错误“连续分配中非法的左侧”。

I haven't assigned any regs so I don't see what the issue is. 我没有分配任何注册表,所以我看不出问题是什么。 If I replace b with an actual number (say, 3) it works fine. 如果我将b替换为实际数字(例如3),则可以正常工作。 But I need b as a variable here. 但是我需要b作为变量。

// Hamming code 1-bit error correction
module HCG(I,e,O);
  input [4:1] I;   // input BCD
  input [7:1] e;   // noise simulation
  wire [7:1] X;    // Hamming code
  wire [7:1] Y;     // Hamming code after addition of noise
  wire [3:1] P;     // Parity at start
  wire [3:1] S;    // Parity at end
  wire b;        // the error bit
  output [4:1] O;  // corrected output


  assign X[1]=I[1]^I[2]^I[4];   // Hamming code generator
  assign X[2]=I[1]^I[3]^I[4];
  assign X[3]=I[1];
  assign X[4]=I[2]^I[3]^I[4];
  assign X[5]=I[2];
  assign X[6]=I[3];
  assign X[7]=I[4];

  assign P[1]=X[1]; // Parity at start
  assign P[2]=X[2];
  assign P[3]=X[4];

  assign Y[1]=e[1]^X[1]; // noise added
  assign Y[2]=e[2]^X[2];
  assign Y[3]=e[3]^X[3];
  assign Y[4]=e[4]^X[4];
  assign Y[5]=e[5]^X[5];
  assign Y[6]=e[6]^X[6];
  assign Y[7]=e[7]^X[7];

  assign S[1]=Y[3]^Y[5]^Y[7]; // Parity at end
  assign S[2]=Y[3]^Y[6]^Y[7];
  assign S[3]=Y[5]^Y[6]^Y[7];

  assign b=(S[1]!=P[1])? b:b+1; // if parity of 2^0 not the same, add 1 to b
  assign b=(S[2]!=P[2])? b:b+2; // if parity of 2^1 not the same, add 2 to b
  assign b=(S[3]!=P[3])? b:b+4; // if parity of 2^2 not the same, add 4 to b

  assign Y[b]=~Y[b]; // correct the incorrect bit
  assign O[1]=Y[3]; // assigning outputs
  assign O[2]=Y[5];
  assign O[3]=Y[6];
  assign O[4]=Y[7];

endmodule

The lines between module and endmodule are executed concurently . moduleendmodule之间的行是并发执行的。 (It seems like you think they are executed sequentially.) Therefore, you are driving all the bits of Y in these lines (似乎您认为它们是按顺序执行的。)因此,您正在驱动这些行中Y所有位

  assign Y[1]=e[1]^X[1]; // noise added
  assign Y[2]=e[2]^X[2];
  assign Y[3]=e[3]^X[3];
  assign Y[4]=e[4]^X[4];
  assign Y[5]=e[5]^X[5];
  assign Y[6]=e[6]^X[6];
  assign Y[7]=e[7]^X[7];

and then are driving one of the bits of Y again in this line: 然后在这一行中再次驱动Y的位之一:

  assign Y[b]=~Y[b]; // correct the incorrect bit

So (a) you have a short circuit and (b) which bit has the short circuit? 那么(a)您有短路,并且(b)哪位有短路? That depends on b . 这取决于b So, the position of the short circuit depends on the state of one of the internal wires. 因此,短路的位置取决于内部导线之一的状态。 You have described a circuit that can reconfigure itself depending on its inputs. 您已经描述了可以根据输入重新配置的电路。 Verilog won't let you do that. Verilog不允许您这样做。 Verilog is a hardware description language . Verilog是一种硬件描述语言 Conventional digital hardware can't reconfigure itself depending on the state of its inputs. 常规的数字硬件无法根据其输入状态重新配置自身。

The problem is the continuous assignment you are doing. 问题是您正在执行连续作业。 To quote from the IEEE Std 1800-2012. 引用IEEE Std 1800-2012。 (Section 10.3) on continuous assignments: (第10.3节)关于连续作业:

Continuous assignments shall drive values onto nets or variables, both vector (packed) and scalar. 连续分配应将值驱动到矢量(打包的)和标量的网络或变量上。 This assignment shall occur whenever the value of the right-hand side changes. 只要右侧的值发生变化,就应进行此分配。 Continuous assignments provide a way to model combinational logic without specifying an interconnection of gates. 连续分配提供了一种在不指定门互连的情况下对组合逻辑建模的方法。

When you do assign Y[b]=~Y[b] , the assignment itself automatically causes the right-hand side to change again, which triggers the assignment again. 当您确实assign Y[b]=~Y[b] ,分配本身会自动导致右侧再次更改,从而再次触发分配。

Verilog standard lists legal lhs values for the continuous assignment as the following (Table 10-1): Verilog标准列出了连续分配的合法lhs值,如下所示(表10-1):

Net or variable (vector or scalar) 净或变量(向量或标量)

Constant bit-select of a vector net or packed variable 向量网络或压缩变量的恒定位选择

Constant part-select of a vector net or packed variable 向量网络或压缩变量的恒定部分选择

Concatenation or nested concatenation of any of the above left-hand sides 上述任何左侧的串联或嵌套串联

in your case Y[b] is not a constant selection, because b is not a constant. 在您的情况下, Y[b]不是常数选择,因为b不是常数。 Therefore syntactically your lhs is illegal and you get this message from the compiler. 因此,从语法上讲,您的lhs是非法的,并且您从编译器获得此消息。

On a side note you have a zero-delay loop here. 附带说明一下,这里有一个零延迟循环。 See other answers for explanation. 请参阅其他答案以获取解释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Verilog错误:连续分配左侧的寄存器非法 - Verilog error: Register is illegal in left-hand side of continuous assignment 连续分配的左侧是非法的 - The left-hand-side of continuous assignment is illegal Verilog HDL错误:左侧分配非法 - Verilog HDL error: Illegal left-hand side assignment Verilog:作业左侧必须具有可变数据类型 - Verilog: on left-hand side of assignment must have a variable data type Verilog错误:分配左侧的对象必须具有可变数据类型 - Verilog Error: Object on left-hand side of assignment must have a variable data type 封锁作业的左侧无效 - Illegal left hand side of blocking assignment 错误(10219):Mux.v处的Verilog HDL连续分配错误(19):分配左侧的对象“ muxout”必须具有网络类型 - Error (10219): Verilog HDL Continuous Assignment error at Mux.v(19): object “muxout” on left-hand side of assignment must have a net type 不允许对非寄存器 shifty 进行程序分配,左侧应该是 reg/integer/time/genvar——这是我得到的错误 - Procedural assignment to a non-register shiftedy is not permitted, left-hand side should be reg/integer/time/genvar -- this is the error I am getting 为什么在内部不允许赋值给wire数据类型变量总是在verilog中阻塞? - Why assignment to wire datatype variable not allowed inside always block in verilog? 如何修复“错误-[IBLHS-NT] 左侧非法行为”? - How do I fix “Error-[IBLHS-NT] Illegal behavioral left hand side”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM