vhdl/src/instruction.vhd

40 lines
No EOL
1.1 KiB
VHDL

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity instruction is
port(
instruction: in STD_LOGIC_VECTOR(7 downto 0);
code: out STD_LOGIC_VECTOR(31 downto 0);
clk: in STD_LOGIC
);
-- Array of STD_LOGIC_VECTOR
type code_array is array(0 to 256) of
STD_LOGIC_VECTOR(31 downto 0);
-- Initialize the code memory
function init return code_array is
variable init_result: code_array;
begin
--do something (e.g. read data from a file, perform some initialization calculation, ...)
-- Exemple :
for i in code_array'range loop
init_result(i) := std_logic_vector(conv_unsigned(i, 32));
end loop;
return init_result;
end function init;
end instruction;
architecture behavior_instr of instruction is
-- Memory variable
signal code_memory: code_array := init;
begin
process(instruction, clk) is
begin
if clk'event AND clk = '1' then
code <= code_memory(CONV_INTEGER(UNSIGNED(instruction)));
end if;
end process;
end behavior_instr;