CoA Lab Manual
CoA Lab Manual
Organization
and Architecture
Lab Manual
Semester IV
Reference Resources
https://github.com/Abhiroop2004/Computer-Organization-and-Architecture-Lab
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Theory:
The basic logic gates are the building blocks of more complex logic circuits.
These logic gates perform the basic Boolean func ons, such as AND, OR,
NAND, NOR, Inversion, Exclusive-OR, Exclusive-NOR. It is seen that each gate
has one or two binary inputs, A and B, and one binary output, C. The small
circle on the output of the circuit symbols designates the logic complement.
The AND, OR, NAND, and NOR gates can be extended to have more than two
inputs. A gate can be extended to have mul ple inputs if the binary opera on
it represents is commuta ve and associa ve. These basic logic gates are
implemented as small-scale integrated circuits (SSICs) or as part of more
complex medium scale (MSI) or very large-scale (VLSI) integrated circuits.
The OR, AND, and NOT are the three basic logic gates as they together can
construct the logic circuit for any given Boolean expression. NOR and NAND
gates have the property that they individually can be used to hardware-
implement any logic circuit. For this reason, the NAND and NOR gates are
called universal gates.
Observations
INPUT OUTPUT
A B AND NAND OR NOR XOR NOT GATE
INPUT
0 0 OUTPUT
0 1 0
1 0 1
1 1
-- DUT component
component not_gate is
port(
a : in std_logic;
q : out std_logic);
end component;
Please provide the waveforms generated by your code and specify whether they verify truth tables
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Theory:
Half-Adder
A half-adder is a combina onal logic circuit that performs the addi on of two
bits, A and B. The output of the half-adder is two bits: the sum bit, S, and the
carry bit, C. The Boolean func ons describing the half-adder are as follows:
Sum bit: S = A ⊕ B Carry bit: C = A ⋅ B
Half-Adder using X-OR and basic gates Half-Adder using NAND gate only
Full-Adder
A full-adder is a combina onal
logic circuit that performs the
addi on of two bits, A and B, and
a carry-in bit, Cin. The output of
the full-adder is two bits: the
sum bit, S, and the carry bit, Cout.
Sum bit: S = (A ⊕ B) ⊕ Cin
Carry bit: Cout = A ⋅ B + Cin ⋅ (A ⊕ B) Full-Adder using X-OR and basic gates
Full-Adder using
NAND gate only
Full Adder
INPUT OUTPUT
A B Cin Sum Cout
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Structural Model
library ieee;
use ieee.std_logic_1164.all;
en ty half_adder is
port (a, b: in std_logic;
sum, carry: out std_logic); architecture structure of half_adder is
component xor_gate
end half_adder; 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;
Please provide the waveforms generated by your code and specify whether they verify truth tables
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Full Subtractor
INPUT Using XOR and basic gates Using NAND gate only
X Y Bin D B D B
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Dataflow Model
library ieee;
use ieee.std_logic_1164.all;
en ty Fullsubtractor is
port (a, b, borrowin: in std_logic;
difference, borrowout: out std_logic);
end Fullsubtractor;
Please provide the waveforms generated by your code and specify whether they verify truth tables
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Theory:
Mul plexing is the generic term used to describe the opera on of sending one
or more analogue or digital signals over a common transmission line at
different mes or speeds and the device used to do that is called Mul plexer.
The mul plexer, shortened to “MUX” or “MPX”, is a combina onal logic circuit
designed to switch one of several input lines through to a single common
output line by the applica on of a control signal. Mul plexers operate like very
fast ac ng mul ple posi on rotary switches connec ng or controlling mul ple
input lines called “channels” one at a me to the output. Mul plexers, or
MUX’s, can be either digital circuits made from high-speed logic gates used to
switch digital or binary data or they can be analogue types using transistors,
MOSFET’s or relays to switch one of the voltage or current inputs through to a
single output.
Basic
Mul plexing
Switch
The rotary switch, also called a wafer switch as each layer of the switch is
known as a wafer, is a mechanical device whose input is selected by rota ng a
sha . In other words, the rotary switch is a manual switch that you can use to
select individual data or signal lines simply by turning its inputs “ON” or “OFF”.
So how can we select each data input automa cally using a digital device.
In digital electronics, mul plexers are also known as data selectors because
they can “select” each input line, are constructed from individual Analogue
Switches encased in a single IC package as opposed to the “mechanical” type
selectors such as normal conven onal switches and relays.
They are used as one method of
reducing the number of logic
gates required in a circuit
design or when a single data
line or data bus is required to
carry two or more different
digital signals. For example, a
single 8-channel mul plexer.
Please provide the waveforms generated by your code and specify whether they verify truth tables
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Encoder:
An encoder is a digital circuit that converts a set of binary inputs into a unique
binary code. The binary code represents the posi on of the input and is used
to iden fy the specific input that is ac ve. Encoders are commonly used in
digital systems to convert a parallel set of inputs into a serial code.
The basic principle of an encoder is to assign a unique binary code to each
possible input. For example, a 2-to-4 line encoder has 2 input lines and 4
output lines and assigns a unique 4-bit binary code to each of the 22 = 4
possible input combina ons.
There are different types of encoders, including priority encoders, which
assign a priority to each input, and binary-weighted encoders, which use a
binary weigh ng system to assign binary codes to inputs. Encoders are widely
used in digital systems to convert parallel inputs into serial codes.
An Encoder has a maximum of 2n input lines and ‘n’ output lines, hence it
encodes the informa on from 2n inputs into an n-bit code. It will produce a
binary code equivalent to the input, which is ac ve High. Therefore, the
encoder encodes 2n input lines with ‘n’ bits.
Truth Table
INPUT OUTPUT
Y3 Y2 Y1 Y0 A1 A0
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
Logical expressions:
A 1=
A 0=
en ty encoder is en ty encoder is
port( port(
i : in std_logic_vector(3 downto 0); i : in std_logic_vector(3 downto 0);
o1, o0 : out std_logic ); o1, o0 : out std_logic );
end encoder; end encoder;
architecture dataflow of encoder is architecture behavioral of encoder is
begin process(i)
o<= i(3) & i(2); begin
end dataflow; if i(3) = '1' then
o <= "00";
elsif i(2) = '1' then
o <= "01";
elsif i(1) = '1' then
o <= "10";
else
o <= "11";
end if;
end process;
end architecture behavioral;
Decoder
A binary decoder is a digital circuit that converts a binary code into a set of
outputs. The binary code represents the posi on of the desired output and is
used to select the specific output that is ac ve. Binary decoders are commonly
used in digital systems to convert a serial code into a parallel set of outputs.
The basic principle of a binary decoder is to assign a unique output to each
possible binary code. For example, a binary decoder with 2 inputs and 22 = 4
outputs can assign a unique output to each of the 4 possible 2-bit binary codes
In Digital Electronics, discrete quan es of informa on are represented by
binary codes. A binary code of n bits is capable of represen ng up to 2n dis nct
coded informa on. A decoder is a combina onal circuit that converts binary
informa on from n input lines to a maximum of 2n unique output lines.
If a binary decoder receives n inputs it ac vates only one of its 2n outputs
based on that input with all other outputs deac vated. If the n-bit coded
informa on has unused combina ons, the decoder may have fewer than 2n
outputs. Binary decoders generate the 2n (or fewer) minterms of n input
variables with each input combina on asser ng a unique output.
Please provide the waveforms generated by your code and specify whether they verify truth tables
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Theory:
Ripple Carry Adders offer a straigh orward approach to binary addi on using
cascaded full adders to gives the results of the addi on of two n bit binary
sequence. This adder includes cascaded full adders in its structure so, the carry
will be generated at every full adder stage in a ripple-carry adder circuit. These
carry output at each full adder stage is forwarded to its next full adder and
there applied as a carry input to it. This process con nues up to its last full
adder stage. So, each carry output bit is rippled to the next stage of a full adder.
By this reason, it is named as “Ripple Carry Adder”.
Ripple Carry Adders serve as essen al components in digital computers for
performing binary addi on. By employing basic logic gates like AND, OR, and
XOR, these adders enable the addi on of mul -bit binary numbers.
In a Ripple Carry Adder, each full adder waits for the carry bit from the previous
full adder, thus propaga ng the carry bit through the chain. While they
facilitate rapid design due to their simple layout, their performance is limited
by carry propaga on delays, resul ng in rela vely slower opera on compared
to alterna ve adder designs.
The expressions for sum and carry for each stage is same as that of a full adder:
Sumi = Ai ⊕ Bi ⊕ Ci-1 Carryi = AiBi + ACi-1 + BCi-1
Truth Table (Full Adder)
INPUT OUTPUT
Ai Bi Ci-1 Sumi Carryi
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
component Ripple_Adder
port(A, B : in std_logic_vector(3 downto 0);
Cin : in std_logic;
S : out std_logic_vector(3 downto 0);
Cout : out std_logic);
end component;
begin
dut: Ripple_Adder port map ( A, B, Cin, S, Cout);
process
begin
A <= "1000"; B <= "0001"; Cin <= '0'; wait for 10 ns;
assert (S="1001" and Cout='0') report "Fail 1000/0001/0" severity error;
A <= "0100"; B <= "0010"; Cin <= '1'; wait for 10 ns;
assert (S="0111" and Cout='0') report "Fail 0100/0010/1" severity error;
A <= "0010"; B <= "0100"; Cin <= '0'; wait for 10 ns;
assert (S="0110" and Cout='0') report "Fail 0010/0100/0" severity error;
A <= "0001"; B <= "1000"; Cin <= '1'; wait for 10 ns;
assert (S="1010" and Cout='0') report "Fail 0001/1000/1" severity error;
A <= "0000"; B <= "0000"; Cin <= '0'; wait for 10 ns;
assert (S="0000" and Cout='0') report "Fail 0000/0000/0" severity error;
A <= "1111"; B <= "1111"; Cin <= '1'; wait for 10 ns;
assert (S="1111" and Cout='1') report "Fail 1111/1111/1" severity error;
A <= "0110"; B <= "0110"; Cin <= '0'; wait for 10 ns;
assert (S="1100" and Cout='0') report "Fail 0110/0110/0" severity error;
en ty Ripple_Adder is
port ( A, B : in std_logic_vector (3 downto 0);
Cin : in std_logic;
S : out std_logic_vector (3 downto 0);
Cout : out std_logic);
end Ripple_Adder;
architecture structural of Ripple_Adder is
component full_adder is
port (
a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum : out std_logic;
cout : out std_logic
);
end component;
signal carry : std_logic_vector (3 downto 0);
begin
u0 : full_adder port map (a(0), b(0), '0', sum(0), carry(0));
u1 : full_adder port map (a(1), b(1), carry(0), sum(1), carry(1));
u2 : full_adder port map (a(2), b(2), carry(1), sum(2), carry(2));
u3 : full_adder port map (a(3), b(3), carry(2), sum(3), carry_out);
end architecture structural;
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Theory:
In ripple carry adders, each adder block waits for the carry to arrive from its
previous block. The ith block waits for the i-1th block to produce its carry. This
causes carry propaga on delay, which increases as the number of bits increase
Consider a 4-bit ripple carry adder. Even a er inputs A3 and B3 are given, the
4th full adder cannot produce steady state outputs un l C3 is available at its
final steady-state value. Similarly C3 depends on C2 and C2 on C1. Therefore,
though the carry must propagate to all the stages in order that outputs S3 and
C4 se le at their final steady-state value.
The propaga on me is equal to the propaga on delay of each adder block,
mul plied by the number of adder blocks in the circuit. For example, if each
full adder stage has a propaga on delay of 20 nanoseconds, then S3 will reach
its final correct value a er 60 (20 × 3) nanoseconds. The situa on gets worse,
if we extend the number of stages for adding more number of bits.
By subs tu ng the previous carry value (Ci) into the expression for Ci+1, we get:
C1 = G0 + P0·C0
C2 = G1 + P1·C1 = G1 + P1·G0 + P1·P0·C0
C3 = G2 + P2·C2 = G2 + P2·G1 + P2·P1·G0 + P2·P1·P0·C0
C4 = G3 + P3·C3 = G3 + P3·G2·P2·G1 + P3·P2·P1·G0 + P3·P2·P1·P0·C0
Carry calculation
Sum calculation
CLA can generate the en re output in 4 gate delays. 1 gate delay for genera ng
the carry propagators and carry generators; 2 gate delays for the compu ng
the carry bit and 1 addi onal gate delay for compu ng the sum bit
component CLA
port(A, B : in std_logic_vector(3 downto 0);
Cin : in std_logic;
S : out std_logic_vector(3 downto 0);
Cout : out std_logic);
end component;
begin
DUT: CLA port map ( A, B, Cin, S, Cout);
process
begin
A <= "1000"; B <= "0001"; Cin <= '0'; wait for 10 ns;
assert (S="1001" and Cout='0') report "Fail 1000/0001/0" severity error;
A <= "0100"; B <= "0010"; Cin <= '1'; wait for 10 ns;
assert (S="0111" and Cout='0') report "Fail 0100/0010/1" severity error;
A <= "0010"; B <= "0100"; Cin <= '0'; wait for 10 ns;
assert (S="0110" and Cout='0') report "Fail 0010/0100/0" severity error;
A <= "0001"; B <= "1000"; Cin <= '1'; wait for 10 ns;
assert (S="1010" and Cout='0') report "Fail 0001/1000/1" severity error;
A <= "0000"; B <= "0000"; Cin <= '0'; wait for 10 ns;
assert (S="0000" and Cout='0') report "Fail 0000/0000/0" severity error;
A <= "1111"; B <= "1111"; Cin <= '1'; wait for 10 ns;
assert (S="1111" and Cout='1') report "Fail 1111/1111/1" severity error;
A <= "0110"; B <= "0110"; Cin <= '0'; wait for 10 ns;
assert (S="1100" and Cout='0') report "Fail 0110/0110/0" severity error;
en ty CLA is
port (A, B : in std_logic_vector(3 downto 0);
Cin : in std_logic;
S : out std_logic_vector(3 downto 0);
Cout : out std_logic);
end CLA;
architecture dataflow of CLA is
signal p,g,c : STD_LOGIC_VECTOR(3 downto 0);
begin
p <= a xor b;
g <= a and b;
c(0) <= cin;
c(1) <= g(0) or (p(0) and cin);
c(2) <= g(1) or(p(1) and g(0)) or (p(1) and p(0) and cin);
c(3) <= g(2) or (p(2) and g(1)) or (p(2) and p(1) and
g(0)) or (p(2) and p(1) and p(0) andcin);
cout <= g(3) or (p(3) and g(2)) or (p(3) and p(2) and g(1))
or (p(3) and p(2) and p(1) and g(0)) or
(p(3) and p(2) and p(1) and p(0) and cin);
sum <= p xor c;
end dataflow;
ROLL NO.
DATE OF EXPERIMENT
DATE OF SUBMISSION
GRADE/MARKS
TEACHER’S SIGNATURE
Sequen al circuits are digital circuits that store and use the previous state
informa on to determine their next state. Unlike combina onal circuits, which
only depend on the current input values to produce outputs, sequen al
circuits depend on both the current inputs and the previous state stored in
memory elements.
SR flip-flop : The SR flip-flop is one of the fundamental parts of the
sequen al circuit logic. SR flip-flop is a memory device and binary data of 1 bit
can be stored in it. SR flip-flop has two stable states in which it can store data
in the form of either binary zero or binary one. Like all flip-flops, an SR flip-flop
is also an edge sensi ve device. SR
flip–flop is one of the most vital
components in digital logic and it is
also the most basic sequen al
circuit that is possible. The S (SET)
input, sets the output to 1 and the
R(RESET) input resets it to 0.
JK flip-flop : JK flip-flop is a
refinement of SR flip-flop where the
indeterminate state of SR type is
defined. Input J and K are respec vely
the set and reset inputs of the flip-flop.
When both the inputs are high then
the output of the flip-flop switches to
its complemented state.
D flip-flop : To ensure that both
S and R inputs don’t become the
same, we can use the Delay/Data
flipflop. Here there is a single
‘Data’ input which is connected to
the Set pin, while its complement
goes to the Reset pin.
en ty SRFF is en ty SRFF is
port(S, R : in std_logic; port(S, R : in std_logic;
Q, Qnot : out std_logic); Q, Qnot : out std_logic);
end SRFF; end SRFF;
architecture srff of SRFF is
signal S,R:STD_LOGIC; architecture srff of SRFF is
begin component nand21
S<= s nand clk; port(a,b: in STD_LOGIC;
R <= r nand clk; y:out STD_LOGIC);
Q <= S nand Qnot; end component;
Qnot <= R nand Q; signal s1,r1:STD_LOGIC;
end srff; begin
0 n1: nand21 port map(S,clk,s1);
n2: nand21 port map(R,clk,r1);
n3: nand21 port map(s1,Qnot,Q);
n4: nand21 port map(r1,Q,Qnot);
end srff;
SR FlipFlop Behavioural Model
library ieee;
use ieee.std_logic_1164.all;
en ty SRFF is
port(S, R : in std_logic;
Q, Qnot : out std_logic);
end SRFF;
architecture Behavioral of SRFF is
process (S,R,RST,CLK)
begin
if (RST = '1') then
Q <= '0';
elsif (RISING_EDGE(CLK))then
if (S /= R) then
Q <= S; Qnot <= R;
elsif (S = '1' AND R = '1') then
Q <= 'Z'; Qnot <= 'Z';
end if;
end if;
end process;
end Behavioral;
en ty testbench is en ty DFF is
-- empty port(D : in std_logic;
end testbench; Q, Qnot : out std_logic);
end DFF;
architecture tb of testbench is architecture dataflow of DFF is
begin
component DFF Q <= D when clk'event and clk = '1';
port(D : in std_logic; end dataflow;
Q, Qnot : out std_logic);
end component;
begin
DUT: DFF port map (D, Q, Qnot);
process
begin
D <= '0'; wait for 10 ns;
assert (Q='0' and Qnot='1')
report "Fail 0" severity error;
D <= '1'; wait for 10 ns;
assert (Q='1' and Qnot='0')
report "Fail 1" severity error;
en ty DFF is en ty DFF is
port(D : in std_logic; port(D : in std_logic;
Q, Qnot : out std_logic); Q, Qnot : out std_logic);
end DFF; end DFF;
architecture behavioral of DFF is architecture structural of DFF is
begin component D_latch is
process(CLOCK) port (
begin clk : in std_logic;
if(CLOCK='1' and CLOCK'EVENT) then d : in std_logic;
Q <= D; q : out std_logic
end if; );
end process; end component;
end behavioral; signal d_latch_q : std_logic;
begin
d_latch_inst : D_latch port map (
clk => clk,
d => d,
q => d_latch_q
);
q <= d_latch_q;
end structural;
Please provide the waveforms generated by your code and specify whether they verify truth table