Source Code (VHDL Modules)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
entity ALU_VHDL is
port(
a, b : in std_logic_vector(15 downto 0);
alu_control : in std_logic_vector(2 downto 0);
alu_result : out std_logic_vector(15 downto 0);
zero : out std_logic
);
end ALU_VHDL;
architecture Behavioral of ALU_VHDL is
signal result : std_logic_vector(15 downto 0);
begin
process(alu_control, a, b)
begin
case alu_control is
when "000" => result <= a + b;
when "001" => result <= a - b;
when "010" => result <= a and b;
when "011" => result <= a or b;
when "100" => result <= (x"0001" when a < b else x"0000");
when others => result <= (others => '0');
end case;
end process;
zero <= '1' when result = x"0000" else '0';
alu_result <= result;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity control_unit_VHDL is
port(
opcode : in std_logic_vector(2 downto 0);
reset : in std_logic;
reg_dst,
mem_to_reg,
alu_op : out std_logic_vector(1 downto 0);
jump, branch, mem_read, mem_write,
alu_src, reg_write, sign_or_zero : out std_logic
);
end control_unit_VHDL;
architecture Behavioral of control_unit_VHDL is
begin
process(reset, opcode)
begin
if reset = '1' then
reg_dst <= "00"; mem_to_reg <= "00"; alu_op <= "00";
jump <= '0'; branch <= '0'; mem_read <= '0';
mem_write <= '0'; alu_src <= '0'; reg_write <= '0';
sign_or_zero <= '1';
else
case opcode is
when "000" => alu_op <= "00"; reg_write <= '1'; -- ADD
when "001" => alu_op <= "01"; reg_write <= '1'; -- SUB
when "010" => alu_op <= "10"; reg_write <= '1'; -- SLTU
when "011" => branch <= '1'; -- BEQ
when others => null;
end case;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity register_file_VHDL is
port(
clk, rst : in std_logic;
reg_write_en : in std_logic;
reg_write_dest : in std_logic_vector(2 downto 0);
reg_write_data : in std_logic_vector(15 downto 0);
reg_read_addr_1, reg_read_addr_2 : in std_logic_vector(2 downto 0);
reg_read_data_1, reg_read_data_2 : out std_logic_vector(15 downto 0)
);
end register_file_VHDL;