SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Experiment–5
Objective: Design and simulate 4- bit Comparator using VHDL.
Requirement: Computer Software Requirement: XILINX 8.2 Software
Theory:
A digital comparator is a hardware electronic device that takes two
numbers as input in binary form and determines whether one number
is greater than, less than or equal to the other number.
A comparator used to compare two binary numbers each of four bits
is called a 4-bit magnitude comparator. It consists of eight inputs
each for two four bit numbers and three outputs to generate less
than, equal to and greater than between two binary numbers.
In a 4-bit comparator the condition of A>B can be possible in the
following four cases:
1. If A3 = 1 and B3 = 0
2. If A3 = B3 and A2 = 1 and B2 = 0
3. If A3 = B3, A2 = B2 and A1 = 1 and B1 = 0
4. If A3 = B3, A2 = B2, A1 = B1 and A0 = 1 and B0 = 0
Similarly the condition for A<B can be possible in the following four
cases:
1. If A3 = 0 and B3 = 1
2. If A3 = B3 and A2 = 0 and B2 = 1
3. If A3 = B3, A2 = B2 and A1 = 0 and B1 = 1
4. If A3 = B3, A2 = B2, A1 = B1 and A0 = 0 and B0 = 1
The condition of A=B is possible only when all the individual bits of
one number exactly coincide with corresponding bits of another
number.
Circuit:
Truth Table:
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comparator_4bit is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
eq : out STD_LOGIC;
ag : out STD_LOGIC;
bg : out STD_LOGIC);
end comparator_4bit;
architecture Behavioral of comparator_4bit is
begin
ag <= '1' when (a> b)
else '0';
eq <= '1' when (a = b)
else '0';
bg <= '1' when (a < b)
else '0';
end Behavioral;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY comparator_tb IS
END comparator_tb;
ARCHITECTURE behavior OF comparator_tb is
COMPONENT comparator_4bit
PORT(
a : IN std_logic_vector(3 downto 0);
b : IN std_logic_vector(3 downto 0);
eq : OUT std_logic;
ag : OUT std_logic;
bg : OUT std_logic
);
END COMPONENT;
--Inputs
signal a : std_logic_vector(3 downto 0) := (others => '0');
signal b : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal eq : std_logic;
signal ag : std_logic;
signal bg : std_logic;
BEGIN
uut: comparator_4bit PORT MAP (
a => a,
b => b,
eq => eq,
ag => ag,
bg => bg
);
-- Stimulus process
stim_proc: process
begin
A<="0100";
B<="0010";
wait for 100 ns;
A<="0101";
B<="0010";
wait for 100 ns;
A<="1100";
B<="0011";
wait for 100 ns;
A<="0100";
B<="0100";
wait for 100 ns;
A<="0101";
B<="1100";
wait for 100 ns;
A<="1100";
B<="1100";
wait for 100 ns;
end process;
END;
OUTPUT:
RTL Schematic:
Wave From:
Result:
VHDL program to implement 4 bit comparator has been
successfully simulated.

More Related Content

PPTX
Verilog operators.pptx
DOCX
Arduino lcd display
PDF
Chapter 6 register
PPT
Interfacing LCD with 8051 Microcontroller
PDF
8085 arithmetic instructions
PPTX
Lect 7: Verilog Behavioral model for Absolute Beginners
DOCX
Microprocessor Interfacing and 8155 Features
PDF
FYBSC IT Digital Electronics Unit V Chapter I Counters
Verilog operators.pptx
Arduino lcd display
Chapter 6 register
Interfacing LCD with 8051 Microcontroller
8085 arithmetic instructions
Lect 7: Verilog Behavioral model for Absolute Beginners
Microprocessor Interfacing and 8155 Features
FYBSC IT Digital Electronics Unit V Chapter I Counters

What's hot (20)

PDF
Unit II arm 7 Instruction Set
PPTX
Verilog
PPTX
Timer counter in arm7(lpc2148)
PDF
Ripple counter
PPT
Memory & I/O interfacing
PPTX
Data flow model -Lecture-4
PPTX
Race around and master slave flip flop
PPT
PPTX
Synchronous Counter
PPT
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
DOCX
4 bit uni shift reg
PPT
MSI Counters
PPT
Case study of digital camera
PPT
Introduction to Interrupts of 8085 microprocessor
PDF
8051 interfacing
PPTX
BCD to binary code converter
PPT
Digital Logic Circuits
PPT
Encoders and Decoders
PPTX
Modules and ports in Verilog HDL
PPTX
Ring Counter.pptx
Unit II arm 7 Instruction Set
Verilog
Timer counter in arm7(lpc2148)
Ripple counter
Memory & I/O interfacing
Data flow model -Lecture-4
Race around and master slave flip flop
Synchronous Counter
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
4 bit uni shift reg
MSI Counters
Case study of digital camera
Introduction to Interrupts of 8085 microprocessor
8051 interfacing
BCD to binary code converter
Digital Logic Circuits
Encoders and Decoders
Modules and ports in Verilog HDL
Ring Counter.pptx
Ad

Similar to vhdl exp-5 (20)

