为什么连线变量在连续赋值中导致非法左侧? [英] Why is wire variable causing illegal left-hand side in continuous assignment?
问题描述
我已经通读了所有类似的帖子,但没有一个解决我遇到的问题,即第 41 行 assign Y[b]=~Y[b];
导致错误Illegal left-手边连续分配."
I have read through all similar posts, but none address the issue I'm having, namely that line 41 assign Y[b]=~Y[b];
causes error "Illegal left-hand side in continuous assignment."
我没有分配任何注册,所以我不知道问题是什么.如果我用实际数字(例如 3)替换 b
它工作正常.但我需要 b
作为这里的变量.
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. But I need b
as a variable here.
// 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
推荐答案
module
和 endmodule
之间的行并发执行.(似乎您认为它们是按顺序执行的.)因此,您正在驱动这些行中 Y
的所有位
The lines between module
and endmodule
are executed concurently. (It seems like you think they are executed sequentially.) Therefore, you are driving all the bits of Y
in these lines
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];
然后在这一行中再次驱动 Y
的一个位:
and then are driving one of the bits of Y
again in this line:
assign Y[b]=~Y[b]; // correct the incorrect bit
所以(a)你有短路和(b)哪个位有短路?这取决于b
.因此,短路的位置取决于其中一根内部导线的状态.您已经描述了一个可以根据其输入重新配置自身的电路.Verilog 不会让你这样做.Verilog 是一种硬件描述语言.传统的数字硬件无法根据其输入的状态重新配置自身.
So (a) you have a short circuit and (b) which bit has the short circuit? That depends on 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 is a hardware description language. Conventional digital hardware can't reconfigure itself depending on the state of its inputs.
这篇关于为什么连线变量在连续赋值中导致非法左侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!