EXP 1: To Model Logic Gates (A) As Indivisible Entities, (B) Using NAND Gates and (C) Using NOR Gates
EXP 1: To Model Logic Gates (A) As Indivisible Entities, (B) Using NAND Gates and (C) Using NOR Gates
EXP 2: To model (a) a half adder, (b) a full adder using two half adders and (c) a
4-bit adder-subtractor.
Code for part (a) and (b)
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity half_adder_entity is
port(
a,b : in std_logic;
s,c : out std_logic
);
end half_adder_entity;
architecture half_adder_arch of half_adder_entity is
begin
s <= a xor b;
c <= a and b;
end half_adder_arch;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity full_adder_entity is
port(
inp1,inp2,inp3 : in std_logic;
sum,carry : out std_logic
);
end full_adder_entity;
architecture full_adder_arch of full_adder_entity is
signal x,y,z:std_logic;
component half_adder_entity
port(
a,b:in std_logic;
s,c:out std_logic
);
end component;
begin
H1:half_adder_entity port map(inp1,inp2,x,y);
H2:half_adder_entity port map(x,inp3,sum,z);
carry <= y or z;
end full_adder_arch;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity fulladder_entity is
port (
inp1,inp2,cin:in std_logic;
s,c:out std_logic
);
end fulladder_entity;
architecture fulladder_arch of fulladder_entity is
begin
s <= inp1 xor inp2 xor cin;
c <= (inp1 and inp2) or (inp2 and cin) or (inp1 and cin);
end architecture;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
entity addersubtractor_entity is
port(
a0,a1,a2,a3,b0,b1,b2,b3,mode:in std_logic;
out0,out1,out2,out3,carry:out std_logic
);
end addersubtractor_entity;
architecture addersubtractor_arch of addersubtractor_entity is
signal carry0,carry1,carry2,temp0,temp1,temp2,temp3:std_logic;
component fulladder_entity
port (
inp1,inp2,cin:in std_logic;
s,c:out std_logic
);
end component;
begin
temp0<=b0 xor mode;
temp1<=b1 xor mode;
temp2<=b2 xor mode;
temp3<=b3 xor mode;
FA1:fulladder_entity port map(a0,temp0,mode,out0,carry0);
FA2:fulladder_entity port map(a1,temp1,carry0,out1,carry1);
FA3:fulladder_entity port map(a2,temp2,carry1,out2,carry2);