Search code examples
vhdl

How to create a subsignal / subvariable from an entity variable in VHDL?


I am currently implementing a MIPS processor in VHDL. The system component (which glues together the ALU, register file, control unit, etc.) has the follow entity description:

entity system is
    port (
                 reset : in std_logic;
                 sys_clk : in std_logic;
                 instruction : in std_logic_vector(15 downto 0);
                 sys_mem_dump : in std_logic := '0'
         );
end system;

In the architecture section of this system, I am trying to create "subvariables" of the instruction variable, corresponding to the opcode and registers in use.

architecture Behavioral of system is
        instruction_opcode : std_logic_vector(3 downto 0) := instruction(15 downto 12);
        instruction_rd : std_logic_vector(3 downto 0) := instruction(11 downto 8); -- destination register
        instruction_rs : std_logic_vector(3 downto 0) := instruction(7 downto 4); -- source register
        instruction_rt : std_logic_vector(3 downto 0) := instruction(3 downto 0); -- target register
        -- a bunch of signals
begin 
    -- a bunch of port maps
end Behavioral

I've tried signal, variable, shared_variable, and constant, but these result in the register file's addresses not being initialized when I port map one of these variables to it. I've also tried putting these variables in the system entity port, but that also doesn't work. I don't want to split the instruction variable in the system entity port into those four variables either.


Solution

  • agree with paebles: you seem to lack basic VHDL knowledge and should look for this in your book.

    You should at least know this method:

    architecture Behavioral of system is
        signal instruction_opcode : std_logic_vector(3 downto 0);
    begin
        instruction_opcode <= instruction(15 downto 12);
    end architecture;
    

    But you can in fact use aliases:

    architecture Behavioral of system is
        alias instruction_opcode : std_logic_vector(3 downto 0) is instruction(15 downto 12);
    begin
    end architecture;