He codificado un sumador simple de 4 bits con signo. No tiene carry in ni carry out, por lo que fácilmente se desborda. A continuación puedes ver mi código.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity four_bit_adder_simple is
port(
A, B : in std_logic_vector(3 downto 0);
Sum : out std_logic_vector(3 downto 0));
end four_bit_adder_simple;
architecture signed_impl of four_bit_adder_simple is
begin
sum <= std_logic_vector(signed(A) + signed(B));
end signed_impl;
Mapeo de puertos:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity four_bit_adder_tester is
port(
SW : in std_logic_vector(7 downto 0);
LEDR : out std_logic_vector(3 downto 0));
end four_bit_adder_tester;
architecture tester_impl of four_bit_adder_tester is
begin
i1: entity work.four_bit_adder_simple(signed_impl)
port map(
A => SW(3 downto 0),
B => SW(7 downto 4),
Sum => LEDR(3 downto 0)
);
end architecture;
¿Cómo puedo añadir un carry-in y un carry-out usando la función resize para cambiar el tamaño de bits de los vectores antes de sumarlos?