Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

concatenation with a for loop

2,172 views
Skip to first unread message

fpgaasicdesigner

unread,
Feb 2, 2010, 4:15:35 PM2/2/10
to
Hi all,

How can I write more with more elegance this:

header={register[0],register[1],register[2]}.

Meaning having a for loop to concatenate these bus ?

Thanks

Cary R.

unread,
Feb 2, 2010, 5:09:23 PM2/2/10
to

localparam max = 2;
for (idx=0; idx<=max; idx=idx+1)
header[(max-idx)*<width> +: <width>] = register[idx];

<width> is the width of the register words.

Cary

John_H

unread,
Feb 2, 2010, 5:15:20 PM2/2/10
to
On Feb 2, 4:15 pm, fpgaasicdesigner <fpgaasicdesig...@gmail.com>
wrote:

A generate statement is the way to go for a wide bus. There really is
no clean way to reverse the order of a bus so the "generate for" will
take care of it in a somewhat better fashion. But if you have few
elements, just write it out. Even 16 elements can come out clean with
4 rows of 4 elements each all lined up under each other in a visible
grid.

header <= { register[ 0], register[ 1], register[ 2], register[ 3]
, register[ 4], register[ 5], register[ 6], register[ 7]
, register[ 8], register[ 9], register[10], register[11]
, register[12], register[13], register[14], register
[15] };

It's possible to use bit manipulation or perhaps the width syntax

header[n] <= register[ n-1 :+ 1 ];

to use a normal for loop but things really start to look unclear to
the reader.

John_H

unread,
Feb 2, 2010, 5:16:20 PM2/2/10
to
On Feb 2, 5:15 pm, John_H <newsgr...@johnhandwork.com> wrote:
>
>   header[n] <= register[ n-1 :+ 1 ];

Oops...
Make that register[ 15-n :+ 1 ]

John_H

unread,
Feb 2, 2010, 5:17:41 PM2/2/10
to

Ans as Cary pointed out, it's +: not :+

I guess the day's gotten the better of me.

fpgaasicdesigner

unread,
Feb 2, 2010, 7:16:09 PM2/2/10
to

thanks guys, that works with
header[idx*WIDTH +: WIDTH] <= register[idx]

Cary R.

unread,
Feb 2, 2010, 7:34:58 PM2/2/10
to
fpgaasicdesigner wrote:

> thanks guys, that works with
> header[idx*WIDTH +: WIDTH] <= register[idx]

except this gives you:

header = {register[2], register[1], register[0]};

not

header = {register[0], register[1], register[2]};

like you originally asked for. I'm just noting a discrepancy. What
matters is that it is working like you expect.

Cary

fpgaasicdesigner

unread,
Feb 2, 2010, 9:09:14 PM2/2/10
to

correct... you know it's never in the sense/direction you wanted 2,1,0
or 0,1,2 whatever or 1'b1 instead of been 1'b0 whatever lol
binary digital is funny if you don't have a 1 you will have a 0, so it
never can been wrong ?

thanks guys for the fast answers
and I didn't know this syntax +:, very interesting syntax...

fpgaasicdesigner

unread,
Feb 2, 2010, 9:12:59 PM2/2/10
to
On Feb 2, 5:15 pm, John_H <newsgr...@johnhandwork.com> wrote:

and I didn't used an array structure cause it goes to an output I/O of
a module. That cannot be done in Verilog, that's annoying sometimes
and there's no difference in the synthesized result for an array or a
vector, cause an vector is a just a one dimension array... I was able
to do it in VHDL. Perhaps System Verilog is able to do that ?

Jonathan Bromley

unread,
Feb 3, 2010, 5:11:55 AM2/3/10
to
On Tue, 2 Feb 2010 18:12:59 -0800 (PST), fpgaasicdesigner wrote:

>and I didn't used an array structure cause it goes to an output I/O of
>a module. That cannot be done in Verilog, that's annoying sometimes
>and there's no difference in the synthesized result for an array or a
>vector, cause an vector is a just a one dimension array... I was able
>to do it in VHDL.

Yes, VHDL has always been a much more expressive language
for synthesisable designs. Only now is SystemVerilog
beginning to catch up.

> Perhaps System Verilog is able to do that ?

Yes, it is. Ports can be of any array type, and all the
new user-definable data types (struct, union, enum) can
also go on ports. At last!

And the great majority of mainstream tools now fully
support that part of SystemVerilog for both simulation
and synthesis.
--
Jonathan Bromley

0 new messages