Assigning elements in Arrays of records

A

a1_nocrap_exh

Is there any technique (other than a for loop) to assign an element in
all records of an array?

Consider a record R defined as follows:

type R is record
flag1 : boolean;
flag2 : boolean;
flag3 : boolean;
end record R;

and an array A of records of type R defined as:

type A is array (0 to 3) of R;

signal flags : A;

To assign flag1 in array element 0 I would do:

flags(0).flag1 <= false;

If I wanted to assign all flag1 elements to false I could use a for
loop

for i in 0 to 3 loop
flags(i).flag1 <= false;
end loop;

Is there anyway to do the same thing using the "others" statement?

Cheers

Alex
 
J

Jonathan Bromley

type R is record
flag1 : boolean;
flag2 : boolean;
flag3 : boolean;
end record R;
type A is array (0 to 3) of R;
signal flags : A;
If I wanted to assign all flag1 elements to false
[...]
You could use an aggregate expression:

A <= (others => (FALSE, FALSE, FALSE));

or, if you prefer,

A <= (others => (flag1 => FALSE, flag2 => FALSE, flag3 => FALSE));

But that would assign to flag2 and flag3 as well. If you want
to assign to only part of the record, I think you have no choice
but to use a procedural loop.

Don't forget that booleans are reliably initialised to FALSE
anyway, without you needing to do anything about it.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
(e-mail address removed)
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
A

a1_nocrap_exh

Jonathan said:
You could use an aggregate expression:

A <= (others => (FALSE, FALSE, FALSE));

But that would assign to flag2 and flag3 as well.

I knew that but I didnt want to assign flag2 & 3.
If you want to assign to only part of the record, I
think you have no choice but to use a procedural loop.

Anyone else got any suggestions?
Don't forget that booleans are reliably initialised to FALSE
anyway, without you needing to do anything about it.

This is a run time problem, not an initialisation time one. I cannot
really use loops because I am in a sequential process. It is only 16
array elements, I'll just write it out long hand. Cut 'n' paste errors
here I come :)

a(0).flag1 <= False;
a(1).flag1 <= False;
.....
.....
a(15).flag1 <= False;

Thanks anyhow.

Alex
 
K

KJ

This is a run time problem, not an initialisation time one. I cannot
really use loops because I am in a sequential process. It is only 16
array elements, I'll just write it out long hand. Cut 'n' paste errors
here I come :)

a(0).flag1 <= False;
a(1).flag1 <= False;
....
....
a(15).flag1 <= False;

Don't cut and paste, you can use put the loop inside your sequential
process
process.
.....
for i in a'range loop
a(i).flag1 <= False;
end loop;
....
end process;

This loop will assign to the 'flag1' elements of each element of 'a'
all in a single pass through the process (presumably this is a process
triggered by rising edge of clock or something).

But to answer your original question, no you can not assign to a single
element of an array of records all in one fell swoop

a(others).flag1 <= False; -- Illegal

And as your reply to Jonathon indicates, in your application you
apparently can't assign to the other elements of the record either so
the loop above is your best approach.

KJ
 
A

Andy

A <= (others => (others => false)); -- assigns every element of every
record

Why can't you use a loop? You said you were in a sequential process;
that's the only place you can use a loop... A loop is nothing more
than a collection of sequential statements, and is completely
synthesizable too, so long as there is no wait statement within it.

For i in a'range loop
a(i).flag1 <= false;
end loop;

is identical to:
a(0).flag1 <= False;
a(1).flag1 <= False;
....
....
a(15).flag1 <= False;

So long as they are both sequential statements.

andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top