Skip to content

Commit 9be8b47

Browse files
authored
Add files via upload
1 parent af7a4a9 commit 9be8b47

19 files changed

+1440
-0
lines changed

CAR.vhd

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
----------------------------------------------------------------------------------
2+
-- Company:
3+
-- Engineer:
4+
--
5+
-- Create Date: 20:52:36 06/25/2017
6+
-- Design Name:
7+
-- Module Name: CAR - Behavioral
8+
-- Project Name:
9+
-- Target Devices:
10+
-- Tool versions:
11+
-- Description:
12+
--
13+
-- Dependencies:
14+
--
15+
-- Revision:
16+
-- Revision 0.01 - File Created
17+
-- Additional Comments:
18+
--
19+
----------------------------------------------------------------------------------
20+
library IEEE;
21+
use IEEE.STD_LOGIC_1164.ALL;
22+
23+
-- Uncomment the following library declaration if using
24+
-- arithmetic functions with Signed or Unsigned values
25+
--use IEEE.NUMERIC_STD.ALL;
26+
27+
-- Uncomment the following library declaration if instantiating
28+
-- any Xilinx primitives in this code.
29+
--library UNISIM;
30+
--use UNISIM.VComponents.all;
31+
32+
entity CAR is
33+
port( clk, rst_n : in std_logic;
34+
memIndex_input : in std_logic_vector(3 downto 0);
35+
memIndex_output : out std_logic_vector(3 downto 0)
36+
);
37+
end CAR;
38+
39+
architecture Behavioral of CAR is
40+
signal temp : std_logic_vector(3 downto 0):="0000";
41+
begin
42+
process(clk, rst_n) begin
43+
if rst_n = '0' then
44+
temp <= "1111";
45+
else
46+
if rising_edge(clk) then
47+
temp <= memIndex_input;
48+
end if;
49+
end if;
50+
end process;
51+
memindex_output <= temp;
52+
53+
54+
end Behavioral;
55+

CZN.vhd

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
----------------------------------------------------------------------------------
2+
-- Company:
3+
-- Engineer:
4+
--
5+
-- Create Date: 17:47:34 06/25/2017
6+
-- Design Name:
7+
-- Module Name: CZN - Behavioral
8+
-- Project Name:
9+
-- Target Devices:
10+
-- Tool versions:
11+
-- Description:
12+
--
13+
-- Dependencies:
14+
--
15+
-- Revision:
16+
-- Revision 0.01 - File Created
17+
-- Additional Comments:
18+
--
19+
----------------------------------------------------------------------------------
20+
library IEEE;
21+
use IEEE.STD_LOGIC_1164.ALL;
22+
23+
-- Uncomment the following library declaration if using
24+
-- arithmetic functions with Signed or Unsigned values
25+
use IEEE.NUMERIC_STD.ALL;
26+
27+
-- Uncomment the following library declaration if instantiating
28+
-- any Xilinx primitives in this code.
29+
--library UNISIM;
30+
--use UNISIM.VComponents.all;
31+
32+
entity CZN is
33+
port(
34+
clk : in std_logic;
35+
cznWrite : in std_logic;
36+
CZNin : in std_logic_vector(2 downto 0);
37+
CZNout : out std_logic_vector(2 downto 0)
38+
);
39+
end CZN;
40+
41+
architecture behave of CZN is
42+
43+
begin
44+
process (clk) begin
45+
if rising_edge(clk) then
46+
if cznWrite = '1' then
47+
CZNout <= CZNin;
48+
end if;
49+
end if;
50+
end process;
51+
52+
end behave;
53+

