Hello I am trying to create a 16-bit ALU from several 1-bit ALUs I created a package named basic_alu1 which contains a component of the 1-bit ALU.The code for this is:
library ieee;
use ieee.std_logic_1164.all;
package basic_alu1 is
component alu1
port (a, b: std_logic_vector(1 downto 0);
m: in std_logic_vector(1 downto 0);
result: out std_logic_vector(1 downto 0));
end component;
end package basic_alu1;
library ieee;
use ieee.std_logic_1164.all;
entity alu1 is
port (a, b: std_logic_vector(1 downto 0);
m: in std_logic_vector(1 downto 0);
result: out std_logic_vector(1 downto 0));
end alu1;
architecture arch1 of alu1 is
begin
process(a, b, m)
begin
case m is
when "00" =>
result <= a + b;
when "01" =>
result <= a + (not b) + 1;
when "10" =>
result <= a and b;
when "11" =>
result <= a or b;
end case
end process
end arch1
So, in order to create the 16 bit ALU I am using a for generate loop and instantiate multiple copies of alu1. My question is how can I take the counter in and counter out and how can I have an overflow check. My main code is :
library ieee;
use ieee.std_logic_1164.all;
use work.basic_alu1.all;
entity alu16 is
port (input_a : in std_logic_vector(15 downto 0);
input_b : in std_logic_vector(15 downto 0);
mode : in std_logic_vector(1 downto 0)
result_x4 : out std_logic);
end alu16;
architecture structural of alu16 is
begin
G1 : for i in 0 to 15 generate
begin
alu_16 : entity work.basic_alu1
port map (
a => input_a(i),
b => input_b(i),
m => mode,
result => result_x4(i));
end generate;
Here is an example of how you can create a N-bit adder component. First of all you need to create a full adder which is a adder that also takes a carry in bit into account.
When you have this 1-bit adder you can easily generate a N-bit ripple carry by generating multiple cells of the full adder we have above.
When you have the adder you can easily put the adder component into an ALU and specify the different operations that the ALU should be able to perform.
This ALU however is not that complex and don´t have that many operations but that functionality can easily be added. I hope the example code I have given you will help you.