-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreg_inc_dec_16_bit.vhd
More file actions
executable file
·72 lines (62 loc) · 2.01 KB
/
reg_inc_dec_16_bit.vhd
File metadata and controls
executable file
·72 lines (62 loc) · 2.01 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- Julio Chavez
-- University of Florida
-- Small8 Microprocessor
-- PC Register with width > 1
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity reg_inc_dec_16_bit is
generic(
width : positive := 8);
port(
clk : in std_logic;
rst : in std_logic;
input : in std_logic_vector(width - 1 downto 0);
inc : in std_logic;
dec : in std_logic;
L_load : in std_logic;
H_load : in std_logic;
L_output : out std_logic_vector(width - 1 downto 0);
H_output : out std_logic_vector(width - 1 downto 0);
output : out std_logic_vector(2*width-1 downto 0)
);
end reg_inc_dec_16_bit;
architecture BHV of reg_inc_dec_16_bit is
begin
process(clk, rst)
constant ZERO : std_logic_vector(15 downto 0) := x"0000";
-- constant ONE : std_logic_vector(15 downto 0) := x"0001";
variable output_var : unsigned((2 * width - 1) downto 0);
begin
if (rst = '1') then
L_output <= (others => '0');
H_output <= (others => '0');
output_var := unsigned(ZERO);
output <= (others => '0');
elsif (clk'event and clk = '1') then
-- Load bottom 8-bits of the PC register
if (L_load = '1') then
L_output <= input;
output_var(7 downto 0) := unsigned(input);
output <= std_logic_vector(output_var);
-- Load top 8-bits of the PC register
elsif (H_load = '1') then
H_output <= input;
output_var(15 downto 8) := unsigned(input);
output <= std_logic_vector(output_var);
-- Increment PC register by 1
elsif (inc = '1') then
output_var := output_var + 1;
L_output <= std_logic_vector(output_var(7 downto 0));
H_output <= std_logic_vector(output_var(15 downto 8));
output <= std_logic_vector(output_var);
-- Decrement PC register by 1
elsif (dec = '1') then
output_var := output_var - 1;
L_output <= std_logic_vector(output_var(7 downto 0));
H_output <= std_logic_vector(output_var(15 downto 8));
output <= std_logic_vector(output_var);
end if;
end if;
end process;
end BHV;