-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogicComponents.vhd
More file actions
86 lines (78 loc) · 2.01 KB
/
LogicComponents.vhd
File metadata and controls
86 lines (78 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 08:21:44 05/06/2014
-- Design Name:
-- Module Name: LogicComponents - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
entity adder is -- adder
generic(width: integer);
port(a, b: in STD_LOGIC_VECTOR(width-1 downto 0);
y: out STD_LOGIC_VECTOR(width-1 downto 0));
end;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity mux2 is -- two-input multiplexer
generic(width: integer);
port(d0, d1: in STD_LOGIC_VECTOR(width-1 downto 0);
s: in STD_LOGIC;
y: out STD_LOGIC_VECTOR(width-1 downto 0));
end;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity mux4 is -- four-input multiplexer
generic(width: integer);
port(d0, d1, d2, d3: in STD_LOGIC_VECTOR(width-1 downto 0);
s: in STD_LOGIC_VECTOR(1 downto 0);
y: out STD_LOGIC_VECTOR(width-1 downto 0));
end;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity pc is -- program counter
port(clk_in: in std_logic;
pc_in: in STD_LOGIC_VECTOR(15 downto 0);
pc_out: out STD_LOGIC_VECTOR(15 downto 0));
end;
architecture behave of adder is
begin
y <= std_logic_vector(signed(a) + signed(b));
end;
architecture behave of pc is
signal count : std_logic_vector(15 downto 0) := (OTHERS => '0');
begin
pc_out <= count;
process(clk_in) begin
if clk_in'event and clk_in = '0' then
count <= pc_in;
end if;
end process;
end;
architecture behave of mux2 is
begin
y <= d0 when s = '0' else d1;
end;
architecture behave of mux4 is
begin
with s select
y <= d0 when "00",
d1 when "01",
d2 when "10",
d3 when others;
end;