5e8c963b53a4682dca811a44069af392e6db2794
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) 
Stefan Schuermans fix sensitivity lists

Stefan Schuermans authored 12 years ago

35)     p_read_a: PROCESS(i_rd_a_no, r_regs)
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

36)     BEGIN
37)         IF i_rd_a_no = "00000" THEN
38)             o_rd_a_data <= X"00000000";
39)         ELSE
40)             o_rd_a_data <= r_regs(no2idx(i_rd_a_no));
41)         END IF;
42)     END PROCESS p_read_a;
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

43) 
Stefan Schuermans fix sensitivity lists

Stefan Schuermans authored 12 years ago

44)     p_read_b: PROCESS(i_rd_b_no, r_regs)
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

45)     BEGIN
46)         IF i_rd_b_no = "00000" THEN
47)             o_rd_b_data <= X"00000000";
48)         ELSE
49)             o_rd_b_data <= r_regs(no2idx(i_rd_b_no));
50)         END IF;
51)     END PROCESS p_read_b;
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

52) 
53)     p_write: PROCESS(rst, clk)
54)     BEGIN
55)         IF rst = '1' THEN
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

56)             -- r_regs <= (OTHERS => X"00000000");
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

57)         ELSIF rising_edge(clk) THEN
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

58)             IF i_wr_en = '1' THEN