Electronic – Assign result of comparison to std_logic

vhdl

I'm trying to design an eight bit subtractor. The operands are declared as \$\mathtt{std\_logic\_vector}\$ and the borrow out is \$\mathtt{std\_logic}\$ type. Is there a way to directly assign the comparison of operands to the borrow out, like so?

borrowOut <= unsigned(r1) < unsigned(r2);

When I analyze the file the following error occurs:

eightBitSubtractor.vhd:24:29: no function declarations for operator "<"

Best Answer

The return type of a comparison operation is boolean.

For std_logic output try this:

borrowOut <= '1' when unsigned(r1) < unsigned(r2) else '0';

If you are planning to use this frequently, you can overload the operator <

function "<"(L: STD_LOGIC_VECTOR; R: STD_LOGIC_VECTOR) return STD_LOGIC is
 variable result : std_logic;
begin
    result <= '1' when unsigned(r1) < unsigned(r2) else '0';
    return result; 
end;