Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Assigning elements in Arrays of records

Reply
Thread Tools

Assigning elements in Arrays of records

 
 
a1_nocrap_exh@hotmail.com
Guest
Posts: n/a
 
      09-11-2006
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

 
Reply With Quote
 
 
 
 
Jonathan Bromley
Guest
Posts: n/a
 
      09-11-2006
On 11 Sep 2006 02:57:18 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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 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.
 
Reply With Quote
 
 
 
 
a1_nocrap_exh@hotmail.com
Guest
Posts: n/a
 
      09-11-2006

Jonathan Bromley wrote:
> 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

 
Reply With Quote
 
KJ
Guest
Posts: n/a
 
      09-11-2006
(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      09-11-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Simple query returns 0 records in asp, but all records in vbscript masg0013@gmail.com ASP General 3 11-02-2006 09:23 AM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
Delete records or update records Dan ASP General 1 05-10-2004 01:25 PM
match muliple header records to associated detail records Luke Airig XML 0 12-31-2003 12:06 AM



Advertisments