-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramCounter.vhd
More file actions
43 lines (35 loc) · 1.08 KB
/
ProgramCounter.vhd
File metadata and controls
43 lines (35 loc) · 1.08 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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity ProgramCounter is
generic(N : integer := 8;
M : integer := 128);
Port ( rst : in STD_LOGIC;
clk : in STD_LOGIC;
en : in STD_LOGIC;
inc : in STD_LOGIC;
load : in STD_LOGIC;
dataBus : inout STD_LOGIC_VECTOR (N-1 downto 0));
end ProgramCounter;
architecture Behavioral of ProgramCounter is
signal r_reg, r_next : unsigned(N-1 downto 0) := (others => '0');
begin
process(rst, clk, en, dataBus, load)
begin
if(rst = '1') then
r_reg <= (others => '0');
elsif(rising_edge(clk)) then
if(inc = '1') then
r_reg <= r_next;
elsif(load = '1') then
r_reg <= unsigned(dataBus);
end if;
end if;
end process;
--Next state logic
r_next <= (others => '0') when r_reg = M-1 else
r_reg + 1;
--Output logic
dataBus <= STD_LOGIC_VECTOR(r_reg) when en = '1' else
(others => 'Z');
end Behavioral;