Syntax error in Verilog task

V

Verictor

Guest
Hi,

What is wrong with the integer i defined in the following task?

task delimited_out;
input [width-1:0] a; // width has been defined
somewhere else
input delimiter_width;
integer i;
begin
for (i = 1; i <= width/delimiter_width; i = i + 1)
begin
$display("the delimited_out is %b_", a[width-
delimiter*(i-1)-1 : width-delimiter*i]);
end
end
endtask


Compiler complains that "Illegal operand for constant expression for
i".

Thanks
 
"Verictor" <stehuang@gmail.com> wrote in message
news:1177602837.351398.89640@r3g2000prh.googlegroups.com...
Hi,

What is wrong with the integer i defined in the following task?

task delimited_out;
input [width-1:0] a; // width has been defined
somewhere else
input delimiter_width;
integer i;
begin
for (i = 1; i <= width/delimiter_width; i = i + 1)
begin
$display("the delimited_out is %b_", a[width-
delimiter*(i-1)-1 : width-delimiter*i]);
end
end
endtask


Compiler complains that "Illegal operand for constant expression for
i".

Thanks
The problem is with the a[width-delimiter*(i-1)-1 : width-delimiter*i]
syntax.
While it looks like it should work by providing a constant width, it's not
valid Verilog.

It also appears you intend to use "delimiter_width" rather than "delimiter."

Verilog2001 allows a syntax that will probably work in your case:

a[width-delimiter*i +: delimiter_width]

The constant width expression - delimeter_width - is now obvious to the
Verilor2001 synthesizer and no syntax errors should be flagged. If this
form is not acceptable to you, insert a second loop to do the bit
assignments one by one, not specifying ranges.

- John_H
 
On Apr 26, 12:51 pm, "John_H" <newsgr...@johnhandwork.com> wrote:
"Verictor" <stehu...@gmail.com> wrote in message

news:1177602837.351398.89640@r3g2000prh.googlegroups.com...



Hi,

What is wrong with the integer i defined in the following task?

task delimited_out;
input [width-1:0] a; // width has been defined
somewhere else
input delimiter_width;
integer i;
begin
for (i = 1; i <= width/delimiter_width; i = i + 1)
begin
$display("the delimited_out is %b_", a[width-
delimiter*(i-1)-1 : width-delimiter*i]);
end
end
endtask

Compiler complains that "Illegal operand for constant expression for
i".

Thanks

The problem is with the a[width-delimiter*(i-1)-1 : width-delimiter*i]
syntax.
While it looks like it should work by providing a constant width, it's not
valid Verilog.

It also appears you intend to use "delimiter_width" rather than "delimiter."

Verilog2001 allows a syntax that will probably work in your case:

a[width-delimiter*i +: delimiter_width]

The constant width expression - delimeter_width - is now obvious to the
Verilor2001 synthesizer and no syntax errors should be flagged. If this
form is not acceptable to you, insert a second loop to do the bit
assignments one by one, not specifying ranges.

- John_H

or perhaps a little more readable?

for (i = delimiter_width; i <= width ; i = i + delimiter_width)

.. . . a[i +: delimiter_width] . . .
 
On Apr 26, 2:00 pm, gabor <g...@alacron.com> wrote:
On Apr 26, 12:51 pm, "John_H" <newsgr...@johnhandwork.com> wrote:





"Verictor" <stehu...@gmail.com> wrote in message

news:1177602837.351398.89640@r3g2000prh.googlegroups.com...

Hi,

What is wrong with the integer i defined in the following task?

task delimited_out;
input [width-1:0] a; // width has been defined
somewhere else
input delimiter_width;
integer i;
begin
for (i = 1; i <= width/delimiter_width; i = i + 1)
begin
$display("the delimited_out is %b_", a[width-
delimiter*(i-1)-1 : width-delimiter*i]);
end
end
endtask

Compiler complains that "Illegal operand for constant expression for
i".

Thanks

The problem is with the a[width-delimiter*(i-1)-1 : width-delimiter*i]
syntax.
While it looks like it should work by providing a constant width, it's not
valid Verilog.

It also appears you intend to use "delimiter_width" rather than "delimiter."

Verilog2001 allows a syntax that will probably work in your case:

a[width-delimiter*i +: delimiter_width]

The constant width expression - delimeter_width - is now obvious to the
Verilor2001 synthesizer and no syntax errors should be flagged. If this
form is not acceptable to you, insert a second loop to do the bit
assignments one by one, not specifying ranges.

- John_H

or perhaps a little more readable?

for (i = delimiter_width; i <= width ; i = i + delimiter_width)

. . . a[i +: delimiter_width] . . .- Hide quoted text -

- Show quoted text -
what simulators are you guys running? I used the two versions you
suggested above but still get "Illegal operand for constant
expression" on delimiter_width (both codes). I am using NC-Verilog.
 
"Verictor" <stehuang@gmail.com> wrote in message
news:1177686916.625055.75720@t39g2000prd.googlegroups.com...
On Apr 26, 2:00 pm, gabor <g...@alacron.com> wrote:
On Apr 26, 12:51 pm, "John_H" <newsgr...@johnhandwork.com> wrote:
"Verictor" <stehu...@gmail.com> wrote in message
news:1177602837.351398.89640@r3g2000prh.googlegroups.com...

Hi,

What is wrong with the integer i defined in the following task?

task delimited_out;
input [width-1:0] a; // width has been defined
somewhere else
input delimiter_width;
integer i;
begin
for (i = 1; i <= width/delimiter_width; i = i + 1)
begin
$display("the delimited_out is %b_", a[width-
delimiter*(i-1)-1 : width-delimiter*i]);
end
end
endtask

Compiler complains that "Illegal operand for constant expression for
i".

Thanks

The problem is with the a[width-delimiter*(i-1)-1 : width-delimiter*i]
syntax.
While it looks like it should work by providing a constant width, it's
not
valid Verilog.

It also appears you intend to use "delimiter_width" rather than
"delimiter."

Verilog2001 allows a syntax that will probably work in your case:

a[width-delimiter*i +: delimiter_width]

The constant width expression - delimeter_width - is now obvious to the
Verilor2001 synthesizer and no syntax errors should be flagged. If
this
form is not acceptable to you, insert a second loop to do the bit
assignments one by one, not specifying ranges.

- John_H

or perhaps a little more readable?

for (i = delimiter_width; i <= width ; i = i + delimiter_width)

. . . a[i +: delimiter_width] . . .- Hide quoted text -

- Show quoted text -

what simulators are you guys running? I used the two versions you
suggested above but still get "Illegal operand for constant
expression" on delimiter_width (both codes). I am using NC-Verilog.

Is the delimeter_width a constant? If so, the value should not be an
"input" as shown in your port list but a "parameter" instead.

If you're not dealing with a constant, you may be able to get where you want
to be by coding bit by bit but the logic feeding into any one bit will be
gnarly: not pretty. A constant value is probably what you want which will
make the coding clean. I certainly prefer gabor's readability compared to
the original form of the code.

- John_H
 

Welcome to EDABoard.com

Sponsor

Back
Top