Subido por Ana Karen Godoy Peña

contol

Anuncio
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity control is
Port( fun_1: in std_logic;
fun_2: in std_logic_vector(2 downto 0);
inst_op: in std_logic_vector(6 downto 0);
zero: in std_logic;
pcSrc: out std_logic;
aluScr: out std_logic;
memtoReg: out std_logic_vector(14 downto 0);
memWrite: out std_logic;
regWrite: out std_logic;
regDst: out std_logic;
alu_control: out std_logic_vector(14 downto 0);
branch: buffer std_logic);
end control;
architecture Behavioral of control is
signal alu_op: std_logic_vector(1 downto 0);
signal s_regWrite, s_aluSrc, s_memWrite, s_regDst, s_branch, s_pcSrc: std_logic;
signal s_alu_control, s_memtoReg: std_logic_vector(2 downto 0);
signal fun_sign: std_logic_vector(3 downto 0);
signal s_op: std_logic_vector(6 downto 0);
begin
process(inst_op)
begin
case inst_op is
when "0000011" => --lw (Tipo I)
regWrite <= '1'; memtoReg <= "000000000000000"; aluScr <= '1'; memWrite <= '0'; regDst <= '1'; branch <= '0'; alu_op <= "00";
when "0010011" => --addi (Tipo I)
regWrite <= '1'; memtoReg <= "000000000000000"; aluScr <= '1'; memWrite <= '0'; regDst <= '1'; branch <= '0'; alu_op <= "00";
when "0000111" => --sw (Tipo S)
regWrite <= '0'; memtoReg <= "000000000000001"; aluScr <= '1'; memWrite <= '1'; regDst <= 'X'; branch <= '0'; alu_op <= "00";
when "0011011" => -- add, sub, slt, or, and (Tipo R)
regWrite <= '1'; memtoReg <= "000000000000011"; aluScr <= '0'; memWrite <= '0'; regDst <= '0'; branch <= '0'; alu_op <= "10";
when "0001011" => -- beq (Tipo B)
regWrite <= '0'; memtoReg <= "000000000000010"; aluScr <= '0'; memWrite <= '0'; regDst <= 'X'; branch <= '1'; alu_op <= "01";
when "0001111" => --Instrucciones tipo J
regWrite <= '0'; memtoReg <= "000000000000100"; aluScr <= 'X'; memWrite <= '0'; regDst <= 'X'; branch <= '1'; alu_op <= "XX";
when others =>
regWrite <= '0'; memtoReg <= "000000000000111"; aluScr <= '0'; memWrite <= '0'; regDst <= '0'; branch <= '0'; alu_op <= "00";
end case;
end process;
fun_sign <= fun_1 & fun_2;
s_op <= inst_op;
alu_control <=
"000000000000010" when (alu_op="00") else
"000000000000110" when (alu_op="01") else
"000000000000010" when (alu_op="10" and fun_sign="0000") else -- add
"000000000000110" when (alu_op="10" and fun_sign="0001") else -- subtract
"000000000000111" when (alu_op="10" and fun_sign="0100") else -- set less than
"000000000000001" when (alu_op="10" and fun_sign="1100") else -- or
"000000000000000" when (alu_op="10" and fun_sign="1110"); -- and
pcSrc <= branch and zero;
end Behavioral;
-- add
-- subtract
Descargar