Search code examples
vhdlmultiplicationexponent

Multiplication with a variable in VHDL


OK guys I need this for my lab assignment. In a part of the project, I have to do this:

M*(2^E) where m is M2 M1 M0 3-bit number and e is E1 E0 2 bit number

I know that we add zeros to the end of the number while multiplying with 2 but the number 'E' is not constant.

I just want to know the way to do that

Language: VHDL * I am not allowed to use 'behavioral' architecture

Thank you!


Solution

  • I won't give you a full solution, as it would defeat the purpose of the lab...

    You know that you add a zero to the end of the number when multiplying by 2, I'm sure you can also figure out how many zeros to add as E1E0 goes from 0 to 3. Since there is only 4 cases, it would be easy to simply list all the cases:

    with e select
        output <= "000" & m when "00",
                  something when "01",
                  something when "10",
                  something when others;
    

    You may or may not have seen this syntax in your classes. This goes in your architecture body, outside of a process. Inside a process, you would use a case statement instead.