0
votes

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

1
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"?Martin Thompson
Also, which is 1 and which is 0, that will affect the result quite significantly :)Martin Thompson
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?vvill

1 Answers

2
votes

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;