Forum Discussion
Altera_Forum
Honored Contributor
16 years agocomparator
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 correctlylibrary 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
Honored 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
Honored Contributor
so how can i use greater or equal than
could you check this page please http://eesun.free.fr/doc/vhdlref/refguide/language_overview/objects__data_types_and_operators/vhdl_operators.htm - Altera_Forum
Honored Contributor
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.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;