0% found this document useful (0 votes)
16 views27 pages

Coa Lab Work Pravin Yadav

The document outlines a Computer Organisation and Architecture Lab course with a series of experiments focused on implementing various digital circuits using VHDL in Xilinx Vivado. Experiments include the implementation of adders, multiplexers, and flip-flops, detailing their theoretical background, software and hardware requirements, VHDL code snippets, procedures, and expected results. Each experiment aims to enhance students' understanding of digital design and simulation techniques.

Uploaded by

kumawatharsh191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views27 pages

Coa Lab Work Pravin Yadav

The document outlines a Computer Organisation and Architecture Lab course with a series of experiments focused on implementing various digital circuits using VHDL in Xilinx Vivado. Experiments include the implementation of adders, multiplexers, and flip-flops, detailing their theoretical background, software and hardware requirements, VHDL code snippets, procedures, and expected results. Each experiment aims to enhance students' understanding of digital design and simulation techniques.

Uploaded by

kumawatharsh191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Computer Organisation and

Architecture
Lab

Name – Pravin Yadav


Enrollment No. – 12023002001137
Course – B. Tech (CSE)
Semester – IV ( II Year )
Section - C

1
List of Experiments
Computer Organisation and Architecture Lab

Index

S. No. Experiment Title Page No.

Implementation of Half Adder, Half Subtractor, Full Adder, Full Subtractor


1 3-5
using VHDL

Implementation of Full Adder using VHDL (Behavioral Model)


2 a)

6-9
Implementation of n-bit Carry Propagation Adder using VHDL (Behavioral
2 b)
Model)

Implementation of 4:1 Multiplexer using 2:1 Multiplexer (Structural Method


3 10 - 13
in VHDL)

4 Implementation of D Flip-Flop, J-K Flip-Flop, and T Flip-Flop using VHDL 14 - 18

5 Implementation of Sequence Detector Algorithm using VHDL 19 - 22

Design of a Primitive ALU with Control Unit for Add, Multiply, AND, OR
6 23 - 26
operations

2
Experiment 1

Implementation of Half Adder, Half Subtractor, Full Adder, Full


Subtractor using VHDL

Aim:

To implement and simulate Half Adder, Half Subtractor, Full Adder, and Full Subtractor circuits
using VHDL in Xilinx Vivado.

Theory:

1. Half Adder:
A combinational circuit that adds two single-bit binary numbers (A and B) and produces a sum (S)
and a carry (C) as outputs.

• Sum (S) = A ⊕ B

• Carry (C) = A · B

2. Full Adder:
A circuit that adds three inputs: two significant bits (A and B) and a carry-in (Cin). It outputs a sum
and a carry-out.

• Sum (S) = A ⊕ B ⊕ Cin

• Carry (Cout) = (A · B) + (Cin · (A ⊕ B))

3. Half Subtractor:
A combinational circuit that subtracts one binary digit from another and outputs the difference and
borrow.

• Difference (D) = A ⊕ B

• Borrow (B) = A̅ · B

4. Full Subtractor:
A circuit that subtracts two bits A and B, considering a borrow-in (Bin), and outputs a difference
and borrow-out.

3
• Difference (D) = A ⊕ B ⊕ Bin

• Borrow (Bout) = (A̅ · B) + (Bin · (A̅ ⊕ B))

Software and Hardware Requirements:

• Software:

• Xilinx Vivado Design Suite (recommended version: 2020.2 or above)

• VHDL compiler and simulation tool (built-in with Vivado)

• Hardware (Optional, for FPGA implementation):

• Xilinx FPGA board (e.g., Basys 3, Nexys A7)

• USB programmer (if applicable)

VHDL Code Snippets Overview (examples):

Half Adder

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity half_adder is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Sum : out STD_LOGIC;
Carry : out STD_LOGIC);
end half_adder;

architecture Behavioral of half_adder is


begin
Sum <= A XOR B;
Carry <= A AND B;
end Behavioral;

Full Adder (can be implemented using two half adders and an OR gate)

