コンピューターアーキテクチャー / rom16を作る

Chapter 5
テキストは16ビット × 32768本のrom32kブラックボックスとして提供しているが、こんなに大きなromを作っていたらLEがいくらあっても足りないので、ここではひとまず16ビット×16本のrom16VHDLで作り込んでおく。最終的にはメモリーブロックに移す。

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity rom16 is
    port (
        address: in std_logic_vector(3 downto 0);
        outp: out std_logic_vector(15 downto 0)
    );
end entity;

architecture behavior of rom16 is
    signal which_word: natural range 0 to 15;
    
    type rom_t is array (0 to 15) of std_logic_vector(15 downto 0);
    constant ROM: rom_t := (
        b"0000_0000_0000_0010",
        b"1110_1100_0001_0000",
        b"0000_0000_0000_0011",
        b"1110_0000_1001_0000",
        b"0000_0000_0000_0000",
        b"1110_0011_0000_1000",
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0'),
        (others => '0')
    );
begin
    which_word <= to_integer(unsigned(address));
    outp <= ROM(which_word);
end architecture;