-
Notifications
You must be signed in to change notification settings - Fork 0
/
OnebitHalfAdd.vhd
49 lines (36 loc) · 1.01 KB
/
OnebitHalfAdd.vhd
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
-- Sub entity One Bit Half Adder
-- importing libraries
library work;
use work.all;
library IEEE;
use IEEE.std_logic_1164.all;
-- defining entity
entity OnebitHalfAdd is
port( a, b : in std_logic;
sum, carry: out std_logic
);
end entity;
--defining architecture
architecture halfadd of OnebitHalfAdd is
-- intermediate variables
signal ac, a1, a0: std_logic;
-- component declaration
component TwoByOneMux
port(i : in std_logic_vector(1 downto 0);
sel : in std_logic;
z : out std_logic
);
end component;
begin
-- instantiating required mux and connecting them for half adder
mux1 : TwoByOneMux
port map (i(1) => '0', i(0) => '1', sel => b, z => a1);
mux2 : TwoByOneMux
port map (i(1) => '1', i(0) => '0', sel => b, z=> a0);
mux3 : TwoByOneMux
port map (i(1) => a1, i(0) => a0, sel => a, z=> sum);
mux4 : TwoByOneMux
port map (i(0) => '0', i(1) => '1', sel => b, z=> ac);
mux5 : TwoByOneMux
port map (i(0) => '0', i(1) => ac, sel => a, z=> carry);
end architecture;