-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_counter.vhd
36 lines (34 loc) · 1.13 KB
/
program_counter.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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
entity program_counter is
generic(PCSTART : integer := 128);
port
(
clk : in std_logic;
reset : in std_logic;
PCsel : in std_logic;
PCSource : in std_logic;
ALUResult : in std_logic_vector(31 downto 0);
ALUOut : in std_logic_vector(31 downto 0);
PC : out std_logic_vector(7 downto 0)
);
end program_counter;
architecture behave of program_counter is
begin
process(clk) begin
if rising_edge(clk) then
if(reset = '1') then
PC <= std_logic_vector(to_unsigned(PCSTART, PC'length)); -- go back to the original instruction
else
if(PCsel = '1') then
case(PCSource) is
when '0' => PC <= ALUResult(7 downto 0); -- direct line from alu
when '1' => PC <= ALUOut(7 downto 0); -- intermediate register
when others => PC <= "XXXXXXXX";
end case;
end if;
end if;
end if;
end process;
end architecture;