4
Procedure:
1. Launch Vivado Design Suite.

2. Create a new project for each circuit (Half Adder, Full Adder, etc.).

3. Write the VHDL code and save it with .vhdl or .vhd extension.

4. Add the design file to the project.

5. Run behavioral simulation using the Vivado simulator.

6. Verify the output waveform against expected truth tables.

7. (Optional) Implement the design on FPGA board using synthesis and implementation tools.

Observation:

Input A Input B Cin/Bin Sum/Diff Carry/Borrow


0 0 0 0 0
0 1 1 0 1
... ... ... ... ...
(Fill out based on simulation results)

Result:

The Half Adder, Half Subtractor, Full Adder, and Full Subtractor were successfully implemented
and simulated using VHDL on Vivado.

5
Experiment 2
a) Implementation of Full Adder using VHDL (Behavioral Model)

b) Implementation of n-bit Carry Propagation Adder in VHDL (Behavioral Model)

Aim:

• (a) To implement a 1-bit Full Adder using the Behavioral Modeling approach in VHDL.

• (b) To implement an n-bit Carry Propagation Adder using Behavioral Modeling in


VHDL.

Theory:
Full Adder:

A full adder adds three bits: A, B, and Carry-in (Cin). It outputs a Sum and Carry-out (Cout).

• Sum (S) = A ⊕ B ⊕ Cin

• Carry (Cout) = (A · B) + (Cin · (A ⊕ B))

n-bit Carry Propagation Adder:

A carry propagation adder connects multiple full adders in series. Each stage passes its Cout to the
next adder as Cin.

For n bits, we need n full adders connected in cascade. Each full adder operates on bits A(i), B(i),
and a carry-in.

Software & Hardware Requirements:

• Software:

• Xilinx Vivado Design Suite

• VHDL simulator (in-built in Vivado)

• Hardware (Optional):

• FPGA Development Board (e.g., Basys 3)

6
VHDL Code:
a) Full Adder (1-bit) - Behavioral Model

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity 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 full_adder;

architecture Behavioral of full_adder is


begin
process(A, B, Cin)
begin
Sum <= A XOR B XOR Cin;
Cout <= (A AND B) OR (B AND Cin) OR (A AND Cin);
end process;
end Behavioral;

b) n-bit Carry Propagation Adder (e.g., 4-bit Example)

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity n_bit_adder is
Generic ( N : integer := 4 ); -- Change N for different bit-widths
Port ( A : in STD_LOGIC_VECTOR(N-1 downto 0);
B : in STD_LOGIC_VECTOR(N-1 downto 0);
Cin : in STD_LOGIC;
Sum : out STD_LOGIC_VECTOR(N-1 downto 0);
Cout : out STD_LOGIC);
end n_bit_adder;

7
architecture Behavioral of n_bit_adder is
signal temp : STD_LOGIC_VECTOR(N downto 0);
begin
process(A, B, Cin)
begin
temp := ('0' & A) + ('0' & B) + Cin;
Sum <= temp(N-1 downto 0);
Cout <= temp(N);
end process;
end Behavioral;

Procedure:

1. Open Vivado and create a new VHDL project.

2. Write and save the VHDL code for Full Adder and n-bit Adder.

3. Add the VHDL files to the project.

4. Run behavioral simulation using testbenches.

5. Observe waveform results and verify against truth tables.

6. (Optional) Synthesize and implement on FPGA board.

Observation Table (Sample for Full Adder):

A B Cin Sum Cout


0 0 0 0 0
0 1 0 1 0
1 1 1 1 1

Result:

• The 1-bit Full Adder was successfully implemented and simulated using Behavioral
Modeling in VHDL.

8
• The n-bit Carry Propagation Adder (4-bit) was also implemented using Behavioral Modeling
and verified through simulation.

9
Experiment 3

Implementation of 4:1 Multiplexer using 2:1 Multiplexers


(Structural Modeling) in VHDL

Aim:

To implement a 4:1 Multiplexer using 2:1 Multiplexers in VHDL using the Structural Modeling
approach.

