summing of array elements in for loop

Discussion in 'VHDL' started by antsor, Feb 12, 2012.

  1. antsor


    Feb 12, 2012
    Likes Received:
    How can I sum an array of vectors in a for loop? If e.g. I would have a type

    type tab is array(my_size downto 0) of STD_LOGIC_VECTOR(3 DOWNTO 0);
    signal s : tab;

    and I want to do a sum that would be equivalent to this:

    dout <= s(0) + s(1) + s(2) + s(3) ....

    but how can I do that in a for loop? Of course I could use a variable:

    for N in my_size-1 downto 0 loop
    temp_var := temp_var + s(N);
    end loop;

    but how is it possible without using a variable?
    antsor, Feb 12, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.