Implement and connect branch

This commit is contained in:
= 2024-02-01 06:58:12 +01:00
parent 8f14afc6ec
commit d57ca49821
4 changed files with 60 additions and 14 deletions

View File

@ -13,7 +13,8 @@ entity Decoder is
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;

27
src/branch.vhd Normal file
View File

@ -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;

0
src/control.vhd Normal file
View File

View File

@ -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
@ -100,7 +102,8 @@ begin
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;