Theory:

A Multiplexer (MUX) is a combinational circuit that selects binary information from one of many
input lines and directs it to a single output line based on select inputs.

• A 4:1 MUX has:

• 4 data inputs: I0, I1, I2, I3

• 2 select lines: S1, S0

• 1 output: Y

The output logic equation for 4:1 MUX is:


Y = (I0 AND ~S1 AND ~S0) OR (I1 AND ~S1 AND S0) OR (I2 AND S1 AND ~S0) OR (I3 AND S1 AND S0)

A 2:1 MUX selects between 2 inputs based on a single select line.

• Output Y = (I0 AND NOT(S)) OR (I1 AND S)

Using three 2:1 MUXes, a 4:1 MUX can be built structurally:

• Use two 2:1 MUXes in the first stage to handle inputs I0/I1 and I2/I3

• Use one 2:1 MUX in the second stage to select between outputs of the first stage.

10
Software Requirements:

• Xilinx Vivado Design Suite (2020.2 or later)

• VHDL simulator

VHDL Code:

Step 1: 2:1 MUX (Component)

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity mux2x1 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Sel : in STD_LOGIC;
Y : out STD_LOGIC);
end mux2x1;

architecture Behavioral of mux2x1 is


begin
Y <= A when Sel = '0' else B;
end Behavioral;

Step 2: 4:1 MUX using 2:1 MUXes (Structural Model)

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity mux4x1_structural is
Port ( I0, I1, I2, I3 : in STD_LOGIC;
S : in STD_LOGIC_VECTOR(1 downto 0);
Y : out STD_LOGIC);
end mux4x1_structural;

architecture Structural of mux4x1_structural is

component mux2x1
Port ( A : in STD_LOGIC;

11
B : in STD_LOGIC;
Sel : in STD_LOGIC;
Y : out STD_LOGIC);
end component;

signal Y1, Y2 : STD_LOGIC;

begin

U1: mux2x1 port map(A => I0, B => I1, Sel => S(0), Y => Y1);
U2: mux2x1 port map(A => I2, B => I3, Sel => S(0), Y => Y2);
U3: mux2x1 port map(A => Y1, B => Y2, Sel => S(1), Y => Y);

end Structural;

Procedure:
1. Open Vivado and create a new project.

2. Write the VHDL code for both the 2:1 MUX and 4:1 MUX.

3. Add both files to the project and declare the 2:1 MUX as a component inside the 4:1 MUX
entity.

4. Run behavioral simulation with test vectors to verify functionality.

5. Optionally synthesize and implement the design on FPGA.

Observation Table (Sample):

S1 S0 I0 I1 I2 I3 Output Y
0 0 1 0 0 0 1
0 1 0 1 0 0 1
1 0 0 0 1 0 1
1 1 0 0 0 1 1

12
Result:
The 4:1 Multiplexer was successfully implemented using 2:1 Multiplexers in Structural
Modeling with VHDL and simulated using Vivado.

13
Experiment 4

Implementation of D Flip-Flop, J-K Flip-Flop, and T Flip-Flop


using VHDL

Aim:
To implement D Flip-Flop, J-K Flip-Flop, and T Flip-Flop using VHDL (Behavioral Modeling)
and simulate their operation.

Theory:
Flip-Flops are basic memory elements used in sequential circuits to store binary data. They operate
on the clock signal and change state according to their characteristic equations.

1. D Flip-Flop (Data or Delay Flip-Flop):

• Characteristic Equation: Q(next) = D

• On every rising edge of the clock, the output follows the input D.

2. J-K Flip-Flop:

• Characteristic Equation:

• J = 0, K = 0 → No change

• J = 0, K = 1 → Reset (Q = 0)

• J = 1, K = 0 → Set (Q = 1)

• J = 1, K = 1 → Toggle

14
3. T Flip-Flop (Toggle Flip-Flop):

• Characteristic Equation:

• T = 0 → No change

• T = 1 → Toggle the output

Software Requirement:

