concatenation with a for loop

  • Thread starter fpgaasicdesigner
  • Start date
F

fpgaasicdesigner

Guest
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
 
fpgaasicdesigner wrote:
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
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
 
On Feb 2, 4:15 pm, fpgaasicdesigner <fpgaasicdesig...@gmail.com>
wrote:
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
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.
 
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 ]
 
On Feb 2, 5:16 pm, John_H <newsgr...@johnhandwork.com> wrote:
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 ]
Ans as Cary pointed out, it's +: not :+

I guess the day's gotten the better of me.
 
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
 
On Feb 2, 5:17 pm, John_H <newsgr...@johnhandwork.com> wrote:
On Feb 2, 5:16 pm, John_H <newsgr...@johnhandwork.com> wrote:

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 ]

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

I guess the day's gotten the better of me.
thanks guys, that works with
header[idx*WIDTH +: WIDTH] <= register[idx]
 
On Feb 2, 7:34 pm, "Cary R." <no-s...@host.spam> wrote:
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
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...
 
On Feb 2, 5:15 pm, John_H <newsgr...@johnhandwork.com> wrote:
On Feb 2, 4:15 pm, fpgaasicdesigner <fpgaasicdesig...@gmail.com
wrote:

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

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.
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 ?
 
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
 

Welcome to EDABoard.com

Sponsor

Back
Top