Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

comparator

i need to do

Greater or equal than

Less or Equal than

not equal

but it is not working with me

could you check this code i have done greater or equal than but it is not workin but aeqb,agtb,altb are working correctly

library ieee;
USE ieee.std_logic_1164.ALL;
entity compare8 is
port(
	a,b :	IN INTEGER RANGE 0 to 255;
	agtb,aeqb,altb,ageqb :	OUT STD_LOGIC
);
end compare8;
architecture a of compare8 is
SIGNAL compare : STD_LOGIC_VECTOR (3 downto 0);
BEGIN
process(a,b)
BEGIN
if a > b THEN
	compare <= "1110";
ELSIF a < b THEN
	compare <= "1101";
ELSIF a = b THEN
	compare <= "1011";
ELSIF ( a >= b ) THEN
	compare <= "0111";
ELSE
	compare <= "1111";
END IF;
END PROCESS;
agtb <= compare(0);
altb <= compare(1);
aeqb <= compare(2);
ageqb <= compare(3);
end a;

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The ">=" case in your code will never trigger as in that case either ">" or "=" will always be evaluated first.

    --- Quote End ---

    could you explain more what u mean by this, sorry ican't understand what u mean exactly
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    
    if a > b THEN
        compare <= "1110";
    ELSIF a < b THEN
        compare <= "1101";
    ELSIF a = b THEN
        compare <= "1011";
    ELSIF ( a >= b ) THEN
        compare <= "0111";
    ELSE
        compare <= "1111";
    END IF;
    The conditions in an IF statements are evaluated in order. The ">=" case in your code will never trigger as in that case either ">" or "=" will always be evaluated first.