0

If I convert two std_logic_vector with values 1 and 0 respectively

signal mlx, mtx : std_logic_vector(15 downto 0) 

into a integer through

variable WLX : integer;
variable WTX : integer;

WLX := TO_INTEGER(signed(mlx));
WTX := TO_INTEGER(signed(mtx));

and after that compare the subtraction of these with -1 literal:

if WTX-WLX = -1 

The result will be true?

Thanks

3
  • Being pedantic: when you say "std_logic_vector with values 1 and 0 respectively" - std_logic_vectors have no numerical value, just a list of bits - do you mean they have values X"0000" and X"0001"? Commented Jun 5, 2013 at 8:52
  • Also, which is 1 and which is 0, that will affect the result quite significantly :) Commented Jun 5, 2013 at 8:53
  • X"0000" and X"0001" exactly. WTX = X"0000" and WLX = X"0001". If I convert with TO_INTEGER signed, I can compare these results with negative values like -1? Commented Jun 5, 2013 at 12:03

1 Answer 1

2

If mlx=X"0001" and mtx=X"0000", then yes, subtracting mlx from mtx as integers yields -1, so given the question the answer is yes.

However: casting values to an integer in order to operate on them or compare them is usually a sign of poorly written code.

Why don't you just use signed for mlx and mtx, and avoid the use of integers?

architecture arch of ent is
    signal mlx, mtx : signed(15 downto 0);
begin
    process(clk) begin
        if(rising_edge(clk)) then
            if(mtx - mlx = -1) then
                -- Do what needs to be done.
            end if;
        end if;
    end process;
end architecture;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I'm working with a legacy code where IEEE.STD_LOGIC_unsigned.all is used. So, I can use: (ieee.Std_Logic_signed."=" (ieee.Std_Logic_signed."-" (mtx, mlx), -1) ?
@wschcom Even with legacy code I would suggest adding IEEE.NUMERIC_STD.all; and then using if(signed(mtx)-signed(mlx)=-1) then. Not sure what you meant by your statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.