Add unconditional jump expressions

This commit is contained in:
= 2024-02-01 08:01:24 +01:00
parent d27dee2745
commit 3e8a72fa05
3 changed files with 20 additions and 9 deletions

View File

@ -14,7 +14,8 @@ entity Decoder is
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 BranchEnable : out std_logic;
UncondJump : out std_logic
); );
end Decoder; end Decoder;
@ -39,12 +40,13 @@ begin
when others => AluOpcd <= "1111"; -- if unsure, do nothing when others => AluOpcd <= "1111"; -- if unsure, do nothing
end case; end case;
-- BranchEnable -- BranchEnable / unconditionaljumpop
case Instruction(3 downto 0) is case Instruction(5 downto 0) is
when "0001" | "1001" | "0100" | "1100" | "0101" | "1101" => when "001110" | "101110" => BranchEnable <= '1';
BranchEnable <= '1'; when "011110" | "111110" => UncondJump <= '1';
when others => BranchEnable <= '0'; when others => BranchEnable <= '0';
end case; end case;
end process Decode; end process Decode;
end Implementation; end Implementation;

View File

@ -12,6 +12,7 @@ entity Branch is
AluResult : in std_logic_vector(15 downto 0); AluResult : in std_logic_vector(15 downto 0);
PC : in std_logic_vector(15 downto 0); PC : in std_logic_vector(15 downto 0);
PMNext : in std_logic_vector(15 downto 0); PMNext : in std_logic_vector(15 downto 0);
UncondJump : in std_logic;
JumpSuggest : out std_logic; JumpSuggest : out std_logic;
PCCalc : out std_logic_vector(15 downto 0) PCCalc : out std_logic_vector(15 downto 0)
); );
@ -22,6 +23,6 @@ architecture Implementation of Branch is
begin begin
PCCalc <= std_logic_vector(signed(PC) + signed(PMNext)); PCCalc <= std_logic_vector(signed(PC) + signed(PMNext));
JumpSuggest <= BranchEnable and AluResult(0); JumpSuggest <= (BranchEnable and AluResult(0)) or UncondJump;
end Implementation; end Implementation;

View File

@ -5,6 +5,12 @@
library IEEE; library IEEE;
use IEEE.std_logic_1164.all; use IEEE.std_logic_1164.all;
-- TODO: Check I Type; Implement Load instructions
-- TODO: Connect Register Data in
-- TODO: Add RAM data and address input
-- TODO: Connect I2C
-- TODO: Add peripheral Memory block
entity Cpu16 is entity Cpu16 is
port ( port (
Clk : in std_logic; Clk : in std_logic;
@ -51,6 +57,7 @@ architecture Implementation of Cpu16 is
signal BranchEnable : std_logic := '0'; signal BranchEnable : std_logic := '0';
signal JumpEnable : std_logic := '0'; signal JumpEnable : std_logic := '0';
signal State : std_logic_vector(2 downto 0) := (others => '0'); signal State : std_logic_vector(2 downto 0) := (others => '0');
signal UnconditionalJumpOp : std_logic := '0';
begin begin
-- Include Entities -- Include Entities
@ -105,7 +112,8 @@ begin
RegOp1 => RegisterRegister1, RegOp1 => RegisterRegister1,
RegOp2 => RegisterRegister2, RegOp2 => RegisterRegister2,
RegWrite => RegisterRegisterW, RegWrite => RegisterRegisterW,
BranchEnable => BranchEnable BranchEnable => BranchEnable,
UncondJump => UnconditionalJumpOp
); );
ImmUseless : entity work.Immediate(Implementation) ImmUseless : entity work.Immediate(Implementation)
@ -141,6 +149,7 @@ begin
AluResult => AluResult, AluResult => AluResult,
PC => InstructionCounter, PC => InstructionCounter,
PMNext => NextInstruction, PMNext => NextInstruction,
UncondJump => UnconditionalJumpOp,
JumpSuggest => Jump, JumpSuggest => Jump,
PCCalc => PcAddrCalc PCCalc => PcAddrCalc
); );
@ -171,7 +180,6 @@ begin
end case; end case;
end process AluSetInput; end process AluSetInput;
RGB <= Switches(7 downto 0); RGB <= Switches(7 downto 0);
end Implementation; end Implementation;