ControlMemory.vhd

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
----------------------------------------------------------------------------------
2+
-- Company:
3+
-- Engineer:
4+
--
5+
-- Create Date: 20:53:57 06/25/2017
6+
-- Design Name:
7+
-- Module Name: ControlMemory - Behavioral
8+
-- Project Name:
9+
-- Target Devices:
10+
-- Tool versions:
11+
-- Description:
12+
--
13+
-- Dependencies:
14+
--
15+
-- Revision:
16+
-- Revision 0.01 - File Created
17+
-- Additional Comments:
18+
--
19+
----------------------------------------------------------------------------------
20+
library IEEE;
21+
use IEEE.std_logic_1164.all;
22+
use IEEE.std_logic_unsigned.all;
23+
24+
entity ControlMemory is
25+
generic (K: integer:=19; -- number of bits per word (data size)
26+
W: integer:=4 -- number of address bits (address size)
27+
);
28+
port (
29+
clk, rst_n : std_logic;
30+
ADDR: in std_logic_vector (W-1 downto 0); -- RAM address
31+
DOUT: out std_logic_vector (K-1 downto 0)); -- read data
32+
end ControlMemory;
33+
34+
35+
architecture behave of ControlMemory is
36+
37+
subtype WORD is std_logic_vector ( K-1 downto 0); -- define size of WORD
38+
type MEMORY is array (0 to 2**W-1) of WORD; -- define size of MEMORY
39+
signal RAM16: MEMORY; -- define RAM16 as signal of type MEMORY
40+
41+
begin
42+
process (clk, rst_n, ADDR, RAM16)
43+
44+
variable RAM_ADDR_IN: integer range 0 to 2**W-1; -- to translate address to integer
45+
--variable STARTUP: boolean :=true; -- temporary variable for initialization
46+
47+
begin
48+
if (rst_n = '0') then -- for initialization of RAM during start of simulation
49+
RAM16 <= (0 => "0100010000000000011", -- initializes first 12 locations in Control Memory
50+
1 => "0000001000000000001", -- to specific values
51+
2 => "0000000110100000000",
52+
3 => "0000000110100100100",
53+
4 => "0000000110101000100",
54+
5 => "0000000110101010100",
55+
6 => "0000000000000001000",
56+
7 => "0001000000000000010",
57+
8 => "1010000000000000000",
58+
9 => "0100000001100000000",
59+
10 => "0101100000000000000",
60+
11 => "0100000000110010100",
61+
12 => "0100000000111000100",
62+
others => "0000000000000000000"
63+
);
64+
DOUT <= "XXXXXXXXXXXXXXXXXXX"; -- force undefined logic values on RAM output
65+
else
66+
--if rising_edge(clk) then
67+
RAM_ADDR_IN := conv_integer (ADDR); -- converts address to integer
68+
--end if;
69+
DOUT <= RAM16 (RAM_ADDR_IN);
70+
end if;
71+
end process;
72+
73+
end architecture behave;
74+

