M
Mr.X
Guest
can anyone help to write da testbench for this 8 bit microprocessor
suggestions r welcome
=====================================================================
Structural VHDL code for the complete EC-2 general-purpose
microprocessor
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
ENTITY mp IS PORT (
Clock : IN STD_LOGIC;
Reset: IN STD_LOGIC;
Enter: IN STD_LOGIC;
Input: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
Output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
Halt: OUT STD_LOGIC);
END mp;
ARCHITECTURE Structural OF mp IS
COMPONENT cu PORT (
Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
-- control input
Enter: IN STD_LOGIC;
-- control signals
IRload: OUT STD_LOGIC;
JMPmux: OUT STD_LOGIC;
PCload: OUT STD_LOGIC;
MemInst: OUT STD_LOGIC;
MemWr: OUT STD_LOGIC;
Asel: OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: OUT STD_LOGIC;
Sub: OUT STD_LOGIC;
-- status signals
IR: IN STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: IN STD_LOGIC;
Apos: IN STD_LOGIC;
-- control outputs
Halt: OUT STD_LOGIC);
END COMPONENT;
COMPONENT dp PORT (
Clock: IN STD_LOGIC;
Clear: IN STD_LOGIC;
-- datapath input
Input: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
-- control signals
IRload: IN STD_LOGIC;
JMPmux: IN STD_LOGIC;
PCload: IN STD_LOGIC;
MemInst: IN STD_LOGIC;
MemWr: IN STD_LOGIC;
ASel: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: IN STD_LOGIC;
Sub: IN STD_LOGIC;
-- status signals
IR: OUT STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: OUT STD_LOGIC;
Apos: OUT STD_LOGIC;
-- datapath output
Output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END COMPONENT;
-- control signals
SIGNAL mp_IRload: STD_LOGIC;
SIGNAL mp_JMPmux: STD_LOGIC;
SIGNAL mp_PCload: STD_LOGIC;
SIGNAL mp_MemInst: STD_LOGIC;
SIGNAL mp_MemWr: STD_LOGIC;
SIGNAL mp_Asel: STD_LOGIC_VECTOR(1 DOWNTO 0);
SIGNAL mp_Aload: STD_LOGIC;
SIGNAL mp_Sub: STD_LOGIC;
-- status signals
SIGNAL mp_IR: STD_LOGIC_VECTOR(7 DOWNTO 5);
SIGNAL mp_Aeq0: STD_LOGIC;
SIGNAL mp_Apos: STD_LOGIC;
BEGIN
-- doing structural modeling for the microprocessor here
U0: cu PORT MAP (
Clock, Reset,
-- control input
Enter,
-- control signals
mp_IRload, mp_JMPmux, mp_PCload, mp_MemInst, mp_MemWr,
mp_Asel,
mp_Aload, mp_Sub,
-- status signals
mp_IR,
mp_Aeq0, mp_Apos,
-- control outputs
Halt);
U1: dp PORT MAP (
Clock, Reset,
-- datapath input
Input,
-- control signals
mp_IRload, mp_JMPmux, mp_PCload, mp_MemInst, mp_MemWr,
mp_Asel,
mp_Aload, mp_Sub,
-- status signals
mp_IR,
mp_Aeq0, mp_Apos,
-- datapath output
Output);
END Structural;
=====================================================================
VHDL code for the control unit of the EC-2.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY cu IS PORT (
Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
-- control input
Enter: IN STD_LOGIC;
-- control signals
IRload: OUT STD_LOGIC;
JMPmux: OUT STD_LOGIC;
PCload: OUT STD_LOGIC;
MemInst: OUT STD_LOGIC;
MemWr: OUT STD_LOGIC;
Asel: OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: OUT STD_LOGIC;
Sub: OUT STD_LOGIC;
-- status signals
IR: IN STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: IN STD_LOGIC;
Apos: IN STD_LOGIC;
-- control outputs
Halt: OUT STD_LOGIC);
END cu;
ARCHITECTURE FSM OF cu IS
TYPE state_type IS (s_start,s_fetch,s_decode,
s_load,s_store,s_add,s_sub,s_in,s_jz,s_jpos,s_halt);
SIGNAL state: state_type;
BEGIN
next_state_logic: PROCESS(Reset, Clock)
BEGIN
IF(Reset = '1') THEN
state <= s_start;
ELSIF(Clock'EVENT AND Clock = '1') THEN
CASE state IS
WHEN s_start => -- reset
state <= s_fetch;
WHEN s_fetch =>
state <= s_decode;
WHEN s_decode =>
CASE IR IS
WHEN "000" => state <= s_load;
WHEN "001" => state <= s_store;
WHEN "010" => state <= s_add;
WHEN "011" => state <= s_sub;
WHEN "100" => state <= s_in;
WHEN "101" => state <= s_jz;
WHEN "110" => state <= s_jpos;
WHEN "111" => state <= s_halt;
WHEN OTHERS => state <= s_halt;
END CASE;
WHEN s_load =>
state <= s_start;
WHEN s_store =>
state <= s_start;
WHEN s_add =>
state <= s_start;
WHEN s_sub =>
state <= s_start;
WHEN s_in =>
IF (Enter = '0') THEN -- wait for the Enter key for inputs
state <= s_in;
ELSE
state <= s_start;
END IF;
WHEN s_jz =>
state <= s_start;
WHEN s_jpos =>
state <= s_start;
WHEN s_halt =>
state <= s_halt;
WHEN OTHERS =>
state <= s_start;
END CASE;
END IF;
END PROCESS;
output_logic: PROCESS(state)
BEGIN
CASE state IS
WHEN s_fetch =>
IRload <= '1'; -- load IR
JMPmux <= '0';
PCload <= '1'; -- increment PC
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_decode => -- also set up for memory access
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1'; -- pass IR address to memory
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_load =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1';
MemWr <= '0';
Asel <= "10";-- pass memory to A
Aload <= '1'; -- load A
Sub <= '0';
Halt <= '0';
WHEN s_store =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1'; -- pass IR address to memory
MemWr <= '1'; -- store A to memory
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_add =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1';
MemWr <= '0';
Asel <= "00";-- pass add/sub unit to A
Aload <= '1'; -- load A
Sub <= '0'; -- select add
Halt <= '0';
WHEN s_sub =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1';
MemWr <= '0';
Asel <= "00";-- pass add/sub unit to A
Aload <= '1'; -- load A
Sub <= '1'; -- select subtract
Halt <= '0';
WHEN s_in =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '0';
MemWr <= '0';
Asel <= "01";-- pass input to A
Aload <= '1'; -- load A
Sub <= '0';
Halt <= '0';
WHEN s_jz =>
IRload <= '0';
JMPmux <= '1'; -- pass IR address to PC
PCload <= Aeq0; -- load PC if condition is true
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_jpos =>
IRload <= '0';
JMPmux <= '1'; -- pass IR address to PC
PCload <= Apos; -- load PC if condition is true
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_halt =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '1';
WHEN OTHERS =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
END CASE;
END PROCESS;
END FSM;
======================================================================
VHDL code for the datapath of the EC-2.
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
-- for memory
USE work.lpm_components.ALL;
ENTITY dp IS
PORT (
Clock: IN STD_LOGIC;
Clear: IN STD_LOGIC;
-- datapath input
Input: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
-- control signals
IRload: IN STD_LOGIC;
JMPmux: IN STD_LOGIC;
PCload: IN STD_LOGIC;
MemInst: IN STD_LOGIC;
MemWr: IN STD_LOGIC;
ASel: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: IN STD_LOGIC;
Sub: IN STD_LOGIC;
-- status signals
IR: OUT STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: OUT STD_LOGIC;
Apos: OUT STD_LOGIC;
-- datapath output
Output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END dp;
ARCHITECTURE Structural OF dp IS
COMPONENT reg
GENERIC (size: INTEGER := 4); -- the actual size is defined in the
instantiation GENERIC MAP
PORT (
Clock, Clear, Load: IN STD_LOGIC;
D: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);
Q: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0));
END COMPONENT;
COMPONENT increment
GENERIC (size: INTEGER := 8); -- default number of bits
PORT (
A: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);
F: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0));
END COMPONENT;
COMPONENT mux2
GENERIC (size: INTEGER := 8); -- default size
PORT (
S: IN STD_LOGIC; -- select line
D1, D0: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0); -- data bus input
Y: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0)); -- data bus output
END COMPONENT;
COMPONENT mux4
GENERIC (size: INTEGER := 8); -- default size
PORT (
S: IN STD_LOGIC_VECTOR(1 DOWNTO 0); -- select line
D3, D2, D1, D0: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0); -- data bus
input
Y: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0)); -- data bus output
END COMPONENT;
COMPONENT addsub
GENERIC(n: INTEGER :=4); -- default number of bits = 4
PORT(S: IN std_logic; -- select subtract signal
A: IN std_logic_vector(n-1 DOWNTO 0);
B: IN std_logic_vector(n-1 DOWNTO 0);
F: OUT std_logic_vector(n-1 DOWNTO 0);
unsigned_overflow: OUT std_logic;
signed_overflow: OUT std_logic);
END COMPONENT;
SIGNAL dp_IR, dp_RAMQ: STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL dp_JMPmux, dp_PC, dp_increment, dp_meminst: STD_LOGIC_VECTOR(4
DOWNTO 0);
SIGNAL dp_Amux, dp_addsub, dp_A: STD_LOGIC_VECTOR(7 DOWNTO 0);
BEGIN
-- doing structural modeling for the datapath here
-- IR
U0: reg GENERIC MAP(8) PORT MAP(Clock, Clear, IRLoad, dp_RAMQ, dp_IR);
IR <= dp_IR(7 DOWNTO 5);
-- JMPmux
U1: mux2 GENERIC MAP(5) PORT MAP(JMPmux,dp_IR(4 DOWNTO 0),
dp_increment,dp_JMPmux);
-- PC
U2: reg GENERIC MAP(5) PORT MAP(Clock, Clear, PCLoad, dp_JMPmux,
dp_PC);
-- Meminst
U3: mux2 GENERIC MAP(5) PORT MAP(Meminst,dp_IR(4 DOWNTO 0),
dp_PC,dp_meminst);
-- increment
U4: increment GENERIC MAP(5) PORT MAP(dp_PC,dp_increment);
-- memory
U5: lpm_ram_dq
GENERIC MAP (
lpm_widthad => 5,
lpm_outdata => "UNREGISTERED",
-- lpm_indata => "UNREGISTERED",
-- lpm_address_control => "UNREGISTERED",
lpm_file => "program.mif",-- fill ram with content of file program.mif
lpm_width => 8)
PORT MAP (
data => dp_A,
address => dp_meminst,
we => MemWr,
inclock => Clock,
q => dp_RAMQ);
-- A input mux
U6: mux4 GENERIC MAP(8) PORT MAP (
Asel,dp_RAMQ,dp_RAMQ,Input,dp_addsub,dp_Amux);
-- Accumulator
U7: reg GENERIC MAP(8) PORT MAP(Clock, Clear, ALoad, dp_Amux, dp_A);
-- Adder-subtractor
U8: addsub GENERIC MAP(8) PORT
MAP(Sub,dp_A,dp_RAMQ,dp_addsub,open,open);
Aeq0 <= '1' WHEN dp_A = "00000000" ELSE '0';
Apos <= NOT dp_A(7);
Output <= dp_A;
END Structural;
======================================================================
suggestions r welcome
=====================================================================
Structural VHDL code for the complete EC-2 general-purpose
microprocessor
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
ENTITY mp IS PORT (
Clock : IN STD_LOGIC;
Reset: IN STD_LOGIC;
Enter: IN STD_LOGIC;
Input: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
Output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
Halt: OUT STD_LOGIC);
END mp;
ARCHITECTURE Structural OF mp IS
COMPONENT cu PORT (
Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
-- control input
Enter: IN STD_LOGIC;
-- control signals
IRload: OUT STD_LOGIC;
JMPmux: OUT STD_LOGIC;
PCload: OUT STD_LOGIC;
MemInst: OUT STD_LOGIC;
MemWr: OUT STD_LOGIC;
Asel: OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: OUT STD_LOGIC;
Sub: OUT STD_LOGIC;
-- status signals
IR: IN STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: IN STD_LOGIC;
Apos: IN STD_LOGIC;
-- control outputs
Halt: OUT STD_LOGIC);
END COMPONENT;
COMPONENT dp PORT (
Clock: IN STD_LOGIC;
Clear: IN STD_LOGIC;
-- datapath input
Input: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
-- control signals
IRload: IN STD_LOGIC;
JMPmux: IN STD_LOGIC;
PCload: IN STD_LOGIC;
MemInst: IN STD_LOGIC;
MemWr: IN STD_LOGIC;
ASel: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: IN STD_LOGIC;
Sub: IN STD_LOGIC;
-- status signals
IR: OUT STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: OUT STD_LOGIC;
Apos: OUT STD_LOGIC;
-- datapath output
Output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END COMPONENT;
-- control signals
SIGNAL mp_IRload: STD_LOGIC;
SIGNAL mp_JMPmux: STD_LOGIC;
SIGNAL mp_PCload: STD_LOGIC;
SIGNAL mp_MemInst: STD_LOGIC;
SIGNAL mp_MemWr: STD_LOGIC;
SIGNAL mp_Asel: STD_LOGIC_VECTOR(1 DOWNTO 0);
SIGNAL mp_Aload: STD_LOGIC;
SIGNAL mp_Sub: STD_LOGIC;
-- status signals
SIGNAL mp_IR: STD_LOGIC_VECTOR(7 DOWNTO 5);
SIGNAL mp_Aeq0: STD_LOGIC;
SIGNAL mp_Apos: STD_LOGIC;
BEGIN
-- doing structural modeling for the microprocessor here
U0: cu PORT MAP (
Clock, Reset,
-- control input
Enter,
-- control signals
mp_IRload, mp_JMPmux, mp_PCload, mp_MemInst, mp_MemWr,
mp_Asel,
mp_Aload, mp_Sub,
-- status signals
mp_IR,
mp_Aeq0, mp_Apos,
-- control outputs
Halt);
U1: dp PORT MAP (
Clock, Reset,
-- datapath input
Input,
-- control signals
mp_IRload, mp_JMPmux, mp_PCload, mp_MemInst, mp_MemWr,
mp_Asel,
mp_Aload, mp_Sub,
-- status signals
mp_IR,
mp_Aeq0, mp_Apos,
-- datapath output
Output);
END Structural;
=====================================================================
VHDL code for the control unit of the EC-2.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY cu IS PORT (
Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
-- control input
Enter: IN STD_LOGIC;
-- control signals
IRload: OUT STD_LOGIC;
JMPmux: OUT STD_LOGIC;
PCload: OUT STD_LOGIC;
MemInst: OUT STD_LOGIC;
MemWr: OUT STD_LOGIC;
Asel: OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: OUT STD_LOGIC;
Sub: OUT STD_LOGIC;
-- status signals
IR: IN STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: IN STD_LOGIC;
Apos: IN STD_LOGIC;
-- control outputs
Halt: OUT STD_LOGIC);
END cu;
ARCHITECTURE FSM OF cu IS
TYPE state_type IS (s_start,s_fetch,s_decode,
s_load,s_store,s_add,s_sub,s_in,s_jz,s_jpos,s_halt);
SIGNAL state: state_type;
BEGIN
next_state_logic: PROCESS(Reset, Clock)
BEGIN
IF(Reset = '1') THEN
state <= s_start;
ELSIF(Clock'EVENT AND Clock = '1') THEN
CASE state IS
WHEN s_start => -- reset
state <= s_fetch;
WHEN s_fetch =>
state <= s_decode;
WHEN s_decode =>
CASE IR IS
WHEN "000" => state <= s_load;
WHEN "001" => state <= s_store;
WHEN "010" => state <= s_add;
WHEN "011" => state <= s_sub;
WHEN "100" => state <= s_in;
WHEN "101" => state <= s_jz;
WHEN "110" => state <= s_jpos;
WHEN "111" => state <= s_halt;
WHEN OTHERS => state <= s_halt;
END CASE;
WHEN s_load =>
state <= s_start;
WHEN s_store =>
state <= s_start;
WHEN s_add =>
state <= s_start;
WHEN s_sub =>
state <= s_start;
WHEN s_in =>
IF (Enter = '0') THEN -- wait for the Enter key for inputs
state <= s_in;
ELSE
state <= s_start;
END IF;
WHEN s_jz =>
state <= s_start;
WHEN s_jpos =>
state <= s_start;
WHEN s_halt =>
state <= s_halt;
WHEN OTHERS =>
state <= s_start;
END CASE;
END IF;
END PROCESS;
output_logic: PROCESS(state)
BEGIN
CASE state IS
WHEN s_fetch =>
IRload <= '1'; -- load IR
JMPmux <= '0';
PCload <= '1'; -- increment PC
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_decode => -- also set up for memory access
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1'; -- pass IR address to memory
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_load =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1';
MemWr <= '0';
Asel <= "10";-- pass memory to A
Aload <= '1'; -- load A
Sub <= '0';
Halt <= '0';
WHEN s_store =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1'; -- pass IR address to memory
MemWr <= '1'; -- store A to memory
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_add =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1';
MemWr <= '0';
Asel <= "00";-- pass add/sub unit to A
Aload <= '1'; -- load A
Sub <= '0'; -- select add
Halt <= '0';
WHEN s_sub =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '1';
MemWr <= '0';
Asel <= "00";-- pass add/sub unit to A
Aload <= '1'; -- load A
Sub <= '1'; -- select subtract
Halt <= '0';
WHEN s_in =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '0';
MemWr <= '0';
Asel <= "01";-- pass input to A
Aload <= '1'; -- load A
Sub <= '0';
Halt <= '0';
WHEN s_jz =>
IRload <= '0';
JMPmux <= '1'; -- pass IR address to PC
PCload <= Aeq0; -- load PC if condition is true
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_jpos =>
IRload <= '0';
JMPmux <= '1'; -- pass IR address to PC
PCload <= Apos; -- load PC if condition is true
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
WHEN s_halt =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '1';
WHEN OTHERS =>
IRload <= '0';
JMPmux <= '0';
PCload <= '0';
Meminst <= '0';
MemWr <= '0';
Asel <= "00";
Aload <= '0';
Sub <= '0';
Halt <= '0';
END CASE;
END PROCESS;
END FSM;
======================================================================
VHDL code for the datapath of the EC-2.
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
-- for memory
USE work.lpm_components.ALL;
ENTITY dp IS
PORT (
Clock: IN STD_LOGIC;
Clear: IN STD_LOGIC;
-- datapath input
Input: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
-- control signals
IRload: IN STD_LOGIC;
JMPmux: IN STD_LOGIC;
PCload: IN STD_LOGIC;
MemInst: IN STD_LOGIC;
MemWr: IN STD_LOGIC;
ASel: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
Aload: IN STD_LOGIC;
Sub: IN STD_LOGIC;
-- status signals
IR: OUT STD_LOGIC_VECTOR(7 DOWNTO 5);
Aeq0: OUT STD_LOGIC;
Apos: OUT STD_LOGIC;
-- datapath output
Output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END dp;
ARCHITECTURE Structural OF dp IS
COMPONENT reg
GENERIC (size: INTEGER := 4); -- the actual size is defined in the
instantiation GENERIC MAP
PORT (
Clock, Clear, Load: IN STD_LOGIC;
D: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);
Q: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0));
END COMPONENT;
COMPONENT increment
GENERIC (size: INTEGER := 8); -- default number of bits
PORT (
A: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);
F: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0));
END COMPONENT;
COMPONENT mux2
GENERIC (size: INTEGER := 8); -- default size
PORT (
S: IN STD_LOGIC; -- select line
D1, D0: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0); -- data bus input
Y: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0)); -- data bus output
END COMPONENT;
COMPONENT mux4
GENERIC (size: INTEGER := 8); -- default size
PORT (
S: IN STD_LOGIC_VECTOR(1 DOWNTO 0); -- select line
D3, D2, D1, D0: IN STD_LOGIC_VECTOR(size-1 DOWNTO 0); -- data bus
input
Y: OUT STD_LOGIC_VECTOR(size-1 DOWNTO 0)); -- data bus output
END COMPONENT;
COMPONENT addsub
GENERIC(n: INTEGER :=4); -- default number of bits = 4
PORT(S: IN std_logic; -- select subtract signal
A: IN std_logic_vector(n-1 DOWNTO 0);
B: IN std_logic_vector(n-1 DOWNTO 0);
F: OUT std_logic_vector(n-1 DOWNTO 0);
unsigned_overflow: OUT std_logic;
signed_overflow: OUT std_logic);
END COMPONENT;
SIGNAL dp_IR, dp_RAMQ: STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL dp_JMPmux, dp_PC, dp_increment, dp_meminst: STD_LOGIC_VECTOR(4
DOWNTO 0);
SIGNAL dp_Amux, dp_addsub, dp_A: STD_LOGIC_VECTOR(7 DOWNTO 0);
BEGIN
-- doing structural modeling for the datapath here
-- IR
U0: reg GENERIC MAP(8) PORT MAP(Clock, Clear, IRLoad, dp_RAMQ, dp_IR);
IR <= dp_IR(7 DOWNTO 5);
-- JMPmux
U1: mux2 GENERIC MAP(5) PORT MAP(JMPmux,dp_IR(4 DOWNTO 0),
dp_increment,dp_JMPmux);
-- PC
U2: reg GENERIC MAP(5) PORT MAP(Clock, Clear, PCLoad, dp_JMPmux,
dp_PC);
-- Meminst
U3: mux2 GENERIC MAP(5) PORT MAP(Meminst,dp_IR(4 DOWNTO 0),
dp_PC,dp_meminst);
-- increment
U4: increment GENERIC MAP(5) PORT MAP(dp_PC,dp_increment);
-- memory
U5: lpm_ram_dq
GENERIC MAP (
lpm_widthad => 5,
lpm_outdata => "UNREGISTERED",
-- lpm_indata => "UNREGISTERED",
-- lpm_address_control => "UNREGISTERED",
lpm_file => "program.mif",-- fill ram with content of file program.mif
lpm_width => 8)
PORT MAP (
data => dp_A,
address => dp_meminst,
we => MemWr,
inclock => Clock,
q => dp_RAMQ);
-- A input mux
U6: mux4 GENERIC MAP(8) PORT MAP (
Asel,dp_RAMQ,dp_RAMQ,Input,dp_addsub,dp_Amux);
-- Accumulator
U7: reg GENERIC MAP(8) PORT MAP(Clock, Clear, ALoad, dp_Amux, dp_A);
-- Adder-subtractor
U8: addsub GENERIC MAP(8) PORT
MAP(Sub,dp_A,dp_RAMQ,dp_addsub,open,open);
Aeq0 <= '1' WHEN dp_A = "00000000" ELSE '0';
Apos <= NOT dp_A(7);
Output <= dp_A;
END Structural;
======================================================================