Common Mistakes in Verilog
Common Mistakes in Verilog
2. Missing semi-colon, {}
3. Accidental assignment
always @(w0, w1, s)
if ( s = 1 )------------------------- s==1 , should have used logical operator
f = w1; f = w0;
always @(x)--------- y not included, the change of y will not reflect on s,c
begin
s = x ∧ y;
c = x & y;
end
Always blocks are concurrent with one another. So a variable should not be
assigned value in more than one always blocks
is syntactically correct.
always @(X)
begin
integer k; Count = 0;
for (k = 0; k < n; k = k+1) Count = Count + X[k];
end
always @(X)
begin: label
integer k; Count = 0;
for (k = 0; k < n; k = k+1) Count = Count + X[k];
end
is syntactically correct.
11. Implied Memory
always @(LA)
if (LA == 1)
EA = 1;
results in implied memory for the EA variable. If this is not desired, then the code can
be fixed by writing
always @(LA)
if (LA == 1)
EA = 1;
else
EA = 0;
does not specify the value of the EA variable when W is not equal to 01, and it does
not specify the value of EB when W is not equal to 10. To avoid having implied
memory for both EA and EB, these variables should be assigned default values, as in
the code
always @(W)
begin
EA = 0; EB = 0;
case (W)
2’b01: EA = 1;
2’b10: EB = 1;
endcase
end