decoder.vhd 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 06/08/2023 11:03:10 AM
  6. -- Design Name:
  7. -- Module Name: decoder - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. -- Uncomment the following library declaration if using
  23. -- arithmetic functions with Signed or Unsigned values
  24. --use IEEE.NUMERIC_STD.ALL;
  25. -- Uncomment the following library declaration if instantiating
  26. -- any Xilinx leaf cells in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29. entity decoder is
  30. Port ( inst : in STD_LOGIC_VECTOR(31 downto 0);
  31. opcode : out STD_LOGIC_VECTOR( 6 downto 0);
  32. rd : out STD_LOGIC_VECTOR( 4 downto 0);
  33. rs1 : out STD_LOGIC_VECTOR( 4 downto 0);
  34. rs2 : out STD_LOGIC_VECTOR( 4 downto 0);
  35. imm : out STD_LOGIC_VECTOR(31 downto 0));
  36. end decoder;
  37. architecture Behavioral of decoder is
  38. type op_type is (R, I, S, B, U, J, X);
  39. signal op : std_logic_vector(4 downto 0);
  40. signal optype : op_type;
  41. begin
  42. opcode <= inst(6 downto 0);
  43. op <= inst(6 downto 2);
  44. optype <= R when op = x"0C" else
  45. I when op = x"04" else
  46. S when op = x"08" else
  47. B when op = x"18" else
  48. U when op = x"0D" or op = x"05" else
  49. J when op = x"1b" else
  50. X;
  51. rd <= inst(11 downto 7);
  52. rs1 <= inst(19 downto 15);
  53. rs2 <= inst(24 downto 20);
  54. imm <= inst(31) & inst(31) & inst(31) & inst(31) & inst(31) & inst(30 downto 25) & inst(24 downto 21) & inst(20) when optype = I else
  55. (others => '0');
  56. end Behavioral;