0
\$\begingroup\$

Using Xilinx, I need to compare a 'variable' called 'row', defined as:

variable row : std_logic_vector(2 * n - 1 downto 0);

This line was given to me, now I need an if statement that will execute if row is = 1.

I have tried:

if (row = "1") then

but the IDE warns me that this condition will always result in false? which should not happen.

If I try if (row = '1') then or if (row = 1) then then I get the error:

found '0' definitions of operator "="

Googling this, the only suggestion is to include libraries that I have already included:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
DonFusili
1,0677 silver badges10 bronze badges
asked Dec 3, 2019 at 14:57
\$\endgroup\$
3
  • \$\begingroup\$ You need to show more code. If you put the things you have shown so far after each other, your variable should be initalized to (others => 'U') (might depend on simulator), which is not equal to "1". But you might think you initialize it, or you wouldn't ask this question. So supply us with a minimal failing example. \$\endgroup\$ Commented Dec 3, 2019 at 15:12
  • 1
    \$\begingroup\$ It's telling you the result will always be false because the comparison strings (arguments of "=") are of unequal length. 'row' is a multiple of 2 bits long, "1" is 1 bit long. What is 'n' in this case and will it change? Next, is this variable declared inside a process and should you be using a signal instead? Don't try to carry programming language views into a descriptor language, you'll make a right mess. \$\endgroup\$ Commented Dec 3, 2019 at 15:13
  • \$\begingroup\$ That 'n' bugs me. Is that a signal or constant or parameter? \$\endgroup\$ Commented Dec 3, 2019 at 15:19

1 Answer 1

4
\$\begingroup\$

Your variable is a std_logic_vector and you compare it to an integer. You have to cast the std_logic_vector like this:

if(to_integer(signed(row)) = 1) or if(to_integer(unsigned(row)) = 1)

answered Dec 3, 2019 at 15:06
\$\endgroup\$
7
  • 3
    \$\begingroup\$ "1" isn't an integer, it's a std_logic_vector of length 1. \$\endgroup\$ Commented Dec 3, 2019 at 15:07
  • 1
    \$\begingroup\$ For completeness, 1 is an integer and '1' is a bit or character. \$\endgroup\$ Commented Dec 3, 2019 at 15:28
  • 2
    \$\begingroup\$ @Kevin We would like to call it 'bit' because 'character' is a convention in C or C++ which represents a byte. \$\endgroup\$ Commented Dec 3, 2019 at 15:35
  • \$\begingroup\$ @MituRaj "character" is well-defined in VHDL and is valid here. The literal '1' is not necessarily a bit nor a character, it may be either depending on what the literal is compared with or assigned to. \$\endgroup\$ Commented Dec 3, 2019 at 16:02
  • 2
    \$\begingroup\$ That was just a convention introduced in VHDL for people from software field. We hardware engineers rarely use it in HDL. It makes more sense to assign a bit vector = 01000001 rather than assigning it as a char by 'A' \$\endgroup\$ Commented Dec 3, 2019 at 16:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.