• Xilinx Vivado Design Suite (any recent version)

• VHDL Simulator (built-in)

VHDL Code:

1. D Flip-Flop

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity d_flip_flop is
Port ( D : in STD_LOGIC;
CLK : in STD_LOGIC;
Q : out STD_LOGIC);
end d_flip_flop;

architecture Behavioral of d_flip_flop is


begin
process(CLK)
begin
if rising_edge(CLK) then
Q <= D;
end if;
end process;
end Behavioral;

15
2. J-K Flip-Flop

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity jk_flip_flop is
Port ( J : in STD_LOGIC;
K : in STD_LOGIC;
CLK : in STD_LOGIC;
Q : out STD_LOGIC);
end jk_flip_flop;

architecture Behavioral of jk_flip_flop is


signal Q_int : STD_LOGIC := '0';
begin
process(CLK)
begin
if rising_edge(CLK) then
if J = '0' and K = '0' then
Q_int <= Q_int;
elsif J = '0' and K = '1' then
Q_int <= '0';
elsif J = '1' and K = '0' then
Q_int <= '1';
elsif J = '1' and K = '1' then
Q_int <= not Q_int;
end if;
end if;
end process;
Q <= Q_int;
end Behavioral;

3. T Flip-Flop

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity t_flip_flop is
Port ( T : in STD_LOGIC;
CLK : in STD_LOGIC;

16
Q : out STD_LOGIC);
end t_flip_flop;

architecture Behavioral of t_flip_flop is


signal Q_int : STD_LOGIC := '0';
begin
process(CLK)
begin
if rising_edge(CLK) then
if T = '1' then
Q_int <= not Q_int;
end if;
end if;
end process;
Q <= Q_int;
end Behavioral;

Procedure:

1. Open Vivado and create a new VHDL project.

2. Write and save the code for each flip-flop (D, JK, T).

3. Add each file to the project and compile.

4. Run simulations using testbenches to observe behavior on clock pulses.

5. (Optional) Implement on FPGA board for hardware verification.

Observation Table (Sample for T Flip-Flop):

CLK T Previous Q Next Q


↑ 0 0 0
↑ 1 0 1
↑ 1 1 0

17
Result:
D Flip-Flop, J-K Flip-Flop, and T Flip-Flop were successfully implemented using VHDL
behavioral modeling and verified through simulation.

18
Experiment 5

Implementation of Sequence Detector Algorithm using VHDL

Aim:

To implement a sequence detector using VHDL and verify its operation via simulation.

Theory:
A sequence detector is a Finite State Machine (FSM) designed to detect a particular pattern of
bits in a serial input stream. There are two types of sequence detectors:

• Moore Machine – Output depends only on the current state.

• Mealy Machine – Output depends on the current state and input.

We will implement a Mealy-based sequence detector for detecting a "1011" bit sequence in a
serial input stream.

FSM for Detecting Sequence "1011":

Let’s define the states:

• S0: Initial state

• S1: '1' detected

• S2: '10' detected

• S3: '101' detected

• S4: '1011' detected → Output = 1

19
We reset back to appropriate states depending on the input to allow overlapping sequences (e.g.,
detecting “1011011”).

State Transition Table:

Present State Input Next State Output


S0 0 S0 0
S0 1 S1 0
S1 0 S2 0
S1 1 S1 0
S2 1 S3 0
S2 0 S0 0
S3 1 S4 1
S3 0 S2 0
S4 x S1 or S0 0

Software Requirements:

• Xilinx Vivado Design Suite

• VHDL Compiler & Simulator

VHDL Code (Behavioral, Mealy FSM, sequence = “1011”)


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity sequence_detector is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
din : in STD_LOGIC;
dout : out STD_LOGIC);
end sequence_detector;

architecture Behavioral of sequence_detector is

20
type state_type is (S0, S1, S2, S3);
signal state, next_state : state_type;
begin

process(clk, rst)
begin
if rst = '1' then
state <= S0;
elsif rising_edge(clk) then
state <= next_state;
end if;
end process;

