dec8c_func.vhd
--
-- decrement library
--
library ieee;
use ieee.std_logic_1164.all;
package libDec is
function decrement8(source : std_logic_vector(7 downto 0)) return std_logic_vector;
end libDec;
package body libDec is
function decrement8(source : std_logic_vector(7 downto 0)) return std_logic_vector is
variable orAll : std_logic;
variable temp : std_logic_vector(source'high downto source'low);
begin
orAll := '0';
for j in source'low to source'high loop
temp(j) := source(j) xor (not orAll);
orAll := orAll or source(j);
end loop;
return(temp);
end decrement8;
end libDec;
--
-- 8-bit decrementor with control (use function)
--
library ieee;
use ieee.std_logic_1164.all;
use work.libDec.all;
entity dec8c_func is
port( a : in std_logic_vector(7 downto 0);
dec : in std_logic;
y : out std_logic_vector(7 downto 0) );
end dec8c_func;
architecture rtl of dec8c_func is
begin
y <= decrement8(a) when (dec = '1') else a;
end rtl;