ROM(データファイル使用)
掲載ページ:149、リスト番号:6.11
※ この記述は合成できません。シミュレーションの際に用いることを想定しています。
【VHDL記述】
library STD, IEEE;
use STD.TEXTIO.all;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_textio.all;
entity ROM is -- 記憶容量 2**AL(words)
generic( WL : integer := 8; -- ワード長(bits)
AL : integer := 4 ); -- アドレスバス長(bits)
port( RE : in std_logic;
ADDR : in std_logic_vector(AL-1 downto 0);
DATA_OUT : out std_logic_vector(WL-1 downto 0));
end ROM;
architecture BEHAVIOR of ROM is
subtype WORD is std_logic_vector(WL-1 downto 0);
type MEMORY is array ( 0 to 2**AL-1 ) of WORD;
signal MEM : MEMORY;
begin
WRITE_OP: process
file DATA_IN : text is in "rom_data.dat";
variable LINE_IN : line;
variable V_A : std_logic_vector(AL-1 downto 0);
variable V_D : std_logic_vector(WL-1 downto 0);
begin
readline(DATA_IN, LINE_IN);
read(LINE_IN, V_A);
read(LINE_IN, V_D);
MEM(conv_integer(V_A)) <= V_D;
if endfile(DATA_IN) then
wait;
end if;
end process;
READ_OP: process( RE, ADDR ) begin
if ( RE = '1' ) then
DATA_OUT <= MEM(conv_integer(ADDR));
end if;
end process;
end BEHAVIOR;
【ROM(リスト6.11)のデータファイル(rom_data.dat)(掲載ページ:150、リスト番号:6.12)】
0000 01101100
0001 10000000
0010 01100010
0011 00000000
0100 10110001
0101 10101010
0110 00000001
0111 00110011
1000 00000100
1001 01110100
1010 10000001
1011 00001111
1100 00000000
1101 00000000
1110 00000000
1111 00000000
【Verilog-HDL記述】
module ROM (
RE, ADDR,
DATA_OUT
);
// 記憶容量 2**AL(words)
parameter WL = 8; // ワード長(bits)
parameter AL = 4; // アドレスバス長(bits)
input RE;
input[ AL-1 : 0 ] ADDR;
output[ WL-1 : 0 ] DATA_OUT;
reg[ WL-1 : 0 ] DATA_OUT;
reg[ WL-1 : 0 ] MEM[ 0 : (1<<AL)-1 ];
initial begin
$readmemb( "ROM_DATA_Verilog.DAT", MEM );
end
always @ ( RE or ADDR ) begin : READ_OP
if ( RE ) begin
DATA_OUT <= MEM[ ADDR ];
end
end
endmodule
【ROM(Verilog-HDL記述用)のデータファイル(ROM_DATA_Verilog.DAT)】
01101100
10000000
01100010
00000000
10110001
10101010
00000001
00110011
00000100
01110100
10000001
00001111
00000000
00000000
00000000
00000000
【合成結果】
※ この記述は合成できません。シミュレーションの際に用いることを想定しています。