Search code examples
vhdl

Is there a way to create a loop inside a case statement on vhdl?


I would like to know if there is a way to create a loop inside a case statement in vhdl.

Currently I have this code

    CASE A1 IS 
        WHEN "00000" => RD1 <= REG0;
        WHEN "00001" => RD1 <= REG1;
        WHEN "00010" => RD1 <= REG2;
        WHEN "00011" => RD1 <= REG3;
        WHEN "00100" => RD1 <= REG4;
        WHEN "00101" => RD1 <= REG5;
        WHEN "00110" => RD1 <= REG6;
        WHEN "00111" => RD1 <= REG7;
        WHEN "01000" => RD1 <= REG8;
        WHEN "01001" => RD1 <= REG9;
        WHEN "01010" => RD1 <= REG10;
        WHEN "01011" => RD1 <= REG11;
        WHEN "01100" => RD1 <= REG12;
        WHEN "01101" => RD1 <= REG13;
        WHEN "01110" => RD1 <= REG14;
        WHEN "01111" => RD1 <= REG15;
        WHEN "10000" => RD1 <= REG16;
        WHEN "10001" => RD1 <= REG17;
        WHEN "10010" => RD1 <= REG18;
        WHEN "10011" => RD1 <= REG19;
        WHEN "10100" => RD1 <= REG20;
        WHEN "10101" => RD1 <= REG21;
        WHEN "10110" => RD1 <= REG22;
        WHEN "10111" => RD1 <= REG23;
        WHEN "11000" => RD1 <= REG24;
        WHEN "11001" => RD1 <= REG25;
        WHEN "11010" => RD1 <= REG26;
        WHEN "11011" => RD1 <= REG27;
        WHEN "11100" => RD1 <= REG28;
        WHEN "11101" => RD1 <= REG29;
        WHEN "11110" => RD1 <= REGZLO;
        WHEN "11111" => RD1 <= REGZHI;
        WHEN OTHERS => RD1 <= (OTHERS => '0');
     END CASE; 

As you can see the only thing that changes from one statement to the next is the number of the REG asigned to RD1. Couldn't the fact that it always matches the value of A1 (except on the last 2 cases but those can be done separately) be used to make a loop so that all the statements don't have to be written?

Thank you.


Solution

  • Is there a way to create a loop inside a case statement

    No, you can not, at least not in the way I think you want to do it.

    It would not make sense because if you can use a loop you can use the loop variable as selector/index or you can derive the value from it.

    A case is intended for non-regular and/or sparse selection.


    You can of course place a loop inside a case like this:

    WHEN "01100" => for ...
    

    But I am pretty sure that is not what you where referring to.