1 | library IEEE;
|
2 | use IEEE.std_logic_1164.all;
|
3 |
|
4 | entity main is port (
|
5 | select_reg : in std_logic_vector(3 downto 0);
|
6 | read, write, reset : in std_logic;
|
7 | idata : in std_logic_vector(7 downto 0);
|
8 | odata : out std_logic_vector(7 downto 0)
|
9 | );
|
10 | end entity;
|
11 |
|
12 | architecture rtl of main is
|
13 | component reg is port (
|
14 | d : in std_logic_vector(7 downto 0);
|
15 | clk : in std_logic;
|
16 | q : out std_logic_vector(7 downto 0));
|
17 | end component;
|
18 |
|
19 | signal d, q : std_logic_vector(7 downto 0) := "00000000";
|
20 | signal clk : std_logic := '1';
|
21 |
|
22 | type regs is array (0 to 15) of std_logic_vector(7 downto 0);
|
23 | signal in_regs : regs;
|
24 | signal out_regs : regs;
|
25 |
|
26 |
|
27 | begin
|
28 |
|
29 | reg1: reg port map (in_regs(0)=>d, clk=>clk, out_regs(0)=>q);
|
30 | reg2: reg port map (in_regs(1)=>d, clk=>clk, out_regs(1)=>q);
|
31 | reg3: reg port map (in_regs(2)=>d, clk=>clk, out_regs(2)=>q);
|
32 | reg4: reg port map (in_regs(3)=>d, clk=>clk, out_regs(3)=>q);
|
33 | reg5: reg port map (in_regs(4)=>d, clk=>clk, out_regs(4)=>q);
|
34 | reg6: reg port map (in_regs(5)=>d, clk=>clk, out_regs(5)=>q);
|
35 | reg7: reg port map (in_regs(6)=>d, clk=>clk, out_regs(6)=>q);
|
36 | reg8: reg port map (in_regs(7)=>d, clk=>clk, out_regs(7)=>q);
|
37 | reg9: reg port map (in_regs(8)=>d, clk=>clk, out_regs(8)=>q);
|
38 | reg10: reg port map (in_regs(9)=>d, clk=>clk, out_regs(9)=>q);
|
39 | reg11: reg port map (in_regs(10)=>d, clk=>clk, out_regs(10)=>q);
|
40 | reg12: reg port map (in_regs(11)=>d, clk=>clk, out_regs(11)=>q);
|
41 | reg13: reg port map (in_regs(12)=>d, clk=>clk, out_regs(12)=>q);
|
42 | reg14: reg port map (in_regs(13)=>d, clk=>clk, out_regs(13)=>q);
|
43 | reg15: reg port map (in_regs(14)=>d, clk=>clk, out_regs(14)=>q);
|
44 | reg16: reg port map (in_regs(15)=>d, clk=>clk, out_regs(15)=>q);
|
45 | process
|
46 | variable select_number : integer;
|
47 | begin
|
48 | select_number := 0;
|
49 | if select_reg(3) = '1' then
|
50 | select_number := 1;
|
51 | end if;
|
52 | if select_reg(2) = '1' then
|
53 | select_number := select_number + 2;
|
54 | end if;
|
55 | if select_reg(1) = '1' then
|
56 | select_number := select_number + 4;
|
57 | end if;
|
58 | if select_reg(0) = '1' then
|
59 | select_number := select_number + 8;
|
60 | end if;
|
61 |
|
62 | if read = '1' then
|
63 | odata <= out_regs(select_number);
|
64 | elsif write = '1' then
|
65 | odata <= "00000000";
|
66 | in_regs(select_number) <= idata;
|
67 | else
|
68 | odata <= "00000000";
|
69 | end if;
|
70 |
|
71 | end process;
|
72 | end architecture;
|