LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.numeric_std.all; USE work.mips_types.all; ENTITY e_mips_regs IS PORT ( clk: IN std_logic; i_rd_a_no: IN std_logic_vector( 4 DOWNTO 0); o_rd_a_data: OUT std_logic_vector(31 DOWNTO 0); i_rd_b_no: IN std_logic_vector( 4 DOWNTO 0); o_rd_b_data: OUT std_logic_vector(31 DOWNTO 0); i_wr_no: IN std_logic_vector( 4 DOWNTO 0); i_wr_data: IN std_logic_vector(31 DOWNTO 0); i_wr_en: IN std_logic ); END ENTITY e_mips_regs; ARCHITECTURE a_mips_regs OF e_mips_regs IS SUBTYPE t_idx IS natural RANGE 31 DOWNTO 0; TYPE t_regs IS ARRAY(t_idx) OF std_logic_vector(31 DOWNTO 0); SIGNAL r_regs: t_regs := (OTHERS => (OTHERS => '0')); FUNCTION no2idx(no: std_logic_vector(4 DOWNTO 0)) RETURN natural IS BEGIN RETURN to_integer(unsigned(no)); END FUNCTION no2idx; BEGIN p_read_a: PROCESS(i_rd_a_no, r_regs) BEGIN IF i_rd_a_no = "00000" THEN o_rd_a_data <= X"00000000"; ELSE o_rd_a_data <= r_regs(no2idx(i_rd_a_no)); END IF; END PROCESS p_read_a; p_read_b: PROCESS(i_rd_b_no, r_regs) BEGIN IF i_rd_b_no = "00000" THEN o_rd_b_data <= X"00000000"; ELSE o_rd_b_data <= r_regs(no2idx(i_rd_b_no)); END IF; END PROCESS p_read_b; p_write: PROCESS(clk) BEGIN IF rising_edge(clk) THEN IF i_wr_en = '1' THEN r_regs(no2idx(i_wr_no)) <= i_wr_data; END IF; END IF; END PROCESS p_write; END ARCHITECTURE a_mips_regs;