Assigning elements in Arrays of records

Discussion in 'VHDL' started by a1_nocrap_exh@hotmail.com, Sep 11, 2006.

  1. Guest

    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
    , Sep 11, 2006
    #1
    1. Advertising

  2. On 11 Sep 2006 02:57:18 -0700, 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

    http://www.MYCOMPANY.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Sep 11, 2006
    #2
    1. Advertising

  3. Guest

    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
    , Sep 11, 2006
    #3
  4. KJ Guest

    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
    KJ, Sep 11, 2006
    #4
  5. Andy Guest

    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
    Andy, Sep 11, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Airig
    Replies:
    0
    Views:
    774
    Luke Airig
    Dec 31, 2003
  2. Philipp
    Replies:
    21
    Views:
    1,109
    Philipp
    Jan 20, 2009
  3. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    454
    Ray at
    May 10, 2004
  4. Replies:
    3
    Views:
    645
    Anthony Jones
    Nov 2, 2006
  5. weston
    Replies:
    1
    Views:
    239
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page