library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cnt161_4bits is
port( d3,d2,d1,d0 : in std_logic;
nld,ent,enp : in std_logic;
clk,nclr : in std_logic;
q3,q2,q1,q0 : out std_logic;
rco : out std_logic);
end cnt161_4bits;
architecture a of cnt161_4bits is
signal q : std_logic_vector( 3 downto 0);
begin
process(nclr,clk)
variable d : std_logic_vector(3 downto 0);
begin
d := d3&d2&d1&d0;
if( nclr='0') then q <="0000";
elsif(clk'event and clk='1') then
if(nld='0') then q <= d;
elsif(ent='1' and enp='1') then
q <= q+'1';
end if;
end if;
end process;
q3<=q(3); q2<=q(2); q1<=q(1); q0<=q(0);
rco <= ent and q(3) and q(2) and q(1) and q(0);
end a;