Implement and connect branch
This commit is contained in:
parent
8f14afc6ec
commit
d57ca49821
|
@ -9,11 +9,12 @@ use IEEE.numeric_std.all;
|
||||||
-- Entity decode: Decoder currently supporting read operations
|
-- Entity decode: Decoder currently supporting read operations
|
||||||
entity Decoder is
|
entity Decoder is
|
||||||
port(
|
port(
|
||||||
Instruction : in std_logic_vector(15 downto 0); -- Instruction from instruction memory
|
Instruction : in std_logic_vector(15 downto 0); -- Instruction from instruction memory
|
||||||
AluOpcd : out std_logic_vector(3 downto 0); -- alu opcode
|
AluOpcd : out std_logic_vector(3 downto 0); -- alu opcode
|
||||||
RegOp1 : out std_logic_vector(3 downto 0); -- Rj: first register to read
|
RegOp1 : out std_logic_vector(3 downto 0); -- Rj: first register to read
|
||||||
RegOp2 : out std_logic_vector(3 downto 0); -- Rk: second register to read
|
RegOp2 : out std_logic_vector(3 downto 0); -- Rk: second register to read
|
||||||
RegWrite : out std_logic_vector(3 downto 0) -- Ri: the register to write to
|
RegWrite : out std_logic_vector(3 downto 0); -- Ri: the register to write to
|
||||||
|
BranchEnable : out std_logic
|
||||||
);
|
);
|
||||||
end Decoder;
|
end Decoder;
|
||||||
|
|
||||||
|
@ -34,9 +35,16 @@ begin
|
||||||
case Instruction(3 downto 0) is
|
case Instruction(3 downto 0) is
|
||||||
when "0000" | "0010" | "0011" | "0100" | "0101" | "0110" | "0111" | "1000" | "1010" => AluOpcd <= Instruction(3 downto 0); -- R-Types
|
when "0000" | "0010" | "0011" | "0100" | "0101" | "0110" | "0111" | "1000" | "1010" => AluOpcd <= Instruction(3 downto 0); -- R-Types
|
||||||
when "0001" | "1001" => AluOpcd <= Instruction(7 downto 4); -- S-Types
|
when "0001" | "1001" => AluOpcd <= Instruction(7 downto 4); -- S-Types
|
||||||
when "1110" => AluOpcd <= Instruction(7 downto 4); -- B-Types (to be debated)
|
when "1110" => AluOpcd <= Instruction(15 downto 12); -- B-Types (to be debated)
|
||||||
when others => AluOpcd <= "1111"; -- if unsure, do nothing
|
when others => AluOpcd <= "1111"; -- if unsure, do nothing
|
||||||
end case;
|
end case;
|
||||||
|
|
||||||
|
-- BranchEnable
|
||||||
|
case Instruction(3 downto 0) is
|
||||||
|
when "0001" | "1001" | "0100" | "1100" | "0101" | "1101" =>
|
||||||
|
BranchEnable <= '1';
|
||||||
|
when others => BranchEnable <= '0';
|
||||||
|
end case;
|
||||||
end process Decode;
|
end process Decode;
|
||||||
|
|
||||||
end Implementation;
|
end Implementation;
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
-- branch.vhd
|
||||||
|
-- Date: Thu Feb 1 06:03:29 2024
|
||||||
|
-- Author: Yannick Reiß
|
||||||
|
-- E-Mail: schnick@nickr.eu
|
||||||
|
library IEEE;
|
||||||
|
use IEEE.std_logic_1164.all;
|
||||||
|
use IEEE.numeric_std.all;
|
||||||
|
|
||||||
|
entity Branch is
|
||||||
|
port (
|
||||||
|
BranchEnable : in std_logic;
|
||||||
|
AluResult : in std_logic_vector(15 downto 0);
|
||||||
|
PC : in std_logic_vector(15 downto 0);
|
||||||
|
PMNext : in std_logic_vector(15 downto 0);
|
||||||
|
JumpSuggest : out std_logic;
|
||||||
|
PCCalc : out std_logic_vector(15 downto 0)
|
||||||
|
);
|
||||||
|
end Branch;
|
||||||
|
|
||||||
|
architecture Implementation of Branch is
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
PCCalc <= std_logic_vector(signed(PC) + signed(PMNext));
|
||||||
|
JumpSuggest <= BranchEnable and AluResult(0);
|
||||||
|
|
||||||
|
end Implementation;
|
|
@ -47,6 +47,8 @@ architecture Implementation of Cpu16 is
|
||||||
signal I2CClient : std_logic_vector(15 downto 0) := (others => '0');
|
signal I2CClient : std_logic_vector(15 downto 0) := (others => '0');
|
||||||
signal I2CClientOut : std_logic_vector(15 downto 0) := (others => '0');
|
signal I2CClientOut : std_logic_vector(15 downto 0) := (others => '0');
|
||||||
signal I2CServer : std_logic_vector(15 downto 0) := (others => '0');
|
signal I2CServer : std_logic_vector(15 downto 0) := (others => '0');
|
||||||
|
signal PcAddrCalc : std_logic_vector(15 downto 0) := (others => '0');
|
||||||
|
signal BranchEnable : std_logic := '0';
|
||||||
begin
|
begin
|
||||||
|
|
||||||
-- Include Entities
|
-- Include Entities
|
||||||
|
@ -96,11 +98,12 @@ begin
|
||||||
|
|
||||||
Decoder : entity work.Decoder(Implementation)
|
Decoder : entity work.Decoder(Implementation)
|
||||||
port map(
|
port map(
|
||||||
Instruction => RawInstruction,
|
Instruction => RawInstruction,
|
||||||
AluOpcd => AluOpcode,
|
AluOpcd => AluOpcode,
|
||||||
RegOp1 => RegisterRegister1,
|
RegOp1 => RegisterRegister1,
|
||||||
RegOp2 => RegisterRegister2,
|
RegOp2 => RegisterRegister2,
|
||||||
RegWrite => RegisterRegisterW
|
RegWrite => RegisterRegisterW,
|
||||||
|
BranchEnable => BranchEnable
|
||||||
);
|
);
|
||||||
|
|
||||||
ImmUseless : entity work.Immediate(Implementation)
|
ImmUseless : entity work.Immediate(Implementation)
|
||||||
|
@ -113,7 +116,7 @@ begin
|
||||||
port map(
|
port map(
|
||||||
Clk => Clk,
|
Clk => Clk,
|
||||||
PcEnable => PcEnable,
|
PcEnable => PcEnable,
|
||||||
AddrCalc => AluResult,
|
AddrCalc => PcAddrCalc,
|
||||||
Jump => Jump,
|
Jump => Jump,
|
||||||
Addr => InstructionCounter
|
Addr => InstructionCounter
|
||||||
);
|
);
|
||||||
|
@ -130,6 +133,16 @@ begin
|
||||||
ClientW => I2CClientOut
|
ClientW => I2CClientOut
|
||||||
);
|
);
|
||||||
|
|
||||||
|
BranchEnabler : entity work.Branch(Implementation)
|
||||||
|
port map(
|
||||||
|
BranchEnable => BranchEnable,
|
||||||
|
AluResult => AluResult,
|
||||||
|
PC => InstructionCounter,
|
||||||
|
PMNext => NextInstruction,
|
||||||
|
JumpSuggest => Jump,
|
||||||
|
PCCalc => PcAddrCalc
|
||||||
|
);
|
||||||
|
|
||||||
AluSetInput : process(ImmediateValue, InstructionCounter, RegisterDataOut1,
|
AluSetInput : process(ImmediateValue, InstructionCounter, RegisterDataOut1,
|
||||||
RegisterDataOut2)
|
RegisterDataOut2)
|
||||||
begin
|
begin
|
||||||
|
@ -141,8 +154,6 @@ begin
|
||||||
AluIn2 <= ImmediateValue;
|
AluIn2 <= ImmediateValue;
|
||||||
when others => AluIn1 <= InstructionCounter;
|
when others => AluIn1 <= InstructionCounter;
|
||||||
AluIn2 <= RegisterDataOut2;
|
AluIn2 <= RegisterDataOut2;
|
||||||
|
|
||||||
|
|
||||||
end case;
|
end case;
|
||||||
end process AluSetInput;
|
end process AluSetInput;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue