Files
IEEE754Adder/TwoComplement.vhd

55 lines
922 B
VHDL
Raw Permalink Normal View History

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TwoComplement is
2019-08-29 15:12:25 +02:00
generic(
BITCOUNT : integer := 8
);
port(
DIFF_EXP_C2 : in std_logic_vector((BITCOUNT-1) downto 0);
2019-08-29 15:12:25 +02:00
DIFF_EXP : out std_logic_vector((BITCOUNT-1) downto 0)
);
2019-08-29 15:12:25 +02:00
end TwoComplement;
architecture TwoComplementArch of TwoComplement is
2019-08-29 15:12:25 +02:00
signal SIGN : std_logic;
signal DIFF_EXP_ABS : std_logic_vector((BITCOUNT-2) downto 0);
begin
2019-08-29 15:12:25 +02:00
SIGN <= DIFF_EXP_C2(BITCOUNT-1);
2019-08-29 18:08:25 +02:00
C2_PROCESS : process (DIFF_EXP_C2, SIGN)
begin
2019-08-29 15:12:25 +02:00
for i in (BITCOUNT-2) downto 0 loop
2019-08-29 15:12:25 +02:00
DIFF_EXP_ABS(i) <= SIGN xor DIFF_EXP_C2(i);
end loop;
2019-08-29 15:12:25 +02:00
end process;
2019-08-29 18:08:25 +02:00
SUM : process (DIFF_EXP_ABS, SIGN)
2019-08-29 15:12:25 +02:00
variable CARRY : std_logic;
begin
CARRY := SIGN;
for i in 0 to (BITCOUNT-2) loop
DIFF_EXP(i) <= DIFF_EXP_ABS(i) xor CARRY;
CARRY := DIFF_EXP_ABS(i) and CARRY;
end loop;
DIFF_EXP(BITCOUNT-1) <= CARRY;
2019-08-29 15:12:25 +02:00
end process;
end TwoComplementArch;