Making a 4-bit ALU from several 1-bit ALUs

前端 未结 2 1438
感情败类
感情败类 2021-01-27 05:56

I\'m trying to combine several 1 bit ALUs into a 4 bit ALU. I am confused about how to actually do this in VHDL. Here is the code for the 1bit ALU that I am using:



        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 06:44

    Interesting you would even ask that question. VHDL synthesizers are quite capable of inferring any adder you like. You can just type what you need:

    use ieee.numeric_std.all;
    ...
    signal r : unsigned(3 downto 0);
    signal a : unsigned(2 downto 0);
    signal b : unsigned(2 downto 0);
    signal c : unsigned(2 downto 0);
    ...
    r  <=  a + b + c;
    

    Then you can slice r to fit your needs:

    result  <=  std_logic_vector(r(2 downto 0));
    

提交回复
热议问题