ea1aa509f28467649b54a1116e0e639e9b77fe73
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)         clk:         IN  std_logic;
9)         i_rd_a_no:   IN  std_logic_vector( 4 DOWNTO 0);
10)         o_rd_a_data: OUT std_logic_vector(31 DOWNTO 0);
11)         i_rd_b_no:   IN  std_logic_vector( 4 DOWNTO 0);
12)         o_rd_b_data: OUT std_logic_vector(31 DOWNTO 0);
13)         i_wr_no:     IN  std_logic_vector( 4 DOWNTO 0);
14)         i_wr_data:   IN  std_logic_vector(31 DOWNTO 0);
15)         i_wr_en:     IN  std_logic
16)     );
17) END ENTITY e_mips_regs;
18) 
19) ARCHITECTURE a_mips_regs OF e_mips_regs IS
20) 
21)     SUBTYPE t_idx IS natural RANGE 31 DOWNTO 0;
22) 
23)     TYPE t_regs IS ARRAY(t_idx) OF std_logic_vector(31 DOWNTO 0);
24) 
Stefan Schuermans add initial values for regi...

Stefan Schuermans authored 12 years ago

25)     SIGNAL r_regs: t_regs := (OTHERS => (OTHERS => '0'));
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

26) 
27)     FUNCTION no2idx(no: std_logic_vector(4 DOWNTO 0)) RETURN natural IS
28)     BEGIN
29)         RETURN to_integer(unsigned(no));
30)     END FUNCTION no2idx;
31) 
32) BEGIN
33) 
Stefan Schuermans fix sensitivity lists

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

42) 
Stefan Schuermans fix sensitivity lists

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

51) 
Stefan Schuermans add initial values for regi...

Stefan Schuermans authored 12 years ago

52)     p_write: PROCESS(clk)
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

53)     BEGIN
Stefan Schuermans add initial values for regi...

Stefan Schuermans authored 12 years ago

54)         IF rising_edge(clk) THEN
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

55)             IF i_wr_en = '1' THEN