Controller.vhd

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
----------------------------------------------------------------------------------
2+
-- Company:
3+
-- Engineer:
4+
--
5+
-- Create Date: 20:19:14 06/25/2017
6+
-- Design Name:
7+
-- Module Name: Controller - Behavioral
8+
-- Project Name:
9+
-- Target Devices:
10+
-- Tool versions:
11+
-- Description:
12+
--
13+
-- Dependencies:
14+
--
15+
-- Revision:
16+
-- Revision 0.01 - File Created
17+
-- Additional Comments:
18+
--
19+
----------------------------------------------------------------------------------
20+
library IEEE;
21+
use IEEE.STD_LOGIC_1164.ALL;
22+
23+
-- Uncomment the following library declaration if using
24+
-- arithmetic functions with Signed or Unsigned values
25+
--use IEEE.NUMERIC_STD.ALL;
26+
use ieee.std_logic_unsigned.all;
27+
28+
-- Uncomment the following library declaration if instantiating
29+
-- any Xilinx primitives in this code.
30+
--library UNISIM;
31+
--use UNISIM.VComponents.all;
32+
33+
entity Controller is
34+
port( clk, reset: in std_logic;
35+
opcode: in std_logic_vector(3 downto 0);
36+
pcSrc, pcWrite, pcWriteCond, IorD, MemWrite, IRWrite1, IRWrite2, MUXR1,
37+
RegDST, MemToReg, RegWrite, AluSrc2, DIWrite, CZNWrite : out std_logic;
38+
AluOp : out std_logic_vector(2 downto 0);
39+
controlmemData : out std_logic_vector(18 downto 0);
40+
nxtline :out std_logic_vector(3 downto 0);
41+
cardata : out std_logic_vector(3 downto 0)
42+
);
43+
44+
end Controller;
45+
46+
architecture behave of Controller is
47+
48+
component ROM1 is
49+
port(
50+
opcode: in std_logic_vector(3 downto 0);
51+
lineNumber: out std_logic_vector(3 downto 0)
52+
);
53+
end component;
54+
55+
component ROM2 is
56+
port(
57+
opcode: in std_logic_vector(2 downto 0);
58+
lineNumber: out std_logic_vector(3 downto 0)
59+
);
60+
end component;
61+
62+
component ControlMemory is
63+
generic (K: integer:=19; -- number of bits per word (data size)
64+
W: integer:=4 -- number of address bits (address size)
65+
);
66+
port ( clk, rst_n : std_logic;
67+
ADDR: in std_logic_vector (W-1 downto 0); -- RAM address
68+
DOUT: out std_logic_vector (K-1 downto 0)
69+
); -- read data
70+
end component;
71+
72+
component CAR is
73+
port( clk, rst_n : in std_logic;
74+
memIndex_input : in std_logic_vector(3 downto 0);
75+
memIndex_output : out std_logic_vector(3 downto 0)
76+
);
77+
end component;
78+
79+
component mux_2bits is
80+
Generic(W : integer :=4);
81+
Port (D0, D1, D2, D3 : in std_logic_vector(W-1 downto 0);
82+
S : in std_logic_vector(1 downto 0);
83+
Y : out std_logic_vector(W-1 downto 0));
84+
end component;
85+
86+
signal rom1ToMux : std_logic_vector(3 downto 0);
87+
signal rom2ToMux : std_logic_vector(3 downto 0);
88+
signal nextLine : std_logic_vector(3 downto 0);
89+
signal seq : std_logic_vector(1 downto 0) := "00";
90+
signal muxOut : std_logic_vector(3 downto 0);
91+
signal CARout : std_logic_vector(3 downto 0);
92+
signal controlWord : std_logic_vector(18 downto 0) := (others => '0');
93+
signal nextlinetemp : std_logic_vector(3 downto 0);
94+
signal zero4Signal : std_logic_vector(3 downto 0);
95+
96+
97+
begin
98+
R1: ROM1 port map(opcode, rom1ToMux);
99+
R2: ROM2 port map(opcode(3 downto 1), rom2ToMux);
100+
101+
zero4signal <= "0000";
102+
M: mux_2bits port map(zero4signal, rom1ToMux, rom2ToMux, nextLine, seq, muxOut);
103+
104+
C: CAR port map(clk, reset, muxOut, CARout);
105+
cardata <= carout;
106+
107+
Mem: ControlMemory port map(clk, reset, CARout, controlWord);
108+
109+
seq <= controlWord(1 downto 0);
110+
nextlinetemp <= CARout + "0001";
111+
nextLine <= nextlinetemp;
112+
nxtline <= nextline;
113+
controlmemData <= controlword;
114+
115+
process (clk, reset, controlword) begin
116+
if(reset = '0') then
117+
pcsrc <= '0';
118+
pcwrite <= '0';
119+
pcwritecond <= '0';
120+
iord <= '0';
121+
memwrite <= '0';
122+
irwrite1 <= '0';
123+
irwrite2 <= '0';
124+
muxr1 <= '0';
125+
regdst <= '0';
126+
memtoreg <= '0';
127+
regwrite <= '0';
128+
alusrc2 <= '0';
129+
aluop <= "000";
130+
diwrite <= '0';
131+
cznwrite <= '0';
132+
else
133+
pcsrc <= controlWord(18);
134+
pcwrite <= controlWord(17);
135+
pcwritecond <= controlWord(16);
136+
iord <= controlWord(15);
137+
memwrite <= controlWord(14);
138+
irwrite1 <= controlWord(13);
139+
irwrite2 <= controlWord(12);
140+
muxr1 <= controlWord(11);
141+
regdst <= controlWord(10);
142+
memtoreg <= controlWord(9);
143+
regwrite <= controlWord(8);
144+
alusrc2 <= controlWord(7);
145+
aluop <= controlWord(6 downto 4);
146+
diwrite <= controlWord(3);
147+
cznwrite <= controlWord(2);
148+
end if;
149+
end process;
150+
151+
152+
end behave;
153+

DI.vhd

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
----------------------------------------------------------------------------------
2+
-- Company:
3+
-- Engineer:
4+
--
5+
-- Create Date: 17:03:20 06/25/2017
6+
-- Design Name:
7+
-- Module Name: DI - Behavioral
8+
-- Project Name:
9+
-- Target Devices:
10+
-- Tool versions:
11+
-- Description:
12+
--
13+
-- Dependencies:
14+
--
15+
-- Revision:
16+
-- Revision 0.01 - File Created
17+
-- Additional Comments:
18+
--
19+
----------------------------------------------------------------------------------
20+
library IEEE;
21+
use IEEE.STD_LOGIC_1164.ALL;
22+
23+
-- Uncomment the following library declaration if using
24+
-- arithmetic functions with Signed or Unsigned values
25+
use IEEE.NUMERIC_STD.ALL;
26+
27+
-- Uncomment the following library declaration if instantiating
28+
-- any Xilinx primitives in this code.
29+
--library UNISIM;
30+
--use UNISIM.VComponents.all;
31+
32+
entity DI is
33+
port( clk : in std_logic;
34+
rst_n : in std_logic;
35+
writeDI : in std_logic;
36+
Din : in std_logic_vector(4 downto 0);
37+
Dout : out std_logic_vector(4 downto 0)
38+
);
39+
end DI;
40+
41+
architecture behave of DI is
42+
43+
begin
44+
process (clk, rst_n)
45+
begin
46+
if rst_n = '0' then
47+
Dout <= (others => '0');
48+
elsif rising_edge(clk) then
49+
if(writeDI = '1') then
50+
Dout <= Din;
51+
end if;
52+
end if;
53+
end process;
54+
55+
end behave;
56+

0 commit comments

Comments
 (0)