Structural Model Codes
Structural Model Codes
library ieee;
use ieee.std_logic_1164.all;
entity xor_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end xor_gate;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity or_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end or_gate;
architecture behavior of or_gate is
begin
o1 <= i1 or i2;
end behavior;
entity half_adder is
port (a, b: in std_logic;
sum, carry_out: out std_logic);
end half_adder;
component xor_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
begin
u1: xor_gate port map (i1 => a, i2 => b, o1 => sum);
u2: and_gate port map (i1 => a, i2 => b, o1 => carry_out);
end structure;
entity full_adder is
port (a, b, cin: in std_logic;
sum, cout: out std_logic);
end full_adder;
component half_adder
port (a, b: in std_logic;
sum, carry_out: out std_logic);
end component;
begin
ha1: half_adder port map (a => a, b => b, sum => s1, carry_out => c1);
ha2: half_adder port map (a => s1, b => cin, sum => sum, carry_out => c2);
cout <= c1 or c2;
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity xor_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end xor_gate;
architecture behavior of xor_gate is
begin
o1 <= i1 xor i2;
end behavior;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity half_subtractor is
port (a, b: in std_logic;
diff, borrow_out: out std_logic);
end half_subtractor;
component xor_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: xor_gate port map (i1 => a, i2 => b, o1 => diff);
u2: not_gate port map (i1 => a, o1 => not_a);
u3: and_gate port map (i1 => not_a, i2 => b, o1 => borrow_out);
end structure;
entity full_subtractor is
port (a, b, bin: in std_logic;
diff, bout: out std_logic);
end full_subtractor;
component half_subtractor
port (a, b: in std_logic;
diff, borrow_out: out std_logic);
end component;
begin
hs1: half_subtractor port map (a => a, b => b, diff => d1, borrow_out => b1);
hs2: half_subtractor port map (a => d1, b => bin, diff => diff, borrow_out => b2);
b3 <= (not a) and bin;
bout <= b1 or b2 or b3;
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity or_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end or_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity mux_2x1 is
port (in0, in1, s: in std_logic;
z: out std_logic);
end mux_2x1;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component or_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => in0, i2 => not_s, o1 => and0);
u3: and_gate port map (i1 => in1, i2 => s, o1 => and1);
u4: or_gate port map (i1 => and0, i2 => and1, o1 => z);
end structure;
entity mux_4x1 is
port (in0, in1, in2, in3: in std_logic;
s0, s1: in std_logic;
z: out std_logic);
end mux_4x1;
component mux_2x1
port (in0, in1, s: in std_logic;
z: out std_logic);
end component;
begin
mux1: mux_2x1 port map (in0 => in0, in1 => in1, s => s0, z => m1);
mux2: mux_2x1 port map (in0 => in2, in1 => in3, s => s0, z => m2);
mux3: mux_2x1 port map (in0 => m1, in1 => m2, s => s1, z => z);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity or_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end or_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity mux_2x1 is
port (in0, in1, s: in std_logic;
z: out std_logic);
end mux_2x1;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component or_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => in0, i2 => not_s, o1 => and0);
u3: and_gate port map (i1 => in1, i2 => s, o1 => and1);
u4: or_gate port map (i1 => and0, i2 => and1, o1 => z);
end structure;
entity mux_8x1 is
port (in0, in1, in2, in3, in4, in5, in6, in7: in std_logic;
s0, s1, s2: in std_logic;
z: out std_logic);
end mux_8x1;
component mux_2x1
port (in0, in1, s: in std_logic;
z: out std_logic);
end component;
begin
mux1: mux_2x1 port map (in0 => in0, in1 => in1, s => s0, z => m1);
mux2: mux_2x1 port map (in0 => in2, in1 => in3, s => s0, z => m2);
mux3: mux_2x1 port map (in0 => in4, in1 => in5, s => s0, z => m3);
mux4: mux_2x1 port map (in0 => in6, in1 => in7, s => s0, z => m4);
mux5: mux_2x1 port map (in0 => m1, in1 => m2, s => s1, z => m5);
mux6: mux_2x1 port map (in0 => m3, in1 => m4, s => s1, z => m6);
mux7: mux_2x1 port map (in0 => m5, in1 => m6, s => s2, z => z);
end structure;
8x1MUX using 4x1MUX:
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity or_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end or_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
architecture behavior of not_gate is
begin
o1 <= not i1;
end behavior;
entity mux_2x1 is
port (in0, in1, s: in std_logic;
z: out std_logic);
end mux_2x1;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component or_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
end structure;
entity mux_4x1 is
port (in0, in1, in2, in3: in std_logic;
s0, s1: in std_logic;
z: out std_logic);
end mux_4x1;
component mux_2x1
port (in0, in1, s: in std_logic;
z: out std_logic);
end component;
begin
mux1: mux_2x1 port map (in0 => in0, in1 => in1, s => s0, z => m1);
mux2: mux_2x1 port map (in0 => in2, in1 => in3, s => s0, z => m2);
mux3: mux_2x1 port map (in0 => m1, in1 => m2, s => s1, z => z);
end structure;
entity mux_8x1 is
port (in0, in1, in2, in3, in4, in5, in6, in7: in std_logic;
s0, s1, s2: in std_logic;
z: out std_logic);
end mux_8x1;
component mux_4x1
port (in0, in1, in2, in3: in std_logic;
s0, s1: in std_logic;
z: out std_logic);
end component;
begin
mux1: mux_4x1 port map (in0 => in0, in1 => in1, in2 => in2, in3 => in3, s0 => s0, s1 => s1, z
=> m1);
mux2: mux_4x1 port map (in0 => in4, in1 => in5, in2 => in6, in3 => in7, s0 => s0, s1 => s1, z
=> m2);
mux3: mux_2x1 port map (in0 => m1, in1 => m2, s => s2, z => z);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity or_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end or_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity mux_2x1 is
port (in0, in1, s: in std_logic;
z: out std_logic);
end mux_2x1;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component or_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => in0, i2 => not_s, o1 => and0);
u3: and_gate port map (i1 => in1, i2 => s, o1 => and1);
u4: or_gate port map (i1 => and0, i2 => and1, o1 => z);
end structure;
entity mux_4x1 is
port (in0, in1, in2, in3: in std_logic;
s0, s1: in std_logic;
z: out std_logic);
end mux_4x1;
component mux_2x1
port (in0, in1, s: in std_logic;
z: out std_logic);
end component;
begin
mux1: mux_2x1 port map (in0 => in0, in1 => in1, s => s0, z => m1);
mux2: mux_2x1 port map (in0 => in2, in1 => in3, s => s0, z => m2);
mux3: mux_2x1 port map (in0 => m1, in1 => m2, s => s1, z => z);
end structure;
entity mux_16x1 is
port (in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, in12, in13, in14, in15: in
std_logic;
s0, s1, s2, s3: in std_logic;
z: out std_logic);
end mux_16x1;
component mux_4x1
port (in0, in1, in2, in3: in std_logic;
s0, s1: in std_logic;
z: out std_logic);
end component;
begin
mux1: mux_4x1 port map (in0 => in0, in1 => in1, in2 => in2, in3 => in3, s0 => s0, s1 => s1, z
=> m1);
mux2: mux_4x1 port map (in0 => in4, in1 => in5, in2 => in6, in3 => in7, s0 => s0, s1 => s1, z
=> m2);
mux3: mux_4x1 port map (in0 => in8, in1 => in9, in2 => in10, in3 => in11, s0 => s0, s1 =>
s1, z => m3);
mux4: mux_4x1 port map (in0 => in12, in1 => in13, in2 => in14, in3 => in15, s0 => s0, s1 =>
s1, z => m4);
mux5: mux_4x1 port map (in0 => m1, in1 => m2, in2 => m3, in3 => m4, s0 => s2, s1 => s3,
z => z);
end structure;
1x4Demux using 1x2Demux:
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
architecture structure of demux_1x2 is
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x4 is
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end demux_1x4;
begin
demux1: demux_1x2 port map (a => a, s => s1, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
end structure;
entity demux_1x8 is
port (a: in std_logic;
s0, s1, s2: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7: out std_logic);
end demux_1x8;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s2, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s1, y0 => d3, y1 => d4);
demux3: demux_1x2 port map (a => d2, s => s1, y0 => d5, y1 => d6);
demux4: demux_1x2 port map (a => d3, s => s0, y0 => y0, y1 => y1);
demux5: demux_1x2 port map (a => d4, s => s0, y0 => y2, y1 => y3);
demux6: demux_1x2 port map (a => d5, s => s0, y0 => y4, y1 => y5);
demux7: demux_1x2 port map (a => d6, s => s0, y0 => y6, y1 => y7);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x4 is
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end demux_1x4;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s1, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
end structure;
entity demux_1x8 is
port (a: in std_logic;
s0, s1, s2: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7: out std_logic);
end demux_1x8;
component demux_1x4
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end component;
begin
demux1: demux_1x4 port map (a => a, s0 => s2, s1 => s1, y0 => d1, y1 => d2, y2 => d3, y3
=> d4);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
demux4: demux_1x2 port map (a => d3, s => s0, y0 => y4, y1 => y5);
demux5: demux_1x2 port map (a => d4, s => s0, y0 => y6, y1 => y7);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
signal not_s: std_logic;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x4 is
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end demux_1x4;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s1, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
end structure;
entity demux_1x16 is
port (a: in std_logic;
s0, s1, s2, s3: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15: out std_logic);
end demux_1x16;
component demux_1x4
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end component;
signal d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15: std_logic;
begin
demux1: demux_1x4 port map (a => a, s0 => s3, s1 => s2, y0 => d1, y1 => d2, y2 => d3, y3
=> d4);
demux2: demux_1x4 port map (a => d1, s0 => s1, s1 => s0, y0 => y0, y1 => y1, y2 => y2, y3
=> y3);
demux3: demux_1x4 port map (a => d2, s0 => s1, s1 => s0, y0 => y4, y1 => y5, y2 => y6, y3
=> y7);
demux4: demux_1x4 port map (a => d3, s0 => s1, s1 => s0, y0 => y8, y1 => y9, y2 => y10,
y3 => y11);
demux5: demux_1x4 port map (a => d4, s0 => s1, s1 => s0, y0 => y12, y1 => y13, y2 =>
y14, y3 => y15);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x4 is
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end demux_1x4;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s1, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x8 is
port (a: in std_logic;
s0, s1, s2: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7: out std_logic);
end demux_1x8;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s2, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s1, y0 => d3, y1 => d4);
demux3: demux_1x2 port map (a => d2, s => s1, y0 => d5, y1 => d6);
demux4: demux_1x2 port map (a => d3, s => s0, y0 => y0, y1 => y1);
demux5: demux_1x2 port map (a => d4, s => s0, y0 => y2, y1 => y3);
demux6: demux_1x2 port map (a => d5, s => s0, y0 => y4, y1 => y5);
demux7: demux_1x2 port map (a => d6, s => s0, y0 => y6, y1 => y7);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x4 is
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end demux_1x4;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s1, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
end structure;
entity demux_1x8 is
port (a: in std_logic;
s0, s1, s2: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7: out std_logic);
end demux_1x8;
architecture structure of demux_1x8 is
component demux_1x4
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end component;
begin
demux1: demux_1x4 port map (a => a, s0 => s2, s1 => s1, y0 => d1, y1 => d2, y2 => d3, y3
=> d4);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
demux4: demux_1x2 port map (a => d3, s => s0, y0 => y4, y1 => y5);
demux5: demux_1x2 port map (a => d4, s => s0, y0 => y6, y1 => y7);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
architecture behavior of and_gate is
begin
o1 <= i1 and i2;
end behavior;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity demux_1x2 is
port (a, s: in std_logic;
y0, y1: out std_logic);
end demux_1x2;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
u1: not_gate port map (i1 => s, o1 => not_s);
u2: and_gate port map (i1 => a, i2 => not_s, o1 => y0);
u3: and_gate port map (i1 => a, i2 => s, o1 => y1);
end structure;
entity demux_1x4 is
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end demux_1x4;
component demux_1x2
port (a, s: in std_logic;
y0, y1: out std_logic);
end component;
begin
demux1: demux_1x2 port map (a => a, s => s1, y0 => d1, y1 => d2);
demux2: demux_1x2 port map (a => d1, s => s0, y0 => y0, y1 => y1);
demux3: demux_1x2 port map (a => d2, s => s0, y0 => y2, y1 => y3);
end structure;
entity demux_1x16 is
port (a: in std_logic;
s0, s1, s2, s3: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15: out std_logic);
end demux_1x16;
component demux_1x4
port (a: in std_logic;
s0, s1: in std_logic;
y0, y1, y2, y3: out std_logic);
end component;
signal d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15: std_logic;
begin
demux1: demux_1x4 port map (a => a, s0 => s3, s1 => s2, y0 => d1, y1 => d2, y2 => d3, y3
=> d4);
demux2: demux_1x4 port map (a => d1, s0 => s1, s1 => s0, y0 => y0, y1 => y1, y2 => y2, y3
=> y3);
demux3: demux_1x4 port map (a => d2, s0 => s1, s1 => s0, y0 => y4, y1 => y5, y2 => y6, y3
=> y7);
demux4: demux_1x4 port map (a => d3, s0 => s1, s1 => s0, y0 => y8, y1 => y9, y2 => y10,
y3 => y11);
demux5: demux_1x4 port map (a => d4, s0 => s1, s1 => s0, y0 => y12, y1 => y13, y2 =>
y14, y3 => y15);
end structure;
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
-- Invert input bits
u1: not_gate port map (i1 => input(1), o1 => not_a);
u2: not_gate port map (i1 => input(0), o1 => not_b);
end structure;
entity decoder_3x8 is
port (input: in std_logic_vector(2 downto 0);
output: out std_logic_vector(7 downto 0));
end decoder_3x8;
component decoder_2x4
port (input: in std_logic_vector(1 downto 0);
en: in std_logic;
output: out std_logic_vector(3 downto 0));
end component;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
-- Invert c for the second decoder enable
u1: not_gate port map (i1 => input(2), o1 => not_c);
end structure;
4x16Decoder using 2x4Decoder:
library ieee;
use ieee.std_logic_1164.all;
entity and_gate is
port (i1, i2: in std_logic;
o1: out std_logic);
end and_gate;
entity not_gate is
port (i1: in std_logic;
o1: out std_logic);
end not_gate;
entity decoder_2x4 is
port (a, b: in std_logic;
en: in std_logic;
y0, y1, y2, y3: out std_logic);
end decoder_2x4;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
component not_gate
port (i1: in std_logic;
o1: out std_logic);
end component;
begin
-- Invert inputs
u1: not_gate port map (i1 => a, o1 => not_a);
u2: not_gate port map (i1 => b, o1 => not_b);
end structure;
entity decoder_4x16 is
port (a, b, c, d: in std_logic;
y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15: out std_logic);
end decoder_4x16;
component decoder_2x4
port (a, b: in std_logic;
en: in std_logic;
y0, y1, y2, y3: out std_logic);
end component;
component and_gate
port (i1, i2: in std_logic;
o1: out std_logic);
end component;
signal not_d, d0, d1, d2, d3, e0, e1, e2, e3: std_logic_vector(3 downto 0);
begin
u1: not_gate port map (i1 => d, o1 => not_d);
dec1: decoder_2x4 port map (a => a, b => b, en => c, y0 => d0(0), y1 => d0(1), y2 => d0(2),
y3 => d0(3));
dec2: decoder_2x4 port map (a => a, b => b, en => not_d, y0 => e0(0), y1 => e0(1), y2 =>
e0(2), y3 => e0(3));
dec3: decoder_2x4 port map (a => c, b => d, en => '1', y0 => d1(0), y1 => d1(1), y2 =>
d1(2), y3 => d1(3));
dec4: decoder_2x4 port map (a => c, b => not_d, en => '1', y0 => e1(0), y1 => e1(1), y2 =>
e1(2), y3 => e1(3));
end structure;