Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with a program for 2-bit comparator in VHDL

Status
Not open for further replies.

fm_com_28

Full Member level 1
Joined
Feb 2, 2006
Messages
99
Helped
11
Reputation
22
Reaction score
7
Trophy points
1,288
Location
Fayoum, Egypt
Activity points
1,916
2bit comaraor

Dear,

I want to design a 2-bit comparator using VHDL that takes two unsigned std_logic_vectrors A and B and produces bits L,G,E, where

L=1 , if A<B
G=1, if A>B
E=1, if A=B

so if one can help me in finding a program for this design,
regards
 

Re: 2bit comaraor

Its very simple!
For more general reusable design see data sheet for CD4585.

Code:
library ieee;
use ieee.std_logic_1164.all;

entity comparator is
  
  port (
    A : in  std_logic_vector(1 downto 0);
    B : in  std_logic_vector(1 downto 0);
    L : out std_logic;
    G : out  std_logic;
    E : out  std_logic);

end comparator;

architecture behav of comparator is

begin  -- behav

  process (A, B)
    variable G_tmp : std_logic;
    variable L_tmp : std_logic;
    variable E_tmp : std_logic;
  begin  -- process
    G_tmp := '0';
    E_tmp := '0';
    L_tmp := '0';  
    if A > B then
      G_tmp := '1';  
    elsif A = B then
      E_tmp := '1';
    else
      L_tmp := '1';
    end if;
    G <= G_tmp;
    E <= E_tmp;
    L <= L_tmp;  
  end process;

end behav;
 

    fm_com_28

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top