process(state, din)
begin
case state is
when S0 =>
if din = '1' then
next_state <= S1;
else
next_state <= S0;
end if;
dout <= '0';

when S1 =>
if din = '0' then
next_state <= S2;
else
next_state <= S1;
end if;
dout <= '0';

when S2 =>
if din = '1' then
next_state <= S3;
else
next_state <= S0;
end if;
dout <= '0';

21
when S3 =>
if din = '1' then
next_state <= S1;
dout <= '1';
else
next_state <= S2;
dout <= '0';
end if;
end case;
end process;

end Behavioral;

Procedure:

1. Open Vivado and create a new VHDL project.

2. Write the VHDL code for the sequence detector.

3. Add a testbench file to apply input sequence and simulate.

4. Observe output waveform to confirm detection of “1011” pattern.

5. Optionally, synthesize and deploy on FPGA for practical testing.

Sample Input/Output Observation Table:

CLK RST DIN DOUT (Expected) Remarks


↑ 0 1 0 S1
↑ 0 0 0 S2
↑ 0 1 0 S3
↑ 0 1 1 S4 → Detected
↑ 0 1 0 S1 (next)

Result:

The sequence detector for the pattern “1011” was successfully implemented using VHDL
behavioral modeling and verified through simulation.

22
23
Experiment 6

Design a Primitive ALU with Control Unit for the Given


Instruction Subset (Add, Multiply, AND, OR)

Aim:

To design and implement a primitive ALU integrated with a Control Unit that can perform the
following operations based on instruction input:

• i) Add

• ii) Multiply

• iii) AND

• iv) OR

Theory:

An Arithmetic Logic Unit (ALU) is a key component of the CPU that performs arithmetic and
logical operations. A Control Unit (CU) generates control signals that dictate the operation to be
performed by the ALU.

For this experiment:

• The ALU accepts two 4-bit inputs: A and B

• A 2-bit control signal Op determines the operation

• Output is an 8-bit result to accommodate multiplication (4-bit × 4-bit = 8-bit)

Operation Table:

Op Code Operation Description


00 ADD A+B

24
Op Code Operation Description
01 MUL A*B

10 AND A AND B (bitwise)

11 OR A OR B (bitwise)

Software Requirements:

• Xilinx Vivado Design Suite

• VHDL Compiler & Simulator

VHDL Code:

Primitive ALU with Control Unit

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity alu_with_control is
Port (
A : in STD_LOGIC_VECTOR(3 downto 0);
B : in STD_LOGIC_VECTOR(3 downto 0);
Op : in STD_LOGIC_VECTOR(1 downto 0);
Y : out STD_LOGIC_VECTOR(7 downto 0)
);
end alu_with_control;

architecture Behavioral of alu_with_control is


signal result : STD_LOGIC_VECTOR(7 downto 0);
begin

process(A, B, Op)
begin
case Op is
when "00" => -- ADD
result <= ("0000" & A) + ("0000" & B);
when "01" => -- MULTIPLY
result <= std_logic_vector(unsigned(A) * unsigned(B));

25
when "10" => -- AND
result <= "000000" & (A and B);
when "11" => -- OR
result <= "000000" & (A or B);
when others =>
result <= (others => '0');
end case;
end process;

Y <= result;

end Behavioral;

Procedure:

1. Create a new project in Vivado.

2. Write the VHDL code above and save it.

3. Create a testbench to apply different values of A, B, and Op.

4. Simulate the project and verify the output for all four operations.

5. Synthesize and optionally implement on an FPGA.

Observation Table (Sample):

A B Op Code Operation Output (Y)


0101 0011 00 5+3 00001000
0011 0010 01 3*2 00000110
1100 1010 10 12 AND 10 00001000
1100 1010 11 12 OR 10 00011110

26
Result:
A primitive ALU with control unit was successfully designed in VHDL to perform addition,
multiplication, bitwise AND, and bitwise OR based on the 2-bit control signal. The operation was
verified through simulation.

27

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy