-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREGX.vhd
52 lines (45 loc) · 1.08 KB
/
REGX.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity REGX is
generic
(
size : natural := 16;
default_value: natural:=0
);
port
(
clk : in std_logic;
ld : in std_logic :='0';
cl : in std_logic :='0';
inc : in std_logic :='0';
dec : in std_logic :='0';
data_in : in std_logic_vector(size-1 downto 0);
data_out : out std_logic_vector(size-1 downto 0)
);
end entity;
architecture rtl of REGX is
signal data,data_next:std_logic_vector(size-1 downto 0):=std_logic_vector(to_unsigned( default_value, size));
begin
data_out<=data;
process (clk)
begin
if (rising_edge(clk)) then
data<=data_next;
end if;
end process;
process (ld, inc, dec, cl, data_in, data)
begin
if cl = '1' then
data_next<=(others=>'0');
elsif ld='1' then
data_next<=data_in;
elsif inc='1' then
data_next<=std_logic_vector(to_unsigned(to_integer(unsigned( data )) + 1, size));
elsif dec='1' then
data_next<=std_logic_vector(to_unsigned(to_integer(unsigned( data )) - 1, size));
else
data_next<=data;
end if;
end process;
end rtl;