Verilog error - can`t find solution

Guest #4103318
Rate this post
• ▲ useful
▼ not useful
I have this code:
1
`timescale 1ns / 1ps
2

3
module blacks(input [31:0] b, 
4
    input left,
5
    output [3:0] nr_black);
6

7
integer i = 0;
8
integer nr;
9
assign nr_black = 4'b0000;
10

11
always @ (*) begin
12
  if(left==0)
13
  begin  
14
    while (i < 31)
15
    begin
16
      if (b[i] == 0)
17
        i=i+1;
18
      else
19
      begin
20
        nr=0;
21
        while (b[i] == 1)
22
        begin
23
          i=i+1;
24
          nr=nr+1;
25
        end
26
        if (nr >= 2)
27
          nr_black = nr_black + 4'b0001;
28
      end
29
    end
30
  end
31
  else;
32
end
33

34
endmodule

It gives me this error: "Procedural assignment to a non-register 
nr_black is not permitted, left-hand side should be 
reg/integer/time/genvar" on line 46

line 46 is this one: nr_black = nr_black + 4'b0001. How can i fix this 
program?

My nr_black is the output on 4 bits, and whenever nr is higher or equal 
than 2, i want to increment nr_black with 1. How do i do that? TY
Guest #4103575
Rate this post
• ▲ useful
▼ not useful
Your Code:
>output [3:0] nr_black);
The Errormessage:
>It gives me this error: "Procedural assignment to a non-register
>nr_black is not permitted, left-hand side should be
>reg/integer/time/genvar" on line 46

Just do what the error mesage says:

output reg [3:0] nr_black);
Guest #4103703
Rate this post
• ▲ useful
▼ not useful
I tried to make nr_black wire, and then initialize a wire [3:0] counter.

And when nr>=2 counter = counter + 1. And at the end: assign nr_black = 
counter.

but it gives me this error: Procedural assignment to a non-register 
counter is not permitted, left-hand side should be 
reg/integer/time/genvar

I can`t figure it out...
(Company: Ha Noi- Vietnam) #4104861
Rate this post
• ▲ useful
▼ not useful
Hi  Alexandru Chiser !

you only edit "output [3:0] nr_black" into "output reg  [3:0] nr_black"

your code when compiled it make circuit combination, but you used " 
alway" so output you is used, it used in "always" must be " reg" not 
"wire". My english is not good, that i written make you difficult 
understand, if you want to call me, skype: tv_long.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.