メモリー / プログラムカウンターpcを作る

Chapter 3

プログラムカウンター用に16ビットカウンター(同期リセット、同期ロード、同期カウントイネーブル)を作る。素直にdffを連結してカウンターを作ったほうが楽だがテキストに従ってインクリメンタを使う。

これでChapter 3は終わり。

library ieee;
use ieee.std_logic_1164.all;

entity pc is
    port (
        inp: in std_logic_vector(15 downto 00);
        clk: in std_logic;
        inc, load, reset: in std_logic;
        outp: out std_logic_vector(15 downto 00)
    );
end entity;

architecture behavior of pc is
    signal temp_reg_in: std_logic_vector(15 downto 0);
    signal temp_reg_out: std_logic_vector(15 downto 0);
    signal temp_inc_in: std_logic_vector(15 downto 0);
    signal temp_inc_out: std_logic_vector(15 downto 0);
    signal temp_data_0: std_logic_vector(15 downto 0);
    signal temp_data_1: std_logic_vector(15 downto 0);
begin
    u0: entity work.mux16
    port map (
        a => temp_reg_out,
        b => temp_inc_out,
        sel => inc,
        outp => temp_data_0
    );
    u1: entity work.mux16
    port map (
        a => temp_data_0,
        b => inp,
        sel => load,
        outp => temp_data_1
    );
    u2: entity work.mux16
    port map (
        a => temp_data_1,
        b => x"0000",
        sel => reset,
        outp => temp_reg_in
    );
    u3: entity work.register_16_bit
    port map (
        clk => clk,
        -- OR(inc, load, reset):
        load => (((inc nand '1') nand (load nand '1')) nand '1') nand (reset nand '1'),
        d => temp_reg_in,
        q => temp_reg_out
    );
    u4: entity work.inc16
    port map (
        inp => temp_reg_out,
        outp => temp_inc_out
    );

    outp <= temp_reg_out;
end architecture;