PPTX
Magnitude comparator
PDF
Digital 4-bit Comprator
PPTX
Magnitude Comparator-DIPLOMA IN ELECTRONICSpptx
PDF
Vhdl lab manual
PDF
Programs of VHDL
DOCX
Computer Architecture_Digital Comparator.docx
PPSX
2-bit comparator
PDF
Lecture6 Chapter4- Design Magnitude Comparator Circuit, Introduction to Decod...
PDF
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
PDF
Digital System Design Lab Report - VHDL ECE
PDF
4 bit magnjtude comparators ppt COA project
PPTX
DLD Lecture No 21 BCD Multiplier and Magnitude Comparator.pptx
PPTX
IS 151 Lecture 9
PDF
Comparators in DLD.
PDF
DLD Chapter-4.pdf
PDF
Practical file
PDF
SCSVMV_DSD LAB MANUAL_KMS
PDF
Digital Combinational Circuits.pdf
PPSX
2-bit comparator
PPTX
Da3_on_FPGA_education_program_by_DIAT.pptx
Magnitude comparator
Digital 4-bit Comprator
Magnitude Comparator-DIPLOMA IN ELECTRONICSpptx
Vhdl lab manual
Programs of VHDL
Computer Architecture_Digital Comparator.docx
2-bit comparator
Lecture6 Chapter4- Design Magnitude Comparator Circuit, Introduction to Decod...
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
Digital System Design Lab Report - VHDL ECE
4 bit magnjtude comparators ppt COA project
DLD Lecture No 21 BCD Multiplier and Magnitude Comparator.pptx
IS 151 Lecture 9
Comparators in DLD.
DLD Chapter-4.pdf
Practical file
SCSVMV_DSD LAB MANUAL_KMS
Digital Combinational Circuits.pdf
2-bit comparator
Da3_on_FPGA_education_program_by_DIAT.pptx
Ad

Recently uploaded (20)

PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
UNIT 4 Total Quality Management .pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Welding lecture in detail for understanding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Digital Logic Computer Design lecture notes
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
R24 SURVEYING LAB MANUAL for civil enggi
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Sustainable Sites - Green Building Construction
CH1 Production IntroductoryConcepts.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
UNIT 4 Total Quality Management .pptx
Mechanical Engineering MATERIALS Selection
Welding lecture in detail for understanding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Digital Logic Computer Design lecture notes
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx

vhdl exp-5

  • 1. Experiment–5 Objective: Design and simulate 4- bit Comparator using VHDL. Requirement: Computer Software Requirement: XILINX 8.2 Software Theory: A digital comparator is a hardware electronic device that takes two numbers as input in binary form and determines whether one number is greater than, less than or equal to the other number. A comparator used to compare two binary numbers each of four bits is called a 4-bit magnitude comparator. It consists of eight inputs each for two four bit numbers and three outputs to generate less than, equal to and greater than between two binary numbers. In a 4-bit comparator the condition of A>B can be possible in the following four cases: 1. If A3 = 1 and B3 = 0 2. If A3 = B3 and A2 = 1 and B2 = 0 3. If A3 = B3, A2 = B2 and A1 = 1 and B1 = 0 4. If A3 = B3, A2 = B2, A1 = B1 and A0 = 1 and B0 = 0 Similarly the condition for A<B can be possible in the following four cases: 1. If A3 = 0 and B3 = 1 2. If A3 = B3 and A2 = 0 and B2 = 1 3. If A3 = B3, A2 = B2 and A1 = 0 and B1 = 1 4. If A3 = B3, A2 = B2, A1 = B1 and A0 = 0 and B0 = 1 The condition of A=B is possible only when all the individual bits of one number exactly coincide with corresponding bits of another number.
  • 2. Circuit: Truth Table: VHDL CODE: library IEEE; use IEEE.STD_LOGIC_1164.ALL;
  • 3. entity comparator_4bit is Port ( a : in STD_LOGIC_VECTOR (3 downto 0); b : in STD_LOGIC_VECTOR (3 downto 0); eq : out STD_LOGIC; ag : out STD_LOGIC; bg : out STD_LOGIC); end comparator_4bit; architecture Behavioral of comparator_4bit is begin ag <= '1' when (a> b) else '0'; eq <= '1' when (a = b) else '0'; bg <= '1' when (a < b) else '0'; end Behavioral; TEST BENCH: LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY comparator_tb IS END comparator_tb; ARCHITECTURE behavior OF comparator_tb is COMPONENT comparator_4bit
  • 4. PORT( a : IN std_logic_vector(3 downto 0); b : IN std_logic_vector(3 downto 0); eq : OUT std_logic; ag : OUT std_logic; bg : OUT std_logic ); END COMPONENT; --Inputs signal a : std_logic_vector(3 downto 0) := (others => '0'); signal b : std_logic_vector(3 downto 0) := (others => '0'); --Outputs signal eq : std_logic; signal ag : std_logic; signal bg : std_logic; BEGIN uut: comparator_4bit PORT MAP ( a => a, b => b, eq => eq, ag => ag, bg => bg );
  • 5. -- Stimulus process stim_proc: process begin A<="0100"; B<="0010"; wait for 100 ns; A<="0101"; B<="0010"; wait for 100 ns; A<="1100"; B<="0011"; wait for 100 ns; A<="0100"; B<="0100"; wait for 100 ns; A<="0101"; B<="1100"; wait for 100 ns; A<="1100"; B<="1100"; wait for 100 ns; end process; END;
  • 7. Result: VHDL program to implement 4 bit comparator has been successfully simulated.