Verilog error - can`t find solution

Guest #4103318
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 #4103526
I can not add a clock in this. I must somehow count the output 
(nr_black) whenever i find out that nr is higher or equal than 2. I 
can`t add a clock. I need to do this without a CLK
Guest #4103575
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 #4103625
Done! Now this error showed up:

"Target <nr_black> of concurrent assignment or output port connection 
should be a net type." on line 28

Line 28: assign nr_black = 4'b0000;
Guest #4103703
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
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.
Guest #4105099
Yet, i can`t make it work. I made it reg / wire, added another wire to 
count and then assign the output = counter. Nothing works...

Reply

A question of your own? This thread is over 11 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

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.