3b33440141a1716efb093bb47e0514b007ad7482
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

1) LIBRARY ieee;
2) USE ieee.std_logic_1164.all;
3) USE ieee.numeric_std.all;
4) USE work.mips_types.all;
5) 
6) ENTITY e_mips_regs IS
7)     PORT (
8)         rst:         IN  std_logic;
9)         clk:         IN  std_logic;
10)         i_rd_a_no:   IN  std_logic_vector( 4 DOWNTO 0);
11)         o_rd_a_data: OUT std_logic_vector(31 DOWNTO 0);
12)         i_rd_b_no:   IN  std_logic_vector( 4 DOWNTO 0);
13)         o_rd_b_data: OUT std_logic_vector(31 DOWNTO 0);
14)         i_wr_no:     IN  std_logic_vector( 4 DOWNTO 0);
15)         i_wr_data:   IN  std_logic_vector(31 DOWNTO 0);
16)         i_wr_en:     IN  std_logic
17)     );
18) END ENTITY e_mips_regs;
19) 
20) ARCHITECTURE a_mips_regs OF e_mips_regs IS
21) 
22)     SUBTYPE t_idx IS natural RANGE 31 DOWNTO 0;
23) 
24)     TYPE t_regs IS ARRAY(t_idx) OF std_logic_vector(31 DOWNTO 0);
25) 
26)     SIGNAL r_regs: t_regs;
27) 
28)     FUNCTION no2idx(no: std_logic_vector(4 DOWNTO 0)) RETURN natural IS
29)     BEGIN
30)         RETURN to_integer(unsigned(no));
31)     END FUNCTION no2idx;
32) 
33) BEGIN
34) 
35)     o_rd_a_data <= r_regs(no2idx(i_rd_a_no));
36) 
37)     o_rd_b_data <= r_regs(no2idx(i_rd_b_no));
38) 
39)     p_write: PROCESS(rst, clk)
40)     BEGIN
41)         IF rst = '1' THEN
Stefan Schuermans register 0 is always 0

Stefan Schuermans authored 12 years ago

42)             r_regs <= (OTHERS => '0');
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

43)         ELSIF rising_edge(clk) THEN
Stefan Schuermans register 0 is always 0

Stefan Schuermans authored 12 years ago

44)             IF i_wr_en = '1' AND i_wr_no /= (OTHERS